#include<cstdio>
int read(){
    int n=0;char c=getchar();bool f=0;
    while(c!='-'&&(c<'0'||c>'9'))c=getchar();
    if(c=='-'){f=1;c=getchar();}
    while(c>='0'&&c<='9'){n=n*10+c-'0';c=getchar();}
    if(f)return -n;
    return n;
}
int readstr(char* str){
    char c=getchar();
    while(c<=' ')c=getchar();
    int cnt=0;
    while(c>' '){str[cnt++]=c;c=getchar();}
    str[cnt]=0;
    return cnt;
}
void write(int n){
    char res[25]="";
    int t=0;
    if(n==0){
        putchar('0');
        return;
    }
    if(n<0){
        putchar('-');
        n=-n;
    }
    while(n){
        res[t++]=n%10+'0';
        n/=10;
    }
    while(t--)putchar(res[t]);
}
char str0[10000];
bool movement(int px,int py,char *str,int sx,int sy){
    if(*str==0){
        return px==0&&py==0;
    }else{
        int nx=px,ny=py;
        switch(*str){
            case 'U':
                ny=py+1;
                break;
            case 'D':
                ny=py-1;
                break;
            case 'L':
                nx=px-1;
                break;
            case 'R':
                nx=px+1;
                break;
        }
        if(nx==sx&&ny==sy){
            nx=px;
            ny=py;
        }
        return movement(nx,ny,str+1,sx,sy);
    }
}
bool chk(int px,int py,char *str,int &a,int &b){
    if(*str==0){
        a=0;
        b=0;
        return false;
    }
    int nx=px,ny=py;
    switch(*str){
            case 'U':
                ny=py+1;
                break;
            case 'D':
                ny=py-1;
                break;
            case 'L':
                nx=px-1;
                break;
            case 'R':
                nx=px+1;
                break;
    }
    if((nx!=0||ny!=0)&&movement(0,0,str0,nx,ny)){
        a=nx;
        b=ny;
        return true;
    }else{
        return chk(nx,ny,str+1,a,b);
    }
}

int main(){
    int t=read();
    while(t--){
        readstr(str0);
        int a=0,b=0;
        chk(0,0,str0,a,b);
        printf("%d %d\n",a,b);
    }
}