# Enter your code here. Read input from STDIN. Print output to STDOUT
import numpy as np
T = int(raw_input())
for t in range(T):
    (N, A, B, C) = (int(x) for x in raw_input().split())
    # The largest N you can handle with a given budget
    max_n_by_budget = [1]*4096
    def max_n(budget):
        if budget < 0:
            return 0
        return max_n_by_budget[budget]
    current_max, i = 1, 0
    while current_max < N:
        i += 1
        current_max = sum([max_n(i - x) for x in (A, B, C)])
        max_n_by_budget[i] = max(current_max, 1)
    print i