__author__ = 'y' # from math import ceil T = int(input()) for t in range(T): N, A, B, C = map(int, input().split()) if N == 1: print(0) continue distinguish = [1 for i in range(10000)] i = 1 distinguish[0] = 1 while True: distinguish[i] = (distinguish[i-A] if i-A >= 0 else 0) + \ (distinguish[i-B] if i-B >= 0 else 0) + \ (distinguish[i-C] if i-C >= 0 else 0) distinguish[i] = max(distinguish[i], distinguish[i-1]) if distinguish[i] >= N: break i += 1 print(i)