#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;

ll dp[101010];

ll get(int x){
	if (x>0){
		return max(1ll, dp[x]);
	}
	if (x<0) return 0;
	return 1;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int tcs;
	cin>>tcs;
	for (int tc=0;tc<tcs;tc++){
		ll n;
		cin>>n;
		int a,b,c;
		cin>>a>>b>>c;
		if (n==1){
			cout<<0<<endl;
			goto loppu;
		}
		for (int i=0;i<10101;i++){
			dp[i]=1;
		}
		for (int i=1;i<10101;i++){
			dp[i]=get(i-a)+get(i-b)+get(i-c);
			if (dp[i]>=n){
				cout<<i<<endl;
				break;
			}
		}
		loppu:;
	}
}