#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef unsigned long long llu;
const int N=3005;
const llu P=13;
int Tc,n;
int p;
char s1[N],s2[N];
llu dfs(char *s){
vector <int> Q;
Q.clear();
while (1){
if (s[p]=='0'){
p++;
Q.push_back(dfs(s));
}
else if (p==n || s[p]=='1'){
p++;
sort(Q.begin(),Q.end());
llu ret=1;
for (int i=0;i<Q.size();i++)
ret=(ret*P)^Q[i];
return ret;
}
}
}
int main(){
scanf("%d",&Tc);
while (Tc--){
scanf("%s%s",s1,s2);
n=strlen(s1);
p=0;
llu hash1=dfs(s1);
p=0;
llu hash2=dfs(s2);
if (hash1==hash2) puts("same");
else puts("different");
}
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGNzdHJpbmc+CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPHZlY3Rvcj4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdHlwZWRlZiB1bnNpZ25lZCBsb25nIGxvbmcgbGx1Owpjb25zdCBpbnQgTj0zMDA1Owpjb25zdCBsbHUgUD0xMzsKaW50IFRjLG47CmludCBwOwpjaGFyIHMxW05dLHMyW05dOwoKbGx1IGRmcyhjaGFyICpzKXsKCXZlY3RvciA8aW50PiBROwoJUS5jbGVhcigpOwoJd2hpbGUgKDEpewoJCWlmIChzW3BdPT0nMCcpewoJCSAgcCsrOwoJCSAgUS5wdXNoX2JhY2soZGZzKHMpKTsKCQl9CgkJZWxzZSBpZiAocD09biB8fCBzW3BdPT0nMScpewoJCSAgcCsrOwoJCSAgc29ydChRLmJlZ2luKCksUS5lbmQoKSk7CgkJICBsbHUgcmV0PTE7CgkJICBmb3IgKGludCBpPTA7aTxRLnNpemUoKTtpKyspCgkJICAJcmV0PShyZXQqUCleUVtpXTsKCQkgIHJldHVybiByZXQ7CgkJfQoJfQp9CgppbnQgbWFpbigpewoJc2NhbmYoIiVkIiwmVGMpOwoJd2hpbGUgKFRjLS0pewoJCXNjYW5mKCIlcyVzIixzMSxzMik7CgkJbj1zdHJsZW4oczEpOwoJCXA9MDsKCQlsbHUgaGFzaDE9ZGZzKHMxKTsKCQlwPTA7CgkJbGx1IGhhc2gyPWRmcyhzMik7CgkJaWYgKGhhc2gxPT1oYXNoMikgcHV0cygic2FtZSIpOwoJCSAgICAgICAgICAgICBlbHNlIHB1dHMoImRpZmZlcmVudCIpOwoJfQp9