#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 1000000000000 struct rolling_hash{ long long t_hash; static const long long MOD = (1LL<<61)-1; static const long long b = 123456; long long sz; rolling_hash(){ sz = 0; t_hash = 0; } rolling_hash(char c){ sz = 1; t_hash = b*c; } long long mul(__int128 x,__int128 y){ __int128 t = x*y; t = (t>>61) + (t&MOD); if(t>=MOD)t -= MOD; return t; } long long get_pow(long long sz){ long long cur = b,ret = 1; rep(i,40){ if((sz>>i)&1)ret = mul(ret,cur); cur = mul(cur,cur); } return ret; /* if(power.size()>sz)return power[sz]; while(power.size()<=sz){ if(power.size()==0)power.push_back(1); else power.push_back(mul(power.back(),b)); } return power.back(); */ } rolling_hash &operator+=(const rolling_hash &another){ (*this).t_hash = mul((*this).t_hash,get_pow(another.sz)); (*this).t_hash += another.t_hash; if((*this).t_hash>=MOD)(*this).t_hash -= MOD; (*this).sz += another.sz; return (*this); } rolling_hash operator+(const rolling_hash &another)const{ return (rolling_hash(*this)+=another); } rolling_hash &operator-=(const rolling_hash &another){ (*this).t_hash += MOD - mul(another.t_hash,get_pow((*this).sz-another.sz)); if((*this).t_hash>=MOD)(*this).t_hash -= MOD; (*this).sz -= another.sz; return (*this); } rolling_hash operator-(const rolling_hash &another)const{ return (rolling_hash(*this)-=another); } bool operator<(const rolling_hash &another)const{ if((*this).t_hash!=another.t_hash)return (*this).t_hash rolling_hash::power; int main() { int _t; cin>>_t; rep(_,_t){ string x,y; cin>>x>>y; int n =x.size(),m = y.size(); vector Rx(n+1),Ry(m+1); rep(i,n){ Rx[i+1] = rolling_hash(x[i]); Rx[i+1] = Rx[i] + Rx[i+1]; } rep(i,m){ Ry[i+1] = rolling_hash(y[i]); Ry[i+1] = Ry[i] + Ry[i+1]; } vector dpx(40),dpy(40); dpx[0] = Rx.back(); dpy[0] = Ry.back(); for(int i=1;i<40;i++){ dpx[i] = dpx[i-1] + dpx[i-1]; dpy[i] = dpy[i-1] + dpy[i-1]; } long long ok = 0,ng = Inf + 1; while(ng-ok>1LL){ long long mid = (ok+ng)/2; rolling_hash X,Y; rep(i,40){ if(((mid/n)>>i)&1)X += dpx[i]; if(((mid/m)>>i)&1)Y += dpy[i]; } X += Rx[mid%n]; Y += Ry[mid%m]; if(X==Y)ok = mid; else ng = mid; } //cout<m)cout<<'X'<y[ok%m])cout<<"X"<