#include #define rep(i,n) for(int i=0;i<(n);++i) using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); map> mp; mp["R"] = {1,0}; mp["L"] = {-1,0}; mp["U"] = {0,1}; mp["D"] = {0,-1}; int t; cin >> t; rep(i,t){ vector a1(2),a2(2); string d1,d2; cin >> a1[0] >> a1[1] >> d1; cin >> a2[0] >> a2[1] >> d2; ll l = 0; ll r = 4e9; while(1){ ll mi = (r+l)/2; a1[0]+=mp[d1][0]*mi; a1[1]+=mp[d1][1]*mi; a2[0]+=mp[d2][0]*mi; a2[1]+=mp[d2][1]*mi; ll c1,c2; c1 = abs(a1[0]-a2[0])+abs(a1[1]-a2[1]); a1[0]+=mp[d1][0]; a1[1]+=mp[d1][1]; a2[0]+=mp[d2][0]; a2[1]+=mp[d2][1]; c2 = abs(a1[0]-a2[0])+abs(a1[1]-a2[1]); if(c1