#include <cstdio> #include <cmath> #include <cstring> #include <string> #include <sstream> #include <algorithm> #include <iostream> #include <iomanip> #include <map> #include <set> #include <list> #include <queue> #include <stack> #include <vector> #include <cassert> using namespace std; #define pb push_back #define mp make_pair #define REP(i, n) for (int i = 0; i < (int)(n); ++i) typedef long long LL; typedef pair<int, int> PII; typedef long double Double; LL mx[100000]; const int UPTO = 5000; LL n; int a, b, c; inline void update(LL &x, LL y) { x = max(x, y); } int main() { int tt; scanf("%d", &tt); REP(test, tt) { scanf("%lld", &n); scanf("%d%d%d", &a, &b, &c); if (a > b) swap(a, b); if (a > c) swap(a, c); if (b > c) swap(b, c); for (int i = 0; i <= UPTO; ++i) mx[i] = 0; mx[0] = 1; for (int i = 0; i <= UPTO; ++i) { if (mx[i] >= n) { printf("%d\n", i); break; } if (i) mx[i] = max(mx[i], mx[i - 1]); for (int j = max(0, i + a - b); j <= i; ++j) { int newCost = max(i + a, j + b); update(mx[newCost], mx[i] + mx[j]); for (int k = max(0, j + b - c); k <= j; ++k) { newCost = max(max(i + a, j + b), k + c); update(mx[newCost], mx[i] + mx[j] + mx[k]); } } } } return 0; }