#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using db = double;
using ld = long double;
using str = string;
 
using pi = pair<int, int>;
using pd = pair<db, db>;
using pl = pair<ll, ll>;
using pld = pair<ld, ld>;
using ps = pair<str,str>;
 
using vb = vector<bool>;
using vi = vector<int>;
using vd = vector<db>;
using vl = vector<ll>;
using vld = vector<ld>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpd = vector<pd>;
using vps = vector<ps>;
using vpld = vector<pld>;
using vpl = vector<pl>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using si = set<int>;
using sl = set<ll>;
using sd = set<db>;
using sb = set<bool>;
using sld = set<ld>;
using ss = set<str>;
using spi = set<pi>;
using spd = set<pd>;
using spl = set<pl>;
using spld = set<pld>;
using sps = set<ps>;
using usi = unordered_set<int>;
using usl = unordered_set<ll>;
using usd = unordered_set<db>;
using usb = unordered_set<bool>;
using usld = unordered_set<ld>;
using uss = unordered_set<str>;
using uspi = unordered_set<pi>;
using uspd = unordered_set<pd>;
using uspl = unordered_set<pl>;
using uspld = unordered_set<pld>;
using usps = unordered_set<ps>;

#define mp make_pair
#define f first
#define s second
 
#define FOR(i,b,e) for (int i = b; i < e; i++)
#define ROF(i,e,b) for (int i = e; i >= b; i--)
#define repr(n) ROF(i,n,0)
#define rep(n) FOR(i,0,n)
 
#define sz(x) int((x).size)
#define pb push_back
#define ins insert
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define rall(x) x.rbegin(), x.rend()
#define sortrev(x) sort(rall(x));
#define rsz resize
#define ins insert 
#define ft front()
#define bk back()
#define pb push_back
#define eb emplace_back 
#define pf push_front 
#define ct count
#define es erase

#define LP(arr,sz,x) lower_bound(arr,arr + sz, x)
#define LPind(arr,sz,x) LP(arr,sz,x) - arr

pi add(char c, pi p) {
    if (c == 'U') p.s++;
    else if (c == 'L') p.f--;
    else if (c == 'R') p.f++;
    else if (c == 'D') p.s--;
    return p;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t; cin >> t;
    while (t--) {
        string x; cin >> x;
        // O(n^2) operations to calculate ending position after each obstacle, 
        // the obstacle is placed where the robot is going
        int sz = x.length();
        // calculate all positions that the robot is going to
        vpi v(sz + 1);
        v[0].f = 0; v[0].s = 0;
        FOR(i,1,sz + 1) {
            v[i] = add(x[i - 1], v[i - 1]);
        }
        // backtrack and place an obstacle at every v[i] from sz to 0
        pi temp;
        pi temp2;
        pi origin; origin.f = 0; origin.s = 0;
        pi answer;
        repr(sz) {
            // place an obstacle at v[i] and calculate the ending position
            temp.f = 0; temp.s = 0;
            FOR(j,0,sz) {
                temp2 = add(x[j],temp);
                if (temp2 != v[i]) temp = add(x[j],temp);
            }
            if (temp == origin) {
                answer = v[i];
                break;
            }
        }
        cout << answer.f << " " << answer.s << "\n";
    }
}