For her next karate demonstration, Ada will break some bricks.
Ada stacked three bricks on top of each other. Initially, their widths (from top to bottom) are $W_1, W_2, W_3$.
Ada's strength is $S$. Whenever she hits a stack of bricks, consider the largest $k \ge 0$ such that the sum of widths of the topmost $k$ bricks does not exceed $S$; the topmost $k$ bricks break and are removed from the stack. Before each hit, Ada may also decide to reverse the current stack of bricks, with no cost.
Find the minimum number of hits Ada needs in order to break all bricks if she performs the reversals optimally. You are not required to minimise the number of reversals.

-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first and only line of each test case contains four space-separated integers $S$, $W_1$, $W_2$ and $W_3$.

-----Output-----
For each test case, print a single line containing one integer ― the minimum required number of hits.

-----Constraints-----
- $1 \le T \le 64$
- $1 \le S \le 8$
- $1 \le W_i \le 2$ for each valid $i$
- it is guaranteed that Ada can break all bricks

-----Subtasks-----
Subtask #1 (50 points): $W_1 = W_2 = W_3$
Subtask #2 (50 points): original constraints

-----Example Input-----
3
3 1 2 2
2 1 1 1
3 2 2 1

-----Example Output-----
2
2
2

-----Explanation-----
Example case 1: Ada can reverse the stack and then hit it two times. Before the first hit, the widths of bricks in the stack (from top to bottom) are $(2,2,1)$. After the first hit, the topmost brick breaks and the stack becomes $(2,1)$. The second hit breaks both remaining bricks.
In this particular case, it is also possible to hit the stack two times without reversing. Before the first hit, it is $(1, 2, 2)$. The first hit breaks the two bricks at the top (so the stack becomes $(2)$) and the second hit breaks the last brick.

Starter code:

Solutions:
t=int(input())
for i in range(t):
 n,w1,w2,w3=map(int,input().split())
 if n>=w1+w2+w3:
  print(1)
 elif n>=w1+w2 or n>=w2+w3:
  print(2)
 else:
  print(3)

t=int(input())
for i in range(t):
 n,w1,w2,w3=map(int,input().split())
 if n>=w1+w2+w3:
  print(1)
 elif n>=w1+w2 or n>=w2+w3:
  print(2)
 else:
  print(3)

t = int(input())
for i in range(t):
 n,w1,w2,w3 = map(int,input().split())
 if n >= w1+w2+w3:
  print(1)
 elif n >= w1+w2 or n >= w2+w3:
  print(2)
 else:
  print(3)

t = int(input())
for i in range(t):
 n,w1,w2,w3 = map(int,input().split())
 if n >= w1+w2+w3:
  print(1)
 elif n >= w1+w2 or n >= w2+w3:
  print(2)
 else:
  print(3)

# cook your dish here
t = int(input())
for i in range(t):
 n,w1,w2,w3 = list(map(int,input().split()))
 if n >= w1+w2+w3:
  print(1)
 elif n >= w1+w2 or n >= w2+w3:
  print(2)
 else:
  print(3)
 
   
  


# cook your dish here
for i in range(int(input())):
 s,w1,w2,w3=list(map(int,input().split()))
 if(s>=w1+w2+w3):
  print(1)
 elif(s>=w1+w2 or s>=w2+w3):
  print(2)
 else:
  print(3)
  


# cook your dish here
for t in range(int(input())):
 s,w1,w2,w3=list(map(int,input().split()))
 if w1+w2+w3<=s:
  print('1')
 elif w1+w2<=s or w2+w3<=s:
  print('2')
 else:
  print('3')


# cook your dish here
import math
t=int(input())
while t>0:
 s,a,b,c=map(int,input().split())
 if s>=a+b+c:
  print("1")
 elif s>=a+b or s>=b+c:
  print("2")
 else:
  print("3")
 t-=1

def solve(s, a, b, c):
 if s >= a + b + c:
  return 1
 if s >= a + b:
  return 2
 if s >= b + c:
  return 2
 return 3
 
def main():
 t = int(input())# cook your dish here
 
 for _ in range(t):
  line = input().strip()
  s, a,b,c = [int(x) for x in line.split(" ")]
  print(solve(s, a, b, c))
  

main()

for _ in range(int(input())):
 n=list(map(int,input().split()))
 s=n[0]
 w=n[1:]
 c=0
 for i in range(3):
  if sum(w)<=s:
   c=c+1
   break
  elif sum(w[:2])<=s:
   w=w[2:]
   c=c+1
  else:
   w=w[1:]
   c+=1
 print(c)# cook your dish here


for _ in range(int(input())):
 a = list(map(int,input().split()))
 s = a.pop(0)
 sm = sum(a)
 ans = 0


 while sm>0:
  a1 = a[::-1]
  s1, i = 0, 0
  while s1<s and i<len(a):
   s1+=a[i]
   i+=1
  if s1>s:
   i-=1
   s1-=a[i]
  s2, i1 = 0, 0
  while s2<s and i1<len(a):
   s2+=a1[i1]
   i1+=1
  if s2>s:
   i1-=1
   s2-=a[i1]
  # print(sm, s1, s2, a, i, i1, ans)
  if i1>i:
   sm-=s2
   a = a1[i1:][::-1]
  else:
   sm-=s1
   a = a[i:]
  ans+=1
 print(ans)





