#include <bits/stdc++.h>

#define endl "\n"
#define int long long
#define debug(statement) \
    if (debugging)       \
    cerr << statement << endl
#define debug_variable(var) \
    if (debugging)          \
    cerr << (#var) << ": " << var << endl

const bool debugging = 1;

using namespace std;

template <class T>
ostream &operator<<(ostream &os, vector<T> V)
{
    for (auto v : V)
    {
        os << v << " ";
    }
    return os << "";
}

template <class T>
ostream &operator<<(ostream &os, set<T> S)
{
    for (auto s : S)
    {
        os << s << " ";
    }
    return os << "";
}

template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P)
{
    return os << P.first << " " << P.second;
}

template <class L, class R>
ostream &operator<<(ostream &os, map<L, R> M)
{
    os << endl;
    for (auto m : M)
    {
        os << m << endl;
    }
    return os << "";
}

void solve()
{
    string S;
    cin >> S;
    int N = S.size();
    int X = 0, Y = 0;
    for (int i = 0; i < N; i++)
    {
        if (S[i] == 'L')
        {
            X -= 1;
        }
        else if (S[i] == 'R')
        {
            X += 1;
        }
        else if (S[i] == 'D')
        {
            Y -= 1;
        }
        else if (S[i] == 'U')
        {
            Y += 1;
        }
        pair<int, int> rock = {X, Y};
        int Xsim = 0, Ysim = 0;
        for (int i = 0; i < N; i++)
        {
            if (S[i] == 'L')
            {
                if (!(rock.first == Xsim - 1 && rock.second == Ysim))
                {
                    Xsim -= 1;
                }
            }
            else if (S[i] == 'R')
            {
                if (!(rock.first == Xsim + 1 && rock.second == Ysim))
                {
                    Xsim += 1;
                }
            }
            else if (S[i] == 'D')
            {
                if (!(rock.first == Xsim && rock.second == Ysim - 1))
                {
                    Ysim -= 1;
                }
            }
            else if (S[i] == 'U')
            {
                if (!(rock.first == Xsim && rock.second == Ysim + 1))
                {
                    Ysim += 1;
                }
            }
        }
        if (Xsim == 0 && Ysim == 0)
        {
            cout << rock << endl;
            return;
        }
    }
    cout << 0 << " " << 0 << endl;
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int no_of_testcases;
    cin >> no_of_testcases;
    while (no_of_testcases-- > 0)
    {
        solve();
    }
    return 0;
}