// karanaggarwal #include <bits/stdc++.h> #include <cstring> #include <queue> #include <stack> #include <iostream> #include <vector> #include <algorithm> #include <cstdio> #include <unordered_map> #include <unordered_set> #include <map> #include <set> using namespace std; #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cerr << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...); } #else #define trace(...) #endif #define si(x) scanf("%d",&x) #define F first #define S second #define PB push_back #define MP make_pair typedef long long LL; typedef pair<int,int> PII; typedef vector<int> VI; typedef vector<PII> VPII; long long DP[100000]; int main() { int t; si(t); while(t--) { int A[3]; LL N; cin>>N; cin>>A[0]>>A[1]>>A[2]; DP[0] = 1; int i = 0; while(1) { if(DP[i]>=N) { cout<<i<<endl; break; } i++; DP[i] = 0; for(int j = 0; j<3; j++) if(i>=A[j])DP[i] += DP[i-A[j]]; DP[i] = max(DP[i-1], DP[i]); } } return 0; }