#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<array<int, 4>> a(n);
for (int i = 0; i < n; i++) cin >> a[i][1];
for (int i = 0; i < n; i++) cin >> a[i][2];
for (int i = 0; i < n; i++) cin >> a[i][3];
for (int i = 0; i < n; i++) a[i][0] = a[i][2] * 1e5 - a[i][1];
sort(a.begin(), a.end());
priority_queue<int> pq;
int tm = 0, ans = 0;
for (auto &[x, p, d, b] : a) {
tm += b;
pq.push(b);
if (tm > d) {
tm -= pq.top();
pq.pop();
}
}
tm = 0;
for (auto &[x, p, d, b] : a) {
tm += b;
ans += p * (d - tm);
}
cout << ans << "\n";
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgojZGVmaW5lIGludCBsb25nIGxvbmcKCnNpZ25lZCBtYWluKCkgewogICAgaW9zOjpzeW5jX3dpdGhfc3RkaW8oMCk7CiAgICBjaW4udGllKDApOwoKICAgIGludCB0OwogICAgY2luID4+IHQ7CiAgICB3aGlsZSAodC0tKSB7CiAgICAgICAgaW50IG47CiAgICAgICAgY2luID4+IG47CiAgICAgICAgCiAgICAgICAgdmVjdG9yPGFycmF5PGludCwgND4+IGEobik7CiAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspIGNpbiA+PiBhW2ldWzFdOyAgCiAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspIGNpbiA+PiBhW2ldWzJdOyAgCiAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspIGNpbiA+PiBhW2ldWzNdOyAgCiAgICAgICAgCiAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspIGFbaV1bMF0gPSBhW2ldWzJdICogMWU1IC0gYVtpXVsxXTsKCiAgICAgICAgc29ydChhLmJlZ2luKCksIGEuZW5kKCkpOwogICAgICAgIAogICAgICAgIHByaW9yaXR5X3F1ZXVlPGludD4gcHE7CiAgICAgICAgaW50IHRtID0gMCwgYW5zID0gMDsKCiAgICAgICAgZm9yIChhdXRvICZbeCwgcCwgZCwgYl0gOiBhKSB7CiAgICAgICAgICAgIHRtICs9IGI7CiAgICAgICAgICAgIHBxLnB1c2goYik7CiAgICAgICAgICAgIGlmICh0bSA+IGQpIHsKICAgICAgICAgICAgICAgIHRtIC09IHBxLnRvcCgpOwogICAgICAgICAgICAgICAgcHEucG9wKCk7CiAgICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIHRtID0gMDsKICAgICAgICBmb3IgKGF1dG8gJlt4LCBwLCBkLCBiXSA6IGEpIHsKICAgICAgICAgICAgdG0gKz0gYjsKICAgICAgICAgICAgYW5zICs9IHAgKiAoZCAtIHRtKTsKICAgICAgICB9CgogICAgICAgIGNvdXQgPDwgYW5zIDw8ICJcbiI7CiAgICB9Cn0=