#!/usr/bin/python
# another fine solution by misof

import sys

def weight(q,a,b): return (q+1)*a+b

def Solve(a,b):
  if (a+b==1): return 0
  q=1
  while not (weight(q,a,b) <= 2**q): q+=1
  if (a%2==0):
    c = a/2
    d = b/2
  else:
    c = (a+1)/2
    d = max(0, (b+2-q)/2 )
  a1, b1 = c, a-c+d
  a2, b2 = a-c, c+b-d
  if weight(q-1,a1,b1)<=2**(q-1) and weight(q-1,a2,b2)<=2**(q-1): res=q
  else: res=q+1
  return res

T = int(sys.stdin.readline())
for test in range(T):
  empty = sys.stdin.readline()
  tokens = sys.stdin.readline().strip().split(' ')
  N,L,S = int(tokens[0]), int(tokens[1]), tokens[2]
  A = min(L,N)
  if S=="no": A = N-A
  B = N-A
  print Solve(A,B)

