#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int T;
cin >> T; // Read the number of test cases
while (T--) {
int n;
cin >> n; // Read the number of rounds
vector<int> counts(3, 0); // To count the occurrences of 0, 1, and 2
for (int i = 0; i < n; i++) {
int s;
cin >> s; // Read each round result
counts[s]++;
}
int a, b, c;
cin >> a >> b >> c; // Read Alice's move restrictions
// Find the optimal number of wins Alice can have
int max_wins = min(counts[0], a) + min(counts[1], b) + min(counts[2], c);
cout << max_wins << endl; // Output the maximum wins Alice can have
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CiAgICBpbnQgVDsKICAgIGNpbiA+PiBUOyAgLy8gUmVhZCB0aGUgbnVtYmVyIG9mIHRlc3QgY2FzZXMKICAgIAogICAgd2hpbGUgKFQtLSkgewogICAgICAgIGludCBuOwogICAgICAgIGNpbiA+PiBuOyAgLy8gUmVhZCB0aGUgbnVtYmVyIG9mIHJvdW5kcwogICAgICAgIAogICAgICAgIHZlY3RvcjxpbnQ+IGNvdW50cygzLCAwKTsgIC8vIFRvIGNvdW50IHRoZSBvY2N1cnJlbmNlcyBvZiAwLCAxLCBhbmQgMgogICAgICAgIAogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSB7CiAgICAgICAgICAgIGludCBzOwogICAgICAgICAgICBjaW4gPj4gczsgIC8vIFJlYWQgZWFjaCByb3VuZCByZXN1bHQKICAgICAgICAgICAgY291bnRzW3NdKys7CiAgICAgICAgfQogICAgICAgIAogICAgICAgIGludCBhLCBiLCBjOwogICAgICAgIGNpbiA+PiBhID4+IGIgPj4gYzsgIC8vIFJlYWQgQWxpY2UncyBtb3ZlIHJlc3RyaWN0aW9ucwogICAgICAgIAogICAgICAgIC8vIEZpbmQgdGhlIG9wdGltYWwgbnVtYmVyIG9mIHdpbnMgQWxpY2UgY2FuIGhhdmUKICAgICAgICBpbnQgbWF4X3dpbnMgPSBtaW4oY291bnRzWzBdLCBhKSArIG1pbihjb3VudHNbMV0sIGIpICsgbWluKGNvdW50c1syXSwgYyk7CiAgICAgICAgCiAgICAgICAgY291dCA8PCBtYXhfd2lucyA8PCBlbmRsOyAgLy8gT3V0cHV0IHRoZSBtYXhpbXVtIHdpbnMgQWxpY2UgY2FuIGhhdmUKICAgIH0KICAgIAogICAgcmV0dXJuIDA7Cn0K