#include <bits/stdc++.h>
using namespace std;
#define Samurai ios_base::sync_with_stdio(false), cout.tie(NULL), cin.tie(NULL);
#define ll long long
#define pb push_back
#define pu push
#define el '\n'
#define f0() for(int i=0; i<n; i++)
#define f1() for(int i=1; i<=n; i++)
const double PI = acos(-1.0);
const ll mod = 1e9+7, N = 2e5 + 5, OO = 0x3f3f3f3f;
int dx[] = { 0, 0, 1, -1, 1, 1, -1, -1 };
int dy[] = { -1, 1, 0, 0, -1, 1, 1, -1 };
void solve(){
int n,a,b,c; cin >> n >> a >> b >> c;
ll d = n/(a+b+c);
d *=3;
n%=(a+b+c);
if(n>0) n-=a, d++;
if(n>0) n-=b, d++;
if(n>0) n-=c, d++;
cout << d << el;
}
int main(){ Samurai
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int _t = 1;
cin >> _t;
for (int i = 1; i <= _t; i++)
{
solve();
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgU2FtdXJhaSBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKSwgY291dC50aWUoTlVMTCksIGNpbi50aWUoTlVMTCk7CiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgcGIgcHVzaF9iYWNrCiNkZWZpbmUgcHUgcHVzaAojZGVmaW5lIGVsICdcbicKI2RlZmluZSBmMCgpIGZvcihpbnQgaT0wOyBpPG47IGkrKykKI2RlZmluZSBmMSgpIGZvcihpbnQgaT0xOyBpPD1uOyBpKyspCmNvbnN0IGRvdWJsZSBQSSA9IGFjb3MoLTEuMCk7CmNvbnN0IGxsIG1vZCA9IDFlOSs3LCBOID0gMmU1ICsgNSwgT08gPSAweDNmM2YzZjNmOwppbnQgZHhbXSA9IHsgMCwgMCwgMSwgLTEsIDEsIDEsIC0xLCAtMSB9OwppbnQgZHlbXSA9IHsgLTEsIDEsIDAsID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