#include <bits/stdc++.h>
using namespace std;


//TEMPLATE
#define len(a)            (ll) a.size()
#define ms(a, x)          memset(a, x, sizeof a)
#define bitcount(n)       __builtin_popcountll(n)
#define FR                ios_base::sync_with_stdio(false);cin.tie(NULL)

#define cin1(a)           cin >> a
#define cin2(a, b)        cin >> a >> b
#define cin3(a, b, c)     cin >> a >> b >> c
#define cin4(a, b, c, d)  cin >> a >> b >> c >> d
#define cots(a)           cout << a << " "
#define cot1(a)           cout << a << "\n"
#define cot2(a, b)        cout << a << " " << b << "\n"
#define cot3(a, b, c)     cout << a << " " << b << " " << c << "\n"
#define cot4(a, b, c, d)  cout << a << " " << b << " " << c << " " << d << "\n"
#define cotcase(cs)       cout << "Case " << cs << ": "
#define yes               cout << "Yes\n"
#define no                cout << "No\n"
#define line              cout << "\n"

#define reversed(s)       reverse(s.begin(), s.end())
#define asort(s)          sort(s.begin(), s.end())
#define dsort(s)          sort(s.rbegin(), s.rend())
#define all(s)            s.begin(), s.end()
#define uniq(s)           s.resize(distance(s.begin(),unique(s.begin(), s.end())))
#define found(s, x)       (s.find(x) != s.end())

#define for0(i, n)        for (i = 0; i < n; i++)
#define for1(i, n)        for (i = 1; i <= n; i++)
#define fora(i, a, b)     for (i = a; i <= b; i++)
#define forb(i, b, a)     for (i = b; i >= a; i--)

#define ll                long long
#define pb                push_back
#define mp                make_pair
#define ld                long double
#define pii               pair <ll, ll>
#define piii              pair <ll, pii>
#define F                 first
#define S                 second
#define pi                acos(-1.0)

#define bug(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << '\n'
void err(istringstream *iss) {}
template<typename T, typename... Args>
void err(istringstream *iss, const T a, const Args... args) {
    string _name;
    *iss >> _name;
    if (_name.back()==',') _name.pop_back();
    cerr << _name << " = " << fixed << setprecision(5) << a << "; ", err(iss, args...);
}

const ll INF = LLONG_MAX;
const ll SZ = 4e5+5;
const ll mod = 1e9+7;



string s, s1, s2;
ll n, k, ans = 0;
ll a[SZ];
//ll b[SZ];

ll nowx(char c, ll x) {
    if(c == 'L') x--;
    if(c == 'R') x++;
    return x;
}

ll nowy(char c, ll y) {
    if(c == 'D') y--;
    if(c == 'U') y++;
    return y;
}

int main() {
    FR;
    ll cs = 0, tc = 1, x, y, z, i, j, g, p, q, sum = 0, c = 0, t = 0;
//    ll a, b, d;
//    string s, s1, s2;

    cin1(tc);

    while(tc--) {
        cin1(s);
        n = len(s);

        vector <pii> vc;
        x = y = 0;
        for0(i, n) {
            x = nowx(s[i], x), y = nowy(s[i], y);
            vc.pb({x, y});
        }

        bool f = 0;
        for(auto p: vc) {
            x = y = 0;
            for0(i, n) {
                ll tx = nowx(s[i], x), ty = nowy(s[i], y);
                if(tx != p.F || ty != p.S) x = tx, y = ty;
            }
            if(x == 0 && y == 0) {
                f = 1;
                x = p.F, y = p.S;
                break;
            }
        }

        if(!f) x = y = 0;
        cot2(x, y);
    }

    return 0;
}

