#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#define FOR(i,a,b) for(i=(a);i<=(b);i++)
#define ROF(i,a,b) for(i=(a);i>=(b);i--)
#define mmt(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define mp make_pair
#define N 1110
using namespace std;
typedef long long LL;
typedef long double LD;
char ss[N],sn[N];
int main()
{
  ios::sync_with_stdio(false);
  int i,T,x,y,j;
  scanf("%d",&T);
  ROF(j,T,1)
  {
    FOR(i,1,3) scanf("%s",ss);
    scanf("%s",sn);
    FOR(i,1,2) scanf("%s",ss);
    scanf("%d",&x);
    FOR(i,1,3) scanf("%s",ss);
    scanf("%d",&y);
    scanf("%s",ss);
    if (sn[0]=='h')
    {
      int c=y-x;
      if (c<y) c++;
      c=max(c,0);
      printf("%d ",c);
      c=30+y-x;
      if (c>y) c--;
      c=max(min(c,30),0);
      printf("%d\n",c);
    }else
    {
      int c=max(y-x,0);
      printf("%d ",c);
      c=max(min(y+30-x,30),0);
      printf("%d\n",c);
    }
  }
  return 0;
}