#include <bits/stdc++.h>   using namespace std;   const int DAYS = 7;   int val[DAYS];   void solve() {     int k;     cin >> k;     int tot = 0;     for (int i = 0; i < DAYS; ++i) {       cin >> val[i];       tot += val[i];     }     int res = 1 << 30;     for (int start = 0; start < DAYS; ++start) {       if (val[start]) {         int tmp = k;         int passed = 0;         for (int j = start; j < DAYS && tmp > 0; ++j) {           passed++;           tmp -= val[j];         }         if (tmp > tot) {           tmp -= tot;           int cycles = tmp / tot;           passed += cycles * DAYS;           tmp %= tot;           tmp += tot;         }         int j = 0;         while (tmp > 0) {           tmp -= val[j];           passed++;           j = (j + 1) % DAYS;         }         res = min(res, passed);       }     }     cout << res << endl;   }   int main() {     ios::sync_with_stdio(false);     int T;     cin >> T;     while (T--) {       solve();     }     return 0;   }   