for _ in range(int(input())):
 a = list(map(int,input().split()))
 s = a.pop(0)
 sm = sum(a)
 ans = 0


 while sm>0:
  a1 = a[::-1]
  s1, i = 0, 0
  while s1<s and i<len(a):
   s1+=a[i]
   i+=1
  if s1>s:
   i-=1
   s1-=a[i]
  s2, i1 = 0, 0
  while s2<s and i1<len(a):
   s2+=a1[i1]
   i1+=1
  if s2>s:
   i1-=1
   s2-=a[i1]
  # print(sm, s1, s2, a, i, i1, ans)
  if i1>i:
   sm-=s2
   a = a1[i1:][::-1]
  else:
   sm-=s1
   a = a[i:]
  ans+=1
 print(ans)





for _ in range(int(input())):
 s,w1,w2,w3= map(int,input().split())
 if w1+w2+w3<=s:
  ans = 1
 elif w1+w2<=s or w2+w3<=s:
  ans = 2
 else:
  ans = 3
 print(ans)

# cook your dish here
a= int(input())
while (a!=0):
 S,x,y,z=input().split(" ")
 x=int(x)
 y=int(y)
 z=int(z)
 S=int(S)
 count=0
 if x+y+z<=S:
  count=1
 elif (x+y<=S and z<=S) or (y+z<=S and x<=S):
  count=2

 else:
  count=3
 print(count)
 a-=1

# cook your dish here
for _ in range(int(input())):
 S,W1,W2,W3=(int(i) for i in input().split(' '))
 if(W1+W2+W3<=S):
  print(1)
 elif(S>=(W1+W2) or S>=(W2+W3)):
  print(2)
 else:
  print(3)

# cook your dish here
 
for _ in range(int(input())):
 L = list(map(int, input().split()))
 S = L[0]
 W = L[1:]
 c = 0
 if W[0] + W[1] <= S:
  if W[0] + W[1] + W[2] <= S:
   print(1)
  else:
   print(2)
 elif W[2] + W[1] <= S:
  print(2)
 else:
  print(3)

for _ in range(int(input())):
 s,w1,w2,w3=list(map(int,input().split()))
 c=w1+w2+w3
 if s>=c:
  print(1)
 elif w1+w2<=s or w2+w3<=s:
  print(2)
 else:
  print(3)
   
  


# cook your dish here
for h in range(int(input())):
 s,w1,w2,w3=map(int,input().split())
 sum1=w1+w2+w3
 if s>=sum1:
  print(1)
 elif s>=(w1+w2)or s>=(w3+w2):
  print(2)
 
 else:
  print(3)

# cook your dish here
for _ in range(int(input())):
 s,w1,w2,w3 = list(map(int,input().split()))
 tot = w1+w2+w3
 if tot<=s :
  print(1)
 elif s == 1 :
   print(3)
 elif s == 2 :
  if tot>=5:
   print(3)
  elif w2 == 2 :
   print(3)
  else :
   print(2)
 elif s == 3 :
  if tot <=5 :
   print(2)
  else :
   print(3)
 else :
   print(2)
    


for _ in range(int(input())):
 s,w1,w2,w3 = list(map(int,input().split()))
 tot = w1+w2+w3
 if tot<=s :
  print(1)
 elif s == 1 :
  print(3)
 elif s == 2 :
  if tot>=5 :
   print(3)
  elif w2 == 2 :
   print(3)
  else :
   print(2)
 elif s == 3 :
  if tot<=5 :
   print(2)
  else :
   print(3)
 else :
  print(2)


for i in range(int(input())):
 s,w1,w2,w3=map(int,input().split())
 c=0
 sum=w1+w2+w3
 if w1<w3:
  tmp=w3
  w3=w1
  w1=tmp
 if w1+w2+w3<=s:
  print("1")
 elif w1+w2<=s:
  print("2")
 elif w1<=s:
  c=c+1
 if c==1:
  if w2+w3<=s:
   print("2")
  elif w2+w3>s:
   print("3")

# cook your dish here
try:
 T=int(input())
 for t in range(T):
  
  w = list(map(int,input().split()))
  s = w.pop(0)
  c=0
  # print(w,s)
  while len(w) > 0:
   r=s
   c+=1
   # print(c,w)
   if w[0] > w[-1]:
    while len(w) > 0 and r >= w[0]:
     r-=w[0]
     w.pop(0)
   else:
    while len(w) > 0 and r >= w[-1]:
     r-=w[-1]
     w.pop(-1) 
  print(c)
except:
 pass

# cook your dish here
try:
 T=int(input())
 for t in range(T):
  
  w = list(map(int,input().split()))
  s = w.pop(0)
  c=0
  # print(w,s)
  while len(w) > 0:
   r=s
   c+=1
   # print(c,w)
   if w[0] > w[-1]:
    while len(w) > 0 and r >= w[0]:
     r-=w[0]
     w.pop(0)
   else:
    while len(w) > 0 and r >= w[-1]:
     r-=w[-1]
     w.pop(-1) 
  print(c)
except:
 pass

t = int(input())

for _ in range(t):
 s, w1, w2, w3 = [int(x) for x in input().split()]
 
 if(w1+w2+w3 <= s):
  print(1)
 elif(w1+w2 <= s or w3+w2 <= s):
  print(2)
 else:
  print(3)