#include using namespace std; typedef long long ll; typedef pair pii; #define F first #define S second const int MAXN = 100 + 10; int n, a[MAXN], b[2][3], c[2]; int cal(int w){ int ret = 0; for (int month = 1; month < b[w][1]; month++) ret += a[month]; ret += b[w][2]; return ret; } int main(){ ios::sync_with_stdio(false); cin.tie(0); int te; cin >> te; while (te--){ cin >> n; int sm = 0; for (int i = 1; i <= n; i++) cin >> a[i], sm += a[i]; for (int w = 0; w < 2; w++){ for (int i = 0; i < 3; i++) cin >> b[w][i]; c[w] = cal(w); } int ans = 1; if (c[1] == sm+1) c[1]--, ans++; if (c[0] == sm+1) c[0]--, ans--; if (c[0] <= c[1]) ans += c[1]-c[0]; else{ if (b[0][0]%4) ans += sm - (c[0] - c[1]); else ans += sm+1 - (c[0] - c[1]); b[0][0]++; } while (b[0][0] < b[1][0]){ ans += b[0][0]%4? sm: sm+1; b[0][0]++; } cout << ans << "\n"; } return 0; }