#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

typedef long long ll;

ll memo[10000];

inline ll get(int i) {
    return i >= 0 ? memo[i] : 0LL;
}

int main() {
    int T;
    cin >> T;
    while (T--) {
        ll N;
        int A, B, C, i;
        cin >> N >> A >> B >> C;
        for (i = 0; ; i++) {
            if ((memo[i] = max(1LL, get(i-A) + get(i-B) + get(i-C))) >= N) {
                break;
            }
        }
        cerr << endl;
        cout << i << endl;
    }
    return 0;
}