#include <bits/stdc++.h>
using namespace std ;

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef long double ld ;

const ll MOD = 1e9 + 7 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

priority_queue <ll> pq, pqTemp ;
ll arr[200005] ;
bool arrCheck[200005] ;
ll n, xInd, yInd, k ;
double x, y ;

bool check(ll target)
{
    ll ans = 0 ;
    pqTemp = pq ;
    for (int i = 1; i <= target; i++) {
        arrCheck[i] = false ;
    }
    ll combo = xInd * yInd ;
    double comboVal = (x + y) / 100, xVal = x / 100, yVal = y / 100 ;
    for (int i = combo; i <= target; i += combo) {
        arrCheck[i] = true ;
        ans += (pqTemp.top() * comboVal) ;
        pqTemp.pop() ;
    }
    if (x > y) {
        for (int i = xInd; i <= target; i += xInd) {
            if (!arrCheck[i]) {
                arrCheck[i] = true ;
                ans += (pqTemp.top() * xVal) ;
                pqTemp.pop() ;
            }
        }
        for (int i = yInd; i <= target; i += yInd) {
            if (!arrCheck[i]) {
                arrCheck[i] = true ;
                ans += (pqTemp.top() * yVal) ;
                pqTemp.pop() ;
            }
        }
    }
    else {
        for (int i = yInd; i <= target; i += yInd) {
            if (!arrCheck[i]) {
                arrCheck[i] = true ;
                ans += (pqTemp.top() * yVal) ;
                pqTemp.pop() ;
            }
        }
        for (int i = xInd; i <= target; i += xInd) {
            if (!arrCheck[i]) {
                arrCheck[i] = true ;
                ans += (pqTemp.top() * xVal) ;
                pqTemp.pop() ;
            }
        }
    }
    if (ans >= k)   return true ;
    else    return false ;
}

int main()
{
    ll t ;
    cin >> t ;
    while (t--) {
        while (!pq.empty()) {
            pq.pop() ;
        }
        cin >> n ;
        for (int i = 1; i <= n; i++) {
            scanf("%lld", &arr[i]) ;
            pq.push(arr[i]) ;
        }
        cin >> x >> xInd >> y >> yInd >> k ;
        ll L = 1, R = n + 1, mid, ans = -1 ;
        while (L <= R) {
            mid = (L + R) / 2 ;
            if (check(mid)) {
                ans = mid ;
                R = mid - 1 ;
            }
            else {
                L = mid + 1 ;
            }
        }
        printf("%lld\n", ans) ;
    }

    return 0 ;
}


#include <bits/stdc++.h>
using namespace std ;

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef long double ld ;

const ll MOD = 1e9 + 7 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

priority_queue <ll> pq ;
ll arr[200005] ;
bool arrCheck[200005] ;
ll n, xInd, yInd, k ;
double x, y ;

bool check(ll target)
{
    while (!pq.empty()) {
        pq.pop() ;
    }
    for (int i = 1; i <= n; i++) {
        pq.push(arr[i]) ;
    }
    for (int i = 1; i <= target; i++) {
        arrCheck[i] = false ;
    }
    ll ans = 0 ;
    ll comboInd = (xInd * yInd) / __gcd(xInd, yInd) ;
    double comboVal = (x + y) / 100, xVal = x / 100, yVal = y / 100 ;
    for (int i = comboInd; i <= target; i += comboInd) {
        arrCheck[i] = true ;
        ans += (pq.top() * comboVal) ;
        pq.pop() ;
    }
    if (x > y) {
        for (int i = xInd; i <= target; i += xInd) {
            if (!arrCheck[i]) {
                arrCheck[i] = true ;
                ans += (pq.top() * xVal) ;
                pq.pop() ;
            }
        }
        for (int i = yInd; i <= target; i += yInd) {
            if (!arrCheck[i]) {
                arrCheck[i] = true ;
                ans += (pq.top() * yVal) ;
                pq.pop() ;
            }
        }
    }
    else {
        for (int i = yInd; i <= target; i += yInd) {
            if (!arrCheck[i]) {
                arrCheck[i] = true ;
                ans += (pq.top() * yVal) ;
                pq.pop() ;
            }
        }
        for (int i = xInd; i <= target; i += xInd) {
            if (!arrCheck[i]) {
                arrCheck[i] = true ;
                ans += (pq.top() * xVal) ;
                pq.pop() ;
            }
        }
    }
    if (ans >= k)   return true ;
    else    return false ;
}

int main()
{
    ll t ;
    cin >> t ;
    while (t--) {
        cin >> n ;
        for (int i = 1; i <= n; i++) {
            scanf("%lld", &arr[i]) ;
        }
        cin >> x >> xInd >> y >> yInd >> k ;
        ll L = 1, R = n, mid, ans = -1 ;
        while (L <= R) {
            mid = (L + R) / 2 ;
            if (check(mid)) {
                ans = mid ;
                R = mid - 1 ;
            }
            else {
                L = mid + 1 ;
            }
        }
        printf("%lld\n", ans) ;
    }

    return 0 ;
}


#include <bits/stdc++.h>
using namespace std ;

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef long double ld ;

const ll MOD = 1e9 + 7 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

priority_queue <ll> pq ;
ll arr[200005] ;
bool arrCheck[200005] ;
ll n, x, xInd, y, yInd, k ;

bool check(ll target)
{
    while (!pq.empty()) {
        pq.pop() ;
    }
    for (int i = 1; i <= n; i++) {
        pq.push(arr[i]) ;
    }
    for (int i = 1; i <= target; i++) {
        arrCheck[i] = false ;
    }
    ll ans = 0 ;
    ll comboInd = (xInd * yInd) / __gcd(xInd, yInd) ;
    for (int i = comboInd; i <= target; i += comboInd) {
        arrCheck[i] = true ;
        ans += (pq.top() * (x + y) ) ;
        pq.pop() ;
    }
    if (x > y) {
        for (int i = xInd; i <= target; i += xInd) {
            if (!arrCheck[i]) {
                arrCheck[i] = true ;
                ans += (pq.top() * x) ;
                pq.pop() ;
            }
        }
        for (int i = yInd; i <= target; i += yInd) {
            if (!arrCheck[i]) {
                arrCheck[i] = true ;
                ans += (pq.top() * y) ;
                pq.pop() ;
            }
        }
    }
    else {
        for (int i = yInd; i <= target; i += yInd) {
            if (!arrCheck[i]) {
                arrCheck[i] = true ;
                ans += (pq.top() * y) ;
                pq.pop() ;
            }
        }
        for (int i = xInd; i <= target; i += xInd) {
            if (!arrCheck[i]) {
                arrCheck[i] = true ;
                ans += (pq.top() * x) ;
                pq.pop() ;
            }
        }
    }
    if (ans >= k)   return true ;
    else    return false ;
}

int main()
{
    ll t ;
    cin >> t ;
    while (t--) {
        cin >> n ;
        for (int i = 1; i <= n; i++) {
            scanf("%lld", &arr[i]) ;
            arr[i] /= 100 ;
        }
        cin >> x >> xInd >> y >> yInd >> k ;
        ll L = 1, R = n, mid, ans = -1 ;
        while (L <= R) {
            mid = (L + R) / 2 ;
            if (check(mid)) {
                ans = mid ;
                R = mid - 1 ;
            }
            else {
                L = mid + 1 ;
            }
        }
        printf("%lld\n", ans) ;
    }

    return 0 ;
}


#include<bits/stdc++.h>

using namespace std;

const int size = 2e5 + 7;
long long int arr[size];

int gcd(int a, int b){
	if(b ==0) return a;
	if(b>a) return gcd(b,a);
	return gcd(b, a%b);
}

int q, n,x,a,y,b;
long long int k;
int t1, t2, t3, l, r, ans;

bool check(int mid){
	long long int total = 0;
	int c = 0;
	long long int p = a;
	p*=b;
	p/=gcd(a,b);
	t1 = mid/a;
	t2 = mid/b;
	t3 = mid/(int(p));
	t1 -= t3;
	t2 -= t3;

	if(t3 > 0) total += arr[t3-1]*(x+y);
	if(t1 > 0){
		total += arr[t1 + t3 -1]*x;
		if(t3 > 0) total -= arr[t3-1]*x;
	}
	if(t2 > 0){
		total += arr[t3 + t2 + t1 -1]*y;
		if(t3 + t1 > 0) total -= arr[t3 + t1 - 1]*y;
	}
	return total >= k;
}

int main(){

	cin>>q;
	while(q--){
		ans = INT_MAX;

		cin>>n;

		for(int x=0;x<n;x++){
			cin>>arr[x];
			arr[x]/=100;
		}

		sort(arr, arr+n);
		reverse(arr, arr+n);

		// for(int x=0;x<n;x++) cout<<arr[x]<<" ";
		// cout<<"\n";
		cin>>x>>a;
		cin>>y>>b;
		cin>>k;

		for(int i=1;i<n;i++) arr[i] += arr[i-1];

		if(x < y){
			swap(x, y);
			swap(a, b);
		}
		l = 0;
		r = n;
		// cout<<l<<" "<<r<<" "<<x<<" "<<a<<" "<<y<<" "<<b<<" "<<k<<"\n";
		while(l <= r){
			int mid = l + (r-l)/2;
			if(check(mid)){
				ans = mid;
				r = mid -1;
			} else {
				l = mid + 1;
			}
		}

		if(ans == INT_MAX) cout<<"-1\n";
		else cout<<ans<<"\n";

	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int size = 2e5 + 7;
long long int arr[size];

int gcd(int a, int b){
	if(b ==0) return a;
	if(b>a) return gcd(b,a);
	return gcd(b, a%b);
}

int q, n,x,a,y,b;
long long int k;
int t1, t2, t3, l, r, ans;

bool check(int mid){
	long long int total = 0;
	int c = 0;
	long long int p = a;
	p*=b;
	p/=gcd(a,b);
	t1 = mid/a;
	t2 = mid/b;
	t3 = mid/(int(p));
	t1 -= t3;
	t2 -= t3;

	if(t3 > 0) total += arr[t3-1]*(x+y);
	if(t1 > 0){
		total += arr[t1 + t3 -1]*x;
		if(t3 > 0) total -= arr[t3-1]*x;
	}
	if(t2 > 0){
		total += arr[t3 + t2 + t1 -1]*y;
		if(t3 + t1 > 0) total -= arr[t3 + t1 - 1]*y;
	}
	return total >= k;
}

int main(){

	cin>>q;
	while(q--){
		ans = INT_MAX;

		cin>>n;
		memset(arr, 0, sizeof(arr));

		for(int x=0;x<n;x++){
			cin>>arr[x];
			arr[x]/=100;
		}

		sort(arr, arr+n);
		reverse(arr, arr+n);

		// for(int x=0;x<n;x++) cout<<arr[x]<<" ";
		// cout<<"\n";
		cin>>x>>a;
		cin>>y>>b;
		cin>>k;

		for(int i=1;i<n;i++) arr[i] += arr[i-1];

		if(x < y){
			swap(x, y);
			swap(a, b);
		}
		l = 0;
		r = n;
		// cout<<l<<" "<<r<<" "<<x<<" "<<a<<" "<<y<<" "<<b<<" "<<k<<"\n";
		while(l <= r){
			int mid = l + (r-l)/2;
			if(check(mid)){
				ans = mid;
				r = mid -1;
			} else {
				l = mid + 1;
			}
		}

		if(ans == INT_MAX) cout<<"-1\n";
		else cout<<ans<<"\n";

	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int size = 2e5 + 7;
long long int arr[size];

int gcd(int a, int b){
	if(b ==0) return a;
	if(b>a) return gcd(b,a);
	return gcd(b, a%b);
}

int q, n,x,a,y,b;
long long int k;
int t1, t2, t3, l, r, ans;

bool check(int mid){
	long long int total = 0;
	int c = 0;
	long long int p = a;
	p*=b;
	p/=gcd(a,b);
	t1 = t2 = t3 = 0;
	// cout<<n<<"\n";
	for(int i=1;i<=mid;i++){
		if(i%a == 0) t1++;
		if(i%b == 0) t2++;
		if(i%a == 0 && i%b ==0) t3++;
	}
	for(int i=0;i<t3;i++){
		total += arr[i]*(x+y);
	}
	for(int i=0;i<t1-t3;i++){
		total += arr[t3+i]*x;
	}
	for(int i=0;i<t2-t3;i++){
		total += arr[t1+i]*y;
	}
	// cout<<total<<"\n";
	return total >= k;
}

int main(){

	cin>>q;
	while(q--){
		ans = INT_MAX;

		cin>>n;
		memset(arr, 0, sizeof(arr));

		for(int x=0;x<n;x++){
			cin>>arr[x];
			arr[x]/=100;
		}

		sort(arr, arr+n);
		reverse(arr, arr+n);

		// for(int x=0;x<n;x++) cout<<arr[x]<<" ";
		// cout<<"\n";
		cin>>x>>a;
		cin>>y>>b;
		cin>>k;

		// for(int i=1;i<n;i++) arr[i] += arr[i-1];

		if(x < y){
			swap(x, y);
			swap(a, b);
		}
		l = 0;
		r = n;
		// cout<<l<<" "<<r<<" "<<x<<" "<<a<<" "<<y<<" "<<b<<" "<<k<<"\n";
		while(l <= r){
			int mid = l + (r-l)/2;
			if(check(mid)){
				ans = mid;
				r = mid -1;
			} else {
				l = mid + 1;
			}
		}

		if(ans == INT_MAX) cout<<"-1\n";
		else cout<<ans<<"\n";

	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int size = 2e5 + 7;
long long int arr[size];

int gcd(int a, int b){
	if(b ==0) return a;
	if(b>a) return gcd(b,a);
	return gcd(b, a%b);
}

int q, n,x,a,y,b;
long long int k;
int t1, t2, t3, l, r, ans;

bool check(int l, int r){
	int mid = l + (r-l)/2;
	long long int total = 0;
	int c = 0;

	t1 = mid/a;
	t2 = mid/b;
	t3 = mid/((a*b)/gcd(a,b));
	t1 -= t3;
	t2 -= t3;

	if(t3 > 0) total += arr[t3-1]*(x+y);
	if(t1 > 0){
		total += arr[t1 + t3 -1]*x;
		if(t3 > 0) total -= arr[t3-1]*x;
	}
	if(t2 > 0){
		total += arr[t3 + t2 + t1 -1]*y;
		if(t3 + t1 > 0) total -= arr[t3 + t1 - 1]*y;
	}
	total/=100;
	return total >= k;
}

int main(){

	cin>>q;
	while(q--){
		ans = INT_MAX;

		cin>>n;

		for(int x=0;x<n;x++) cin>>arr[x];

		sort(arr, arr+n);
		reverse(arr, arr+n);

		// for(int x=0;x<n;x++) cout<<arr[x]<<" ";
		// cout<<"\n";
		cin>>x>>a;
		cin>>y>>b;
		cin>>k;

		for(int i=1;i<n;i++) arr[i] += arr[i-1];

		if(x < y){
			swap(x, y);
			swap(a, b);
		}
		l = 0;
		r = n;
		// cout<<l<<" "<<r<<" "<<x<<" "<<a<<" "<<y<<" "<<b<<" "<<k<<"\n";
		while(l <= r){
			int mid = l + (r-l)/2;
			if(check(l, r)){
				ans = mid;
				r = mid -1;
			} else {
				l = mid + 1;
			}
		}

		if(ans == INT_MAX) cout<<"-1\n";
		else cout<<ans<<"\n";

	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int size = 2e5 + 7;
long long int arr[size];

int gcd(int a, int b){
	if(b ==0) return a;
	if(b>a) return gcd(b,a);
	return gcd(b, a%b);
}

int q, n,x,a,y,b;
long long int k;
int t1, t2, t3, l, r, ans;

bool check(int mid){
	long long int total = 0;
	int c = 0;
	long long int p = a;
	p*=b;
	p/=gcd(a,b);
	t1 = mid/a;
	t2 = mid/b;
	t3 = mid/(int(p));
	t1 -= t3;
	t2 -= t3;

	if(t3 > 0) total += arr[t3-1]*(x+y);
	if(t1 > 0){
		total += arr[t1 + t3 -1]*x;
		if(t3 > 0) total -= arr[t3-1]*x;
	}
	if(t2 > 0){
		total += arr[t3 + t2 + t1 -1]*y;
		if(t3 + t1 > 0) total -= arr[t3 + t1 - 1]*y;
	}
	total/=100;
	return total >= k;
}

int main(){

	cin>>q;
	while(q--){
		ans = INT_MAX;

		cin>>n;

		for(int x=0;x<n;x++) cin>>arr[x];

		sort(arr, arr+n);
		reverse(arr, arr+n);

		// for(int x=0;x<n;x++) cout<<arr[x]<<" ";
		// cout<<"\n";
		cin>>x>>a;
		cin>>y>>b;
		cin>>k;

		for(int i=1;i<n;i++) arr[i] += arr[i-1];

		if(x < y){
			swap(x, y);
			swap(a, b);
		}
		l = 0;
		r = n;
		// cout<<l<<" "<<r<<" "<<x<<" "<<a<<" "<<y<<" "<<b<<" "<<k<<"\n";
		while(l <= r){
			int mid = l + (r-l)/2;
			if(check(mid)){
				ans = mid;
				r = mid -1;
			} else {
				l = mid + 1;
			}
		}

		if(ans == INT_MAX) cout<<"-1\n";
		else cout<<ans<<"\n";

	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(0);
	int t;
	cin>>t;
	int cnt[26],cnt1[26];
	while(t--){
		int n;
		cin>>n;
		int prices[n];
		for(int i=0;i<n;i++)
			cin>>prices[i];
		sort(prices,prices+n);
		// for(int i=0;i<n;i++)cout<<prices[i]<<" ";
		// 	cout<<"\n";
		int curr_pos[n+1];
		for(int i=1;i<=n;i++)curr_pos[i]=-1;
		int x,a,y,b;
		long long int k;
		cin>>x>>a>>y>>b>>k;
		long long int lcm=1LL*(a*b)/__gcd(a,b);
		int c=n-1;
		for(int i=lcm;i<=n;i+=lcm){
			curr_pos[i]=prices[c];
			// cout<<curr_pos[i]<<" lcm "<<i<<endl;
			c--;
		}
		if(1LL*n*b*x>1LL*n*a*y){
			for(int i=a;i<=n;i+=a){
				if(curr_pos[i]==-1)
				{
					curr_pos[i]=prices[c];
					c--;
					// cout<<curr_pos[i]<<" a "<<i<<endl;
				}

			}
			for(int i=b;i<=n;i+=b){
				if(curr_pos[i]==-1)
				{
					curr_pos[i]=prices[c];
					c--;
					// cout<<curr_pos[i]<<" b "<<i<<endl;
				}
			}
		}
		else {
			for(int i=b;i<=n;i+=b){
				if(curr_pos[i]==-1)
				{
					curr_pos[i]=prices[c];
					c--;
					// cout<<curr_pos[i]<<" b "<<i<<endl;
				}
			}
			for(int i=a;i<=n;i+=a){
				if(curr_pos[i]==-1)
				{
					curr_pos[i]=prices[c];
					c--;
					// cout<<curr_pos[i]<<" b "<<i<<endl;
				}
			}
		}
		for(int i=1;i<=n;i++){
			if(curr_pos[i]==-1){
				curr_pos[i]=prices[c];
				c--;
							// cout<<curr_pos[i]<<" rest "<<i<<endl;
			}
		}
		// cout<<c<<endl;
		// for(int i=1;i<=n;i++)cout<<curr_pos[i]<<" ";
		// 	cout<<"\n";
		long long int sum=0;
		int ans=0;
		int f=0;
		for(int i=1;i<=n;i++){
			if(sum<k)ans++;
			else if(sum>=k) {
				f=1;
				break;
			}
			if(i%(lcm)==0){
				sum+=(long long int)(curr_pos[i]/100)*(long long int)((x+y));
			}
			else if(i%(b)==0){
				sum+=(long long int)(curr_pos[i]/100)*(long long int)((y));
			}
			else if(i%(a)==0){
				sum+=(long long int)(curr_pos[i]/100)*(long long int)((x));			}
		}
		if(sum>=k)f=1;
		if(f==0)ans=-1;
		cout<<ans<<"\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(0);
	int t;
	cin>>t;
	int cnt[26],cnt1[26];
	while(t--){
		int n;
		cin>>n;
		int prices[n];
		for(int i=0;i<n;i++)
			cin>>prices[i];
		sort(prices,prices+n);
		long long int prefix_sum[n+1];
		prefix_sum[1]=1LL*prices[0];
		for(int i=2;i<=n;i++)prefix_sum[i]=prefix_sum[i-1]+1LL*prices[i-1];
		// for(int i=0;i<n;i++)cout<<prices[i]<<" ";
		// 	cout<<"\n";
		int curr_pos[n+1];
		for(int i=1;i<=n;i++)curr_pos[i]=-1;
		int x,a,y,b;
		long long int k;
		cin>>x>>a>>y>>b>>k;
		long long int lcm=1LL*(a*b)/__gcd(a,b);
		int c=n-1;
		for(int i=lcm;i<=n;i+=lcm){
			curr_pos[i]=prices[c];
			// cout<<curr_pos[i]<<" lcm "<<i<<endl;
			c--;
		}
		long long int val=prefix_sum[c+1]-prefix_sum[c-(n/a)];
		val/=100;
		val*=x;
		long long int val1=prefix_sum[c+1]-prefix_sum[c-(n/b)];
		val/=100;
		val*=y;
		if(val>val1){
			for(int i=a;i<=n;i+=a){
				if(curr_pos[i]==-1)
				{
					curr_pos[i]=prices[c];
					c--;
					// cout<<curr_pos[i]<<" a "<<i<<endl;
				}

			}
			for(int i=b;i<=n;i+=b){
				if(curr_pos[i]==-1)
				{
					curr_pos[i]=prices[c];
					c--;
					// cout<<curr_pos[i]<<" b "<<i<<endl;
				}
			}
		}
		else {
			for(int i=b;i<=n;i+=b){
				if(curr_pos[i]==-1)
				{
					curr_pos[i]=prices[c];
					c--;
					// cout<<curr_pos[i]<<" b "<<i<<endl;
				}
			}
			for(int i=a;i<=n;i+=a){
				if(curr_pos[i]==-1)
				{
					curr_pos[i]=prices[c];
					c--;
					// cout<<curr_pos[i]<<" b "<<i<<endl;
				}
			}
		}
		for(int i=1;i<=n;i++){
			if(curr_pos[i]==-1){
				curr_pos[i]=prices[c];
				c--;
							// cout<<curr_pos[i]<<" rest "<<i<<endl;
			}
		}
		// cout<<c<<endl;
		// for(int i=1;i<=n;i++)cout<<curr_pos[i]<<" ";
		// 	cout<<"\n";
		long long int sum=0;
		int ans=0;
		int f=0;
		for(int i=1;i<=n;i++){
			if(sum<k)ans++;
			else if(sum>=k) {
				f=1;
				break;
			}
			if(i%(lcm)==0){
				sum+=(long long int)(curr_pos[i]/100)*(long long int)((x+y));
			}
			else if(i%(b)==0){
				sum+=(long long int)(curr_pos[i]/100)*(long long int)((y));
			}
			else if(i%(a)==0){
				sum+=(long long int)(curr_pos[i]/100)*(long long int)((x));			}
		}
		if(sum>=k)f=1;
		if(f==0)ans=-1;
		cout<<ans<<"\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ios_base::sync_with_stdio(0);
	int t;
	cin>>t;
	while(t--){
		ll n;
		cin>>n;
		ll prices[n+1];
		for(ll i=0;i<n;i++){
			cin>>prices[i];
			prices[i]/=100;
		}
		sort(prices,prices+n,greater<int>());
		ll x,a,y,b;
		ll k;
		cin>>x>>a>>y>>b>>k;
		if(x<y){
			swap(x,y);
			swap(a,b);
		}
		ll lcm=a*b/__gcd(a,b);
		ll sum=0,u1=0,u2=0,u3=0;
		ll lo=0,hi=n+1;
		while(hi-lo>1)
		{
			ll len=(lo+hi)/2;
			sum=0,u1=0,u2=0,u3=0;

			for(ll i=1;i<=len;i++){
				if(i%a==0&&i%b==0)u1++;
				else if(i%a==0)u2++;
				else if(i%b==0)u3++;
			}

			for(ll i=0;i<u1;i++){
				sum+=prices[i]*(x+y);
			}
			for(ll i=0;i<u2;i++){
				sum+=prices[i+u1]*x;
			}
			for(ll i=0;i<u3;i++){
				sum+=prices[i+ u1+ u2]*y;
			}
			//cout<<"Sum: "<< sum<<" Hi: "<< hi<<endl;
			if(sum>=k)
				hi=len;
			else
				lo=len;

		}
		if(hi>n)hi=-1;
		cout<<hi<<"\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(0);
	int t;
	cin>>t;
	int cnt[26],cnt1[26];
	while(t--){
		int n;
		cin>>n;
		int prices[n+1];
		for(int i=1;i<=n;i++)
			cin>>prices[i];
		sort(prices+1,prices+n+1,greater<int>());
		int x,a,y,b;
		long long int k;
		cin>>x>>a>>y>>b>>k;
		if(x<y){
			swap(x,y);
			swap(a,b);
		}
		long long int lcm=1LL*a*b/__gcd(a,b);
		long long int sum=0;
		int ans=-1;
		int lo=0,hi=n+1;
		while(hi-lo>1)
		{
			int len=(lo+hi)/2;
			sum=0;
			for(int i=1;i<=len/lcm;i++){
				sum+=(long long int)(prices[i]/100)*(long long int)((x+y));
			}
			for(int i=1;i<=len/a;i++){
				sum+=(long long int)(prices[i+len/lcm]/100)*(long long int)((x));
			}
			for(int i=1;i<=len/b;i++){
				sum+=(long long int)(prices[i+ len/lcm + len/a]/100)*(long long int)((y));
			}
			//cout<<"Sum: "<< sum<<" Hi: "<< hi<<endl;
			if(sum>=k)
				hi=len;
			else
				lo=len;

		}
		if(hi>n)hi=-1;
		cout<<hi<<"\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(0);
	int t;
	cin>>t;
	int cnt[26],cnt1[26];
	while(t--){
		int n;
		cin>>n;
		int prices[n];
		for(int i=0;i<n;i++)
			cin>>prices[i];
		sort(prices,prices+n);
		long long int prefix_sum[n+1];
		prefix_sum[1]=1LL*prices[0];
		for(int i=2;i<=n;i++)prefix_sum[i]=prefix_sum[i-1]+1LL*prices[i-1];
		// for(int i=0;i<n;i++)cout<<prices[i]<<" ";
		// 	cout<<"\n";
		int curr_pos[n+1];
		for(int i=1;i<=n;i++)curr_pos[i]=-1;
		int x,a,y,b;
		long long int k;
		cin>>x>>a>>y>>b>>k;
		long long int lcm=1LL*(a*b)/__gcd(a,b);
		int c=n-1;
		for(int i=lcm;i<=n;i+=lcm){
			curr_pos[i]=prices[c];
			// cout<<curr_pos[i]<<" lcm "<<i<<endl;
			c--;
		}
		long long int val=prefix_sum[c+1]-prefix_sum[c+1-(n/a)];
		val/=100;
		val*=x;
		long long int val1=prefix_sum[c+1]-prefix_sum[c+1-(n/b)];
		val/=100;
		val*=y;
		if(val>val1){
			for(int i=a;i<=n;i+=a){
				if(curr_pos[i]==-1)
				{
					curr_pos[i]=prices[c];
					c--;
					// cout<<curr_pos[i]<<" a "<<i<<endl;
				}

			}
			for(int i=b;i<=n;i+=b){
				if(curr_pos[i]==-1)
				{
					curr_pos[i]=prices[c];
					c--;
					// cout<<curr_pos[i]<<" b "<<i<<endl;
				}
			}
		}
		else {
			for(int i=b;i<=n;i+=b){
				if(curr_pos[i]==-1)
				{
					curr_pos[i]=prices[c];
					c--;
					// cout<<curr_pos[i]<<" b "<<i<<endl;
				}
			}
			for(int i=a;i<=n;i+=a){
				if(curr_pos[i]==-1)
				{
					curr_pos[i]=prices[c];
					c--;
					// cout<<curr_pos[i]<<" b "<<i<<endl;
				}
			}
		}
		for(int i=1;i<=n;i++){
			if(curr_pos[i]==-1){
				curr_pos[i]=prices[c];
				c--;
							// cout<<curr_pos[i]<<" rest "<<i<<endl;
			}
		}
		// cout<<c<<endl;
		// for(int i=1;i<=n;i++)cout<<curr_pos[i]<<" ";
		// 	cout<<"\n";
		long long int sum=0;
		int ans=0;
		int f=0;
		for(int i=1;i<=n;i++){
			if(sum<k)ans++;
			else if(sum>=k) {
				f=1;
				break;
			}
			if(i%(lcm)==0){
				sum+=(long long int)(curr_pos[i]/100)*(long long int)((x+y));
			}
			else if(i%(b)==0){
				sum+=(long long int)(curr_pos[i]/100)*(long long int)((y));
			}
			else if(i%(a)==0){
				sum+=(long long int)(curr_pos[i]/100)*(long long int)((x));			}
		}
		if(sum>=k)f=1;
		if(f==0)ans=-1;
		cout<<ans<<"\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    long long int t;
    cin>>t;
    while(t--){
        long long int n;
        cin>>n;
        long long int p[n+1],temp[n+1],start=1,end=n,sum=0,ans[n+1],w=0;
        for(int i=1;i<=n;i++){
            cin>>p[i];
        }
        long long int x,a,y,b,k;
        cin>>x>>a>>y>>b>>k;
        sort(p+1,p+n+1);
        if(y<x){
            swap(x,y);
            swap(a,b);
        }
        int j=n;
        sum=0;
        for(int i=1;i<=end;i++){
            if(i%b==0){
                temp[i]=p[j];
                j--;
                sum=sum+(y*temp[i])/100;
            }
            if(i%a==0&&i%b==0){
                sum=sum+(x*temp[i])/100;
            }
        }
        for(int i=1;i<=end;i++){
            if(i%a==0&&i%b!=0){
                temp[i]=p[j];
                sum=sum+(x*temp[i])/100;
                j--;
            }
        }
        if(sum>=k){
            ans[w++]=end;
        }
        j=n;
        while(start<end){
            int mid=(start+end)/2;
            sum=0;
            for(int i=1;i<=mid;i++){
                if(i%b==0){
                    temp[i]=p[j];
                    j--;
                    sum=sum+(y*temp[i])/100;
                }
                if(i%a==0&&i%b==0){
                    sum=sum+(x*temp[i])/100;
                }
            }
            for(int i=1;i<=mid;i++){
                if(i%a==0&&i%b!=0){
                    temp[i]=p[j];
                    sum=sum+(x*temp[i])/100;
                    j--;
                }
            }
            if(sum==k){
                j=n;
                start=mid;
                end=mid;
                break;
            }
            if(sum>k){
                ans[w++]=mid;
                j=n;
                end=mid-1;
            }
            else{
                j=n;
                start=mid+1;
            }

        }
        if(w>0){
            cout<<ans[w-1]<<"\n";
        }
        else{
            cout<<"-1"<<"\n";
        }
    }

}


#include<bits/stdc++.h>
using namespace std;
int main(){
    long long int t;
    cin>>t;
    while(t--){
        long long int n;
        cin>>n;
        long long int p[n+1],temp[n+1],start=1,end=n,sum=0,ans[n+1],w=0;
        for(int i=1;i<=n;i++){
            cin>>p[i];
        }
        long long int x,a,y,b,k;
        cin>>x>>a>>y>>b>>k;
        sort(p+1,p+n+1);
        if(y<x){
            swap(x,y);
            swap(a,b);
        }
        int j=n;
        sum=0;
        for(int i=1;i<=end;i++){
            if(i%b==0){
                temp[i]=p[j];
                j--;
                sum=sum+(y*temp[i])/100;
            }
            if(i%a==0&&i%b==0){
                sum=sum+(x*temp[i])/100;
            }
        }
        for(int i=1;i<=end;i++){
            if(i%a==0&&i%b!=0){
                temp[i]=p[j];
                sum=sum+(x*temp[i])/100;
                j--;
            }
        }
        if(sum>=k){
            ans[w++]=end;
        }
        j=n;
        while(start<=end){
            int mid=(start+end)/2;
            sum=0;
            for(int i=1;i<=mid;i++){
                if(i%a==0&&i%b==0){
                    temp[i]=p[j];
                    j--;
                    sum=sum+((x+y)*temp[i])/100;
                }
            }
            for(int i=1;i<=mid;i++){
                if(i%b==0&&i%a!=0){
                    temp[i]=p[j];
                    sum=sum+(y*temp[i])/100;
                    j--;
                }
            }
            for(int i=1;i<=mid;i++){
                if(i%a==0&&i%b!=0){
                    temp[i]=p[j];
                    sum=sum+(x*temp[i])/100;
                    j--;
                }
            }
            //cout<<sum<<" "<<mid<<"\n";
            if(sum==k){
                j=n;
                ans[w++]=mid;
                end=mid-1;
            }
            else if(sum>k){
                ans[w++]=mid;
                j=n;
                end=mid-1;
            }
            else{
                j=n;
                start=mid+1;
            }

        }
        if(w>0){
            cout<<ans[w-1]<<"\n";
        }
        else{
            cout<<"-1"<<"\n";
        }
    }

}


#include<bits/stdc++.h>
using namespace std;
int main(){
    long long int t;
    cin>>t;
    while(t--){
        long long int n;
        cin>>n;
        long long int p[n+1],temp[n+1],start=1,end=n,sum=0,ans[n+1],w=0;
        for(int i=1;i<=n;i++){
            cin>>p[i];
        }
        long long int x,a,y,b,k;
        cin>>x>>a>>y>>b>>k;
        sort(p+1,p+n+1);
        if(y<x){
            swap(x,y);
            swap(a,b);
        }
        int j=n;
        sum=0;
        for(int i=1;i<=end;i++){
            if(i%b==0){
                temp[i]=p[j];
                j--;
                sum=sum+(y*temp[i])/100;
            }
            if(i%a==0&&i%b==0){
                sum=sum+(x*temp[i])/100;
            }
        }
        for(int i=1;i<=end;i++){
            if(i%a==0&&i%b!=0){
                temp[i]=p[j];
                sum=sum+(x*temp[i])/100;
                j--;
            }
        }
        if(sum>=k){
            ans[w++]=end;
        }
        j=n;
        while(start<end){
            int mid=(start+end)/2;
            sum=0;
            for(int i=1;i<=mid;i++){
                if(i%b==0){
                    temp[i]=p[j];
                    j--;
                    sum=sum+(y*temp[i])/100;
                }
                if(i%a==0&&i%b==0){
                    sum=sum+(x*temp[i])/100;
                }
            }
            for(int i=1;i<=mid;i++){
                if(i%a==0&&i%b!=0){
                    temp[i]=p[j];
                    sum=sum+(x*temp[i])/100;
                    j--;
                }
            }
            if(sum==k){
                j=n;
                ans[w++]=mid;
                end=mid-1;
            }
            else if(sum>k){
                ans[w++]=mid;
                j=n;
                end=mid-1;
            }
            else{
                j=n;
                start=mid+1;
            }

        }
        if(w>0){
            cout<<ans[w-1]<<"\n";
        }
        else{
            cout<<"-1"<<"\n";
        }
    }

}


#include<bits/stdc++.h>
using namespace std;
int main(){
    long long int t;
    cin>>t;
    while(t--){
        long long int n;
        cin>>n;
        long long int p[n+1],temp[n+1],start=1,end=n,sum=0,ans[n+1],w=0;
        for(int i=1;i<=n;i++){
            cin>>p[i];
        }
        long long int x,a,y,b,k;
        cin>>x>>a>>y>>b>>k;
        sort(p+1,p+n+1);
        if(y<x){
            swap(x,y);
            swap(a,b);
        }
        int j=n;
        sum=0;
        for(int i=1;i<=end;i++){
            if(i%b==0){
                temp[i]=p[j];
                j--;
                sum=sum+(y*temp[i])/100;
            }
            if(i%a==0&&i%b==0){
                sum=sum+(x*temp[i])/100;
            }
        }
        for(int i=1;i<=end;i++){
            if(i%a==0&&i%b!=0){
                temp[i]=p[j];
                sum=sum+(x*temp[i])/100;
                j--;
            }
        }
        if(sum>=k){
            ans[w++]=end;
        }
        j=n;
        while(start<=end){
            int mid=(start+end)/2;
            sum=0;
            for(int i=1;i<=mid;i++){
                if(i%b==0){
                    temp[i]=p[j];
                    j--;
                    sum=sum+(y*temp[i])/100;
                }
                if(i%a==0&&i%b==0){
                    sum=sum+(x*temp[i])/100;
                }
            }
            for(int i=1;i<=mid;i++){
                if(i%a==0&&i%b!=0){
                    temp[i]=p[j];
                    sum=sum+(x*temp[i])/100;
                    j--;
                }
            }
            //cout<<sum<<" "<<mid<<"\n";
            if(sum==k){
                j=n;
                ans[w++]=mid;
                end=mid-1;
            }
            else if(sum>k){
                ans[w++]=mid;
                j=n;
                end=mid-1;
            }
            else{
                j=n;
                start=mid+1;
            }

        }
        if(w>0){
            cout<<ans[w-1]<<"\n";
        }
        else{
            cout<<"-1"<<"\n";
        }
    }

}


#define MOD 1000000007
#define PI 3.14159265358979323846
#define inf 100000000000000
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define sz(V) (int)V.size()
//#define int long long
#define _ <<" "<<
#define forn(i, n)             for(int i = 0; i < n; i ++)

#define forn1(i, n)            for(int i = 1; i <= n; i ++)

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;
#define int long long
vector<int > p;
vector<pair<int ,int >> v;

int fn(int n , int a, int b ,int x ,int y )
{
    //int lcm = (a * b) / __gcd(a,b);

    vector<int > tmp;
    forn(i , v.size())
    {
        if(v[i].fi > n)break;

        tmp.pb(v[i].se);
    }

    sort(ALL(tmp));
    reverse(ALL(tmp));

    int ans = 0;
    forn(i,tmp.size())
    {
        ans += (tmp[i] * p[i] ) / 100;
    }

    return ans ;

}

signed main() {

    ios::sync_with_stdio(0); cin.tie(0);
    cout.tie(0);
    //freopen("test.txt" ,"r", stdin);
    int t;cin>>t;
    while(t--)
    {
        int n;cin>>n;
        // int p[n];
        forn(i,n){
            int plo;
            cin>>plo;
            p.pb(plo);//in>>p[i];
        }
        int x,a;
        cin>>x>>a;
        int y,b;
        cin>>y>>b;
        int k;cin>>k;

        int lcm = (a * b) / __gcd(a,b);

        //cout<<lcm<<endl;

       sort(ALL(p));
       reverse(ALL(p));

        forn1(i,n)
        {
            if(i % a == 0 && i % b == 0)v.pb({i,x+y});
            else if(i % a == 0)v.pb({i,x});
            else if(i % b == 0)v.pb({i,y});
        }

        int l = 1;
        int r = n;

        int c = 0;
        while(l < r )
        {
            int mid = (l+r)/2;
            int foo = fn(mid ,a,b,x,y);
            //cout<<foo<<endl;
            if(foo >= k)
            {
                r = mid;
            }
            else
            {
                l = mid + 1;
            }
            c++;
        }

        if(fn( l , a, b ,x ,y ) < k)
        {
            cout<<-1<<endl;
        }
        else cout<<l<<endl;
        v.clear();
            p.clear();

    }
}


#define MOD 1000000007
#define PI 3.14159265358979323846
#define inf 100000000000000
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define sz(V) (int)V.size()
//#define int long long
#define _ <<" "<<
#define forn(i, n)             for(int i = 0; i < n; i ++)
#define forn1(i, n)            for(int i = 1; i <= n; i ++)
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;
#define int long long
vector<int > p;
vector<pair<int ,int >> v;

int fn(int n , int a, int b ,int x ,int y )
{
    //int lcm = (a * b) / __gcd(a,b);

    vector<int> tmp;
    forn(i , v.size())
    {
        if(v[i].fi > n)break;

        tmp.pb(v[i].se);
    }

    sort(ALL(tmp));
    reverse(ALL(tmp));
    // cout<<n<<"ASD"<<endl;
    // forn(i,tmp.size())cout<<tmp[i]<<" ";
    // cout<<endl;

    int ans = 0;
    forn(i,tmp.size())
    {
        ans += (tmp[i] * p[i] ) / 100;
    }

    return ans ;

}

signed main() {

    ios::sync_with_stdio(0); cin.tie(0);
    cout.tie(0);
   // freopen("test.txt" ,"r", stdin);
    int t;cin>>t;
    while(t--)
    {
        int n;cin>>n;
        // int p[n];
        forn(i,n){
            int plo;
            cin>>plo;
            p.pb(plo);//in>>p[i];
        }
        int x,a;
        cin>>x>>a;
        int y,b;
        cin>>y>>b;
        int k;cin>>k;

        int lcm = (a * b) / __gcd(a,b);

        //cout<<lcm<<endl;

       sort(ALL(p));
       reverse(ALL(p));

        forn1(i,n)
        {
            if(i % a == 0 && i % b == 0)v.pb({i,x+y});
            else if(i % a == 0)v.pb({i,x});
            else if(i % b == 0)v.pb({i,y});
        }

        // cout<<v.size()<<endl;
        // forn(i,v.size())cout<<v[i].fi<<" ";
        // cout<<endl;
        int l = 1;
        int r = n;

        int c = 0;
        while(l < r )
        {
            int mid = (l+r)/2;
            int foo = fn(mid ,a,b,x,y);
            //cout<<foo<<endl;
            if(foo >= k)
            {
                r = mid;
            }
            else
            {
                l = mid + 1;
            }
            c++;
        }

        if(fn( l , a, b ,x ,y ) < k)
        {
            cout<<-1<<endl;
        }

        //cout<<fn(n,a,b,x,y)<<endl;
        // if( < k){
        //     cout<<-1<<endl;
        //     v.clear();
        //     p.clear();
        //     continue;
        // }
        else cout<<l<<endl;
        v.clear();
            p.clear();

    }
}


#define MOD 1000000007
#define PI 3.14159265358979323846
#define inf 100000000000000
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define sz(V) (int)V.size()
//#define int long long
#define _ <<" "<<
#define forn(i, n)             for(int i = 0; i < n; i ++)
#define forn1(i, n)            for(int i = 1; i <= n; i ++)
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;
#define int long long
vector<int > p;
vector<pair<int ,int >> v;

int fn(int n , int a, int b ,int x ,int y )
{
    //int lcm = (a * b) / __gcd(a,b);

    vector<int > tmp;
    forn(i , v.size())
    {
        if(v[i].fi > n)break;

        tmp.pb(v[i].se);
    }

    sort(ALL(tmp));
    reverse(ALL(tmp));

    int ans = 0;
    forn(i,tmp.size())
    {
        ans += (tmp[i] * p[i] ) / 100;
    }

    return ans ;

}

signed main() {

    ios::sync_with_stdio(0); cin.tie(0);
    cout.tie(0);
    //freopen("test.txt" ,"r", stdin);
    int t;cin>>t;
    while(t--)
    {
        int n;cin>>n;
        // int p[n];
        forn(i,n){
            int plo;
            cin>>plo;
            p.pb(plo);//in>>p[i];
        }
        int x,a;
        cin>>x>>a;
        int y,b;
        cin>>y>>b;
        int k;cin>>k;

        int lcm = (a * b) / __gcd(a,b);

        //cout<<lcm<<endl;

       sort(ALL(p));
       reverse(ALL(p));

        forn1(i,n)
        {
            if(i % a == 0 && i % b == 0)v.pb({i,x+y});
            else if(i % a == 0)v.pb({i,x});
            else if(i % b == 0)v.pb({i,y});
        }

        // cout<<v.size()<<endl;
        // forn(i,v.size())cout<<v[i].fi<<" ";
        // cout<<endl;
        int l = 1;
        int r = n;

        int c = 0;
        while(l < r )
        {
            int mid = (l+r)/2;
            int foo = fn(mid ,a,b,x,y);
            //cout<<foo<<endl;
            if(foo >= k)
            {
                r = mid;
            }
            else
            {
                l = mid + 1;
            }
            c++;
        }

        if(fn( l , a, b ,x ,y ) < k)
        {
            cout<<-1<<endl;
        }
        else cout<<l<<endl;
        v.clear();
            p.clear();

    }
}


#define MOD 1000000007
#define PI 3.14159265358979323846
#define inf 100000000000000
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define sz(V) (int)V.size()
//#define int long long
#define _ <<" "<<
#define forn(i, n)             for(int i = 0; i < n; i ++)

#define forn1(i, n)            for(int i = 1; i <= n; i ++)

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;
#define int long long
vector<int > p;
vector<pair<int ,int >> v;

int fn(int n , int a, int b ,int x ,int y )
{
    //int lcm = (a * b) / __gcd(a,b);

    vector<int > tmp;
    forn(i , v.size())
    {
        if(v[i].fi > n)break;

        tmp.pb(v[i].se);
    }

    sort(ALL(tmp));
    reverse(ALL(tmp));
    // cout<<n<<"ASD"<<endl;
    // forn(i,tmp.size())cout<<tmp[i]<<" ";
    // cout<<endl;

    int ans = 0;
    forn(i,tmp.size())
    {
        ans += (tmp[i] * p[i] ) / 100;
    }

    return ans ;

}

signed main() {

    ios::sync_with_stdio(0); cin.tie(0);
    cout.tie(0);
    //freopen("test.txt" ,"r", stdin);
    int t;cin>>t;
    while(t--)
    {
        int n;cin>>n;
        // int p[n];
        forn(i,n){
            int plo;
            cin>>plo;
            p.pb(plo);//in>>p[i];
        }
        int x,a;
        cin>>x>>a;
        int y,b;
        cin>>y>>b;
        int k;cin>>k;

        int lcm = (a * b) / __gcd(a,b);

        //cout<<lcm<<endl;

       sort(ALL(p));
       reverse(ALL(p));

        forn1(i,n)
        {
            if(i % a == 0 && i % b == 0)v.pb({i,x+y});
            else if(i % a == 0)v.pb({i,x});
            else if(i % b == 0)v.pb({i,y});
        }

        // cout<<v.size()<<endl;
        // forn(i,v.size())cout<<v[i].fi<<" ";
        // cout<<endl;
        int l = 1;
        int r = n;

        int c = 0;
        while(l < r )
        {
            int mid = (l+r)/2;
            int foo = fn(mid ,a,b,x,y);
            //cout<<foo<<endl;
            if(foo >= k)
            {
                r = mid;
            }
            else
            {
                l = mid + 1;
            }
            c++;
        }

        if(fn( l , a, b ,x ,y ) < k)
        {
            cout<<-1<<endl;
        }
        else cout<<l<<endl;
        v.clear();
            p.clear();

    }
}


#define MOD 1000000007
#define PI 3.14159265358979323846
#define inf 100000000000000
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define sz(V) (int)V.size()
//#define int long long
#define _ <<" "<<
#define forn(i, n)             for(int i = 0; i < n; i ++)
#define forn1(i, n)            for(int i = 1; i <= n; i ++)
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;
#define int long long
vector<int > p;
vector<pair<int ,int >> v;

int fn(int n , int a, int b ,int x ,int y )
{
    //int lcm = (a * b) / __gcd(a,b);

    vector<int > tmp;
    forn(i , v.size())
    {
        if(v[i].fi > n)break;

        tmp.pb(v[i].se);
    }

    sort(ALL(tmp));
    reverse(ALL(tmp));
    // cout<<n<<"ASD"<<endl;
    // forn(i,tmp.size())cout<<tmp[i]<<" ";
    // cout<<endl;

    int ans = 0;
    forn(i,tmp.size())
    {
        ans += (tmp[i] * p[i] ) / 100;
    }

    return ans ;

}

signed main() {

    ios::sync_with_stdio(0); cin.tie(0);
    cout.tie(0);
    //freopen("test.txt" ,"r", stdin);
    int t;cin>>t;
    while(t--)
    {
        int n;cin>>n;
        // int p[n];
        forn(i,n){
            int plo;
            cin>>plo;
            p.pb(plo);//in>>p[i];
        }
        int x,a;
        cin>>x>>a;
        int y,b;
        cin>>y>>b;
        int k;cin>>k;

        int lcm = (a * b) / __gcd(a,b);

        //cout<<lcm<<endl;

       sort(ALL(p));
       reverse(ALL(p));

        forn1(i,n)
        {
            if(i % a == 0 && i % b == 0)v.pb({i,x+y});
            else if(i % a == 0)v.pb({i,x});
            else if(i % b == 0)v.pb({i,y});
        }

        // cout<<v.size()<<endl;
        // forn(i,v.size())cout<<v[i].fi<<" ";
        // cout<<endl;
        int l = 1;
        int r = n;

        int c = 0;
        while(l < r )
        {
            int mid = (l+r)/2;
            int foo = fn(mid ,a,b,x,y);
            //cout<<foo<<endl;
            if(foo >= k)
            {
                r = mid;
            }
            else
            {
                l = mid + 1;
            }
            c++;
        }

        if(fn( l , a, b ,x ,y ) < k)
        {
            cout<<-1<<endl;
        }
        else cout<<l<<endl;
        v.clear();
            p.clear();

    }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

int main()
{
	LL q;
	cin >> q;

	while (q--)
	{
		LL n;
		cin >> n;

		vector<LL> t(n);

		for (auto &e : t) {
			cin >> e;
		}

		LL x, a, y, b;
		cin >> x >> a >> y >> b;

		LL k;
		cin >> k;

		sort(t.begin(), t.end(), greater<LL>());

		vector<LL> pre(n);
		pre[n-1] = t[n-1];
		for (int j = n-2; j >= 0; --j) {
			pre[j] = t[j] + pre[j+1];
		}
		pre.push_back(0);

		LL lcm = a*b/__gcd(a, b);
		LL amt = 0;
		LL min_days = 0;

		k*= 100;

		bool poss = false, cksmall = false;

		//cout << cnt_a << "~~" << cnt_b << "\n";

		for (LL i = 0; i < n; i += 1) {
			LL cA = lcm/a-1, cB = lcm/b-1, cAB = 1;
			cA *= (i+1)/lcm;
			cB *= (i+1)/lcm;
			cAB *= (i+1)/lcm;

			cA += ((i+1)%lcm)/a;
			cB += ((i+1)%lcm)/b;
			//cout << i << " " << cA << ", " << cB << ", " << cAB << "\n";

			amt = (pre[0]-pre[cAB])*(x+y);

			//cout << "amti " << amt << "\n";

			LL v1 = x*(pre[cAB]-pre[cAB+cA]) + y*(pre[cAB+cA]-pre[cAB+cA+cB]);
			LL v2 = y*(pre[cAB]-pre[cAB+cB]) + x*(pre[cAB+cB]-pre[cAB+cA+cB]);

			amt += max(v1, v2);

			//cout << i << " " << v1 << ". " << v2 << "??\n";

			if (amt >= k) {
				min_days = i+1;
				poss = true;
				break;
			}

		}

		if (poss) {
			cout << min_days << endl;
		}
		else {
			cout << -1 << endl;
		}

	}

}


#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

int main()
{
	LL q;
	cin >> q;

	while (q--)
	{
		LL n;
		cin >> n;

		vector<LL> t(n);

		for (auto &e : t) {
			cin >> e;
		}

		LL x, a, y, b;
		cin >> x >> a >> y >> b;

		LL k;
		cin >> k;

		sort(t.begin(), t.end(), greater<LL>());

		vector<LL> pre(n);
		pre[n-1] = t[n-1];
		for (int j = n-2; j >= 0; --j) {
			pre[j] = t[j] + pre[j+1];
		}
		pre.push_back(0);

		LL lcm = a*b/__gcd(a, b);
		LL cnt_a = lcm/a - 1;
		LL cnt_b = lcm/b - 1;
		LL pre_point = 0;
		LL amt = 0;
		LL min_days = 0;

		bool poss = false, cksmall = false;

		//cout << cnt_a << "~~" << cnt_b << "\n";

		for (LL i = 0; i < n && !poss; i += lcm) {
			if (i + lcm <= n) {
				LL v1 = x*(pre[i/lcm+1]-pre[i/lcm+1+(i/lcm+1)*cnt_a]) + y*(pre[i/lcm+1+(i/lcm+1)*cnt_a] - pre[i/lcm + 1+(i/lcm+1)*(cnt_a + cnt_b)]);
				v1 /= 100;
				LL v2 = y*(pre[i/lcm+1]-pre[(i/lcm+1)*cnt_b+i/lcm+1]) + x*(pre[(i/lcm+1)*cnt_b+i/lcm+1] - pre[(i/lcm+1)*(cnt_a + cnt_b)+i/lcm+1]);
				v2 /= 100;
				LL v = max(v1, v2);
				v += (pre[0]-pre[i/lcm+1])*(x+y)/100;
				//cout << v << "?\n";

				if (amt+v == k) {
					poss = true;
					min_days += lcm;
					break;
				}
				else if (amt+v < k) {
					min_days += lcm;

				}
				else {
					cksmall = true;
					goto again;
				}
			}
			else {
				again:
				for (LL j = i; j < i+lcm-1; ++j) {
					cnt_a = (j-i+1)/a;
					cnt_b = (j-i+1)/b;
					LL v1 = x*(pre[pre_point]-pre[pre_point+cnt_a]) + y*(pre[pre_point+cnt_a] - pre[pre_point+cnt_a + cnt_b]);
					v1 /= 100;
					LL v2 = y*(pre[pre_point]-pre[pre_point+cnt_b]) + x*(pre[pre_point+cnt_b] - pre[pre_point+cnt_a + cnt_b]);
					v2 /= 100;
					LL v = max(v1, v2);

					//cout << i << " how " << j << "  " << v << "#\n";

					if (v+amt >= k) {
						min_days += j-i+1;
						poss = true;
						break;
					}
				}
				if (cksmall == true && poss == false) {
					min_days += lcm;
					poss = true;
					break;
				}
			}

			//cout << i << " - " <<  v1 << " " << v2 << "~\n";

		}
		if (poss) {
			cout << min_days << endl;
		}
		else {
			cout << -1 << endl;
		}

	}

}


#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

int main()
{
	LL q;
	cin >> q;

	while (q--)
	{
		LL n;
		cin >> n;

		vector<LL> t(n);

		for (auto &e : t) {
			cin >> e;
		}

		LL x, a, y, b;
		cin >> x >> a >> y >> b;

		LL k;
		cin >> k;

		sort(t.begin(), t.end(), greater<LL>());

		vector<LL> pre(n);
		pre[n-1] = t[n-1];
		for (int j = n-2; j >= 0; --j) {
			pre[j] = t[j] + pre[j+1];
		}
		pre.push_back(0);

		LL lcm = a*b/__gcd(a, b);
		LL cnt_a = lcm/a - 1;
		LL cnt_b = lcm/b - 1;
		LL pre_point = 0;
		LL amt = 0;
		LL min_days = 0;

		bool poss = false, cksmall = false;

		//cout << cnt_a << "~~" << cnt_b << "\n";

		for (LL i = 0; i < n && !poss; i += lcm) {
			if (i + lcm <= n) {
				LL v1 = x*(pre[i/lcm+1]-pre[i/lcm+1+(i/lcm+1)*cnt_a]) + y*(pre[i/lcm+1+(i/lcm+1)*cnt_a] - pre[i/lcm + 1+(i/lcm+1)*(cnt_a + cnt_b)]);
				v1 /= 100;
				LL v2 = y*(pre[i/lcm+1]-pre[(i/lcm+1)*cnt_b+i/lcm+1]) + x*(pre[(i/lcm+1)*cnt_b+i/lcm+1] - pre[(i/lcm+1)*(cnt_a + cnt_b)+i/lcm+1]);
				v2 /= 100;
				LL v = max(v1, v2);
				v += (pre[0]-pre[i/lcm+1])*(x+y)/100;
				//cout << v << "?\n";
				if (v == k) {
					poss = true;
					min_days += lcm;
					break;
				}
				else if (v < k) {
					min_days += lcm;
					amt = v;
					pre_point += cnt_a + cnt_b+1;
				}
				else {
					cksmall = true;
					goto again;
				}
			}
			else {
				again:
				for (LL j = i; j < i+lcm-1; ++j) {
					cnt_a = (j-i+1)/a;
					cnt_b = (j-i+1)/b;
					LL v1 = x*(pre[pre_point]-pre[pre_point+cnt_a]) + y*(pre[pre_point+cnt_a] - pre[pre_point+cnt_a + cnt_b]);
					v1 /= 100;
					LL v2 = y*(pre[pre_point]-pre[pre_point+cnt_b]) + x*(pre[pre_point+cnt_b] - pre[pre_point+cnt_a + cnt_b]);
					v2 /= 100;
					LL v = max(v1, v2);

					//cout << i << " how " << j << "  " << v << "#\n";

					if (v+amt >= k) {
						min_days += j-i+1;
						poss = true;
						break;
					}
				}
				if (cksmall == true && poss == false) {
					min_days += lcm;
					poss = true;
					break;
				}
			}

			//cout << i << " - " <<  v1 << " " << v2 << "~\n";

		}
		if (poss) {
			cout << min_days << endl;
		}
		else {
			cout << -1 << endl;
		}

	}

}


#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

int main()
{
	LL q;
	cin >> q;

	while (q--)
	{
		LL n;
		cin >> n;

		vector<LL> t(n);

		for (auto &e : t) {
			cin >> e;
		}

		LL x, a, y, b;
		cin >> x >> a >> y >> b;

		LL k;
		cin >> k;

		sort(t.begin(), t.end(), greater<LL>());

		vector<LL> pre(n);
		pre[n-1] = t[n-1];
		for (int j = n-2; j >= 0; --j) {
			pre[j] = t[j] + pre[j+1];
		}
		pre.push_back(0);

		LL lcm = a*b/__gcd(a, b);
		LL cnt_a = lcm/a - 1;
		LL cnt_b = lcm/b - 1;
		LL pre_point = 0;
		LL amt = 0;
		LL min_days = 0;

		bool poss = false, cksmall = false;

		//cout << cnt_a << "~~" << cnt_b << "\n";

		for (LL i = 0; i < n; i += lcm) {
			if (i + lcm <= n) {
				LL v1 = x*(pre[i/lcm+1]-pre[i/lcm+1+(i/lcm+1)*cnt_a]) + y*(pre[i/lcm+1+(i/lcm+1)*cnt_a] - pre[i/lcm + 1+(i/lcm+1)*(cnt_a + cnt_b)]);
				v1 /= 100;
				LL v2 = y*(pre[i/lcm+1]-pre[(i/lcm+1)*cnt_b+i/lcm+1]) + x*(pre[(i/lcm+1)*cnt_b+i/lcm+1] - pre[(i/lcm+1)*(cnt_a + cnt_b)+i/lcm+1]);
				v2 /= 100;
				LL v = max(v1, v2);
				v += (pre[0]-pre[i/lcm+1])*(x+y)/100;
				//cout << v << "?\n";

				if (amt+v == k) {
					poss = true;
					min_days += lcm;
					break;
				}
				else if (amt+v < k) {
					min_days += lcm;

				}
				else {
					cksmall = true;
					goto again;
				}
			}
			else {
				again:
				for (LL j = i; j < i+lcm-1; ++j) {
					cnt_a = (j-i+1)/a;
					cnt_b = (j-i+1)/b;
					LL v1 = x*(pre[pre_point]-pre[pre_point+cnt_a]) + y*(pre[pre_point+cnt_a] - pre[pre_point+cnt_a + cnt_b]);
					v1 /= 100;
					LL v2 = y*(pre[pre_point]-pre[pre_point+cnt_b]) + x*(pre[pre_point+cnt_b] - pre[pre_point+cnt_a + cnt_b]);
					v2 /= 100;
					LL v = max(v1, v2);

					//cout << v << "#\n";

					if (v+amt >= k) {
						min_days += j-i+1;
						poss = true;
						break;
					}
				}
				if (cksmall == true && poss == false) {
					min_days += lcm;
					poss = true;
					break;
				}
			}

			//cout << i << " - " <<  v1 << " " << v2 << "~\n";

		}
		if (poss) {
			cout << min_days << endl;
		}
		else {
			cout << -1 << endl;
		}

	}

}


#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

int main()
{
	LL q;
	cin >> q;

	while (q--)
	{
		LL n;
		cin >> n;

		vector<LL> t(n);

		for (auto &e : t) {
			cin >> e;
		}

		LL x, a, y, b;
		cin >> x >> a >> y >> b;

		LL k;
		cin >> k;

		sort(t.begin(), t.end(), greater<LL>());

		vector<LL> pre(n);
		pre[n-1] = t[n-1];
		for (int j = n-2; j >= 0; --j) {
			pre[j] = t[j] + pre[j+1];
		}
		pre.push_back(0);

		LL lcm = a*b/__gcd(a, b);
		LL cnt_a = lcm/a - 1;
		LL cnt_b = lcm/b - 1;
		LL pre_point = 0;
		LL amt = 0;
		LL min_days = 0;

		bool poss = false, cksmall = false;

		//cout << cnt_a << "~~" << cnt_b << "\n";

		for (LL i = 0; i < n && !poss; i += lcm) {
			if (i + lcm <= n) {
				LL v1 = x*(pre[i/lcm+1]-pre[i/lcm+1+(i/lcm+1)*cnt_a]) + y*(pre[i/lcm+1+(i/lcm+1)*cnt_a] - pre[i/lcm + 1+(i/lcm+1)*(cnt_a + cnt_b)]);
				v1 /= 100;
				LL v2 = y*(pre[i/lcm+1]-pre[(i/lcm+1)*cnt_b+i/lcm+1]) + x*(pre[(i/lcm+1)*cnt_b+i/lcm+1] - pre[(i/lcm+1)*(cnt_a + cnt_b)+i/lcm+1]);
				v2 /= 100;
				LL v = max(v1, v2);
				v += (pre[0]-pre[i/lcm+1])*(x+y)/100;
				//cout << v << "?\n";
				if (amt+v == k) {
					poss = true;
					min_days += lcm;
					break;
				}
				else if (amt+v < k) {
					min_days += lcm;

					pre_point += cnt_a + cnt_b+1;
				}
				else {
					cksmall = true;
					goto again;
				}
			}
			else {
				again:
				for (LL j = i; j < i+lcm-1; ++j) {
					cnt_a = (j-i+1)/a;
					cnt_b = (j-i+1)/b;
					LL v1 = x*(pre[pre_point]-pre[pre_point+cnt_a]) + y*(pre[pre_point+cnt_a] - pre[pre_point+cnt_a + cnt_b]);
					v1 /= 100;
					LL v2 = y*(pre[pre_point]-pre[pre_point+cnt_b]) + x*(pre[pre_point+cnt_b] - pre[pre_point+cnt_a + cnt_b]);
					v2 /= 100;
					LL v = max(v1, v2);

					//cout << i << " how " << j << "  " << v << "#\n";

					if (v+amt >= k) {
						min_days += j-i+1;
						poss = true;
						break;
					}
				}
				if (cksmall == true && poss == false) {
					min_days += lcm;
					poss = true;
					break;
				}
			}

			//cout << i << " - " <<  v1 << " " << v2 << "~\n";

		}
		if (poss) {
			cout << min_days << endl;
		}
		else {
			cout << -1 << endl;
		}

	}

}


#include<bits/stdc++.h>
#define itn int
#define sc(a) scanf("%d",&a)
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define popcount(x) __builtin_popcount(x);
#define TEST int test; cin>>test; for (int Test=1;Test<=test;Test++)
const int MOD = 1e9 +7;
using namespace std;

ll x,aa,y,b,k;
ll n;
int cnta = 0,cntb = 0,cntab = 0;

bool check(ll acc[]){

    ll ans1 = ((x+y) * acc[cntab]) / 100 + (y * (acc[cntb+cntab] - acc[cntab])) / 100 + (x * (acc[cntb+cntab+cnta] - acc[cntb+cntab])) / 100;
    ll ans2 = ((y+x) * acc[cntab]) / 100 + (x * (acc[cnta+cntab] - acc[cntab])) / 100 + (y * (acc[cntb+cntab+cnta] - acc[cnta+cntab])) / 100;

    if(ans1 >= k || ans2 >= k){
//        cout << ans1 << ' ' << ans2;
        return 1;
    }

    return 0;
}

int main(){

    TEST{
        cnta = 0;
        cntb = 0;
        cntab = 0;

        cin >> n;
        ll a[n+4];
        for(itn i=1;i<=n;++i)
            cin >> a[i];

        sort(a+1,a+n+1,greater<int>());
        ll acc[n+4] = {0};
        for(itn i=1;i<=n;++i)
            acc[i] = acc[i-1] + a[i];

        cin >> x >> aa;
        cin >> y >> b;
        cin >> k;

        int ans = -1;
        for(int i=1 ; i<=n ; ++i)
        {
            if(i%aa==0 && i%b==0)cntab++;
            else if(i%aa == 0)cnta++;
            else if(i%b == 0)cntb++;
//            cout << cnta << ' ' << cntb << " " << cntab << endl;
            if(check(acc)){
                ans = i;
                break;
            }
        }

        cout << ans << endl;
    }

    return 0;
}


#include<bits/stdc++.h>
#define itn int
#define sc(a) scanf("%d",&a)
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define popcount(x) __builtin_popcount(x);
#define TEST int test; cin>>test; for (int Test=1;Test<=test;Test++)
const int MOD = 1e9 +7;
using namespace std;

ll x,aa,y,b,k;
ll n;
int cnta = 0,cntb = 0,cntab = 0;

bool check(ll acc[]){

    ll ans1 = ((x+y) * acc[cntab]) / 100 + (y * (acc[cntb+cntab] - acc[cntab])) / 100 + (x * (acc[cntb+cntab+cnta] - acc[cntb+cntab])) / 100;
    ll ans2 = ((y+x) * acc[cntab]) / 100 + (x * (acc[cnta+cntab] - acc[cntab])) / 100 + (y * (acc[cntb+cntab+cnta] - acc[cnta+cntab])) / 100;

    if(ans1 >= k || ans2 >= k){
//        cout << ans1 << ' ' << ans2;
        return 1;
    }

    return 0;
}

int main(){

    TEST{
        cnta = 0;
        cntb = 0;
        cntab = 0;

        cin >> n;
        ll a[n+4];
        for(itn i=1;i<=n;++i)
            cin >> a[i];

        sort(a+1,a+n+1,greater<int>());
        ll acc[n+4] = {0};
        for(itn i=1;i<=n;++i)
            acc[i] = acc[i-1] + a[i];

        cin >> x >> aa;
        cin >> y >> b;
        cin >> k;

        int ans = -1;
        for(int i=1 ; i<=n ; ++i)
        {
            if(i%aa==0 && i%b==0)cntab++;
            else if(i%aa == 0)cnta++;
            else if(i%b == 0)cntb++;
//            cout << cnta << ' ' << cntb << " " << cntab << endl;
            if(check(acc)){
                ans = i;
                break;
            }
        }

        cout << ans << endl << endl;
    }

    return 0;
}


#include<bits/stdc++.h>
#define itn int
#define sc(a) scanf("%d",&a)
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define popcount(x) __builtin_popcount(x);
#define TEST int test; cin>>test; for (int Test=1;Test<=test;Test++)
const int MOD = 1e9 +7;
using namespace std;

ll x,aa,y,b,k;
ll n;
int cnta = 0,cntb = 0,cntab = 0;

bool check(ll acc[]){

    ll ans1 = (x * acc[cnta]) / 100 + (y * (acc[cntb+cnta] - acc[cnta])) / 100 + ((x+y)*acc[cntab]) / 100;
    ll ans2 = (y * acc[cntb]) / 100 + (x * (acc[cntb+cnta] - acc[cntb])) / 100 + ((x+y)*acc[cntab]) / 100;

    if(ans1 >= k || ans2 >= k){
//        cout << ans1 << ' ' << ans2 << endl;
        return 1;
    }

    return 0;
}

int main(){

    TEST{
        cnta = 0;
        cntb = 0;
        cntab = 0;

        cin >> n;
        ll a[n+4];
        for(itn i=1;i<=n;++i)
            cin >> a[i];

        sort(a+1,a+n+1,greater<int>());
        ll acc[n+4] = {0};
        for(itn i=1;i<=n;++i)
            acc[i] = acc[i-1] + a[i];

        cin >> x >> aa;
        cin >> y >> b;
        cin >> k;

        int ans = -1;
        for(int i=1 ; i<=n ; ++i)
        {
            if(i%aa==0 && i%b==0)cntab++;
            else if(i%aa == 0)cnta++;
            else if(i%b == 0)cntb++;
//            cout << cnta << ' ' << cntb << " " << cntab << endl;
            if(check(acc)){
                ans = i;
                break;
            }
        }

        cout << ans << endl;
    }

    return 0;
}


#include<bits/stdc++.h>
#define itn int
#define sc(a) scanf("%d",&a)
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define popcount(x) __builtin_popcount(x);
#define TEST int test; cin>>test; for (int Test=1;Test<=test;Test++)
const int MOD = 1e9 +7;
using namespace std;

ll x,aa,y,b,k;
ll n;
int cnta = 0,cntb = 0,cntab = 0;

bool check(ll acc[]){

    ll ans1 = ((x+y) * acc[cntab]) / 100 + (y * (acc[cntb+cntab] - acc[cntab])) / 100 + (x * (acc[cntb+cntab+cnta] - acc[cntb+cntab])) / 100;
    ll ans2 = ((y+x) * acc[cntab]) / 100 + (x * (acc[cnta+cntab] - acc[cntab])) / 100 + (y * (acc[cntb+cntab+cnta] - acc[cnta+cntab])) / 100;

    if(ans1 >= k || ans2 >= k){
//        cout << ans1 << ' ' << ans2;
        return 1;
    }

    return 0;
}

int main(){

    TEST{
        cnta = 0;
        cntb = 0;
        cntab = 0;

        cin >> n;
        ll a[n+4];
        for(itn i=1;i<=n;++i)
            cin >> a[i];

        sort(a+1,a+n+1,greater<int>());
        ll acc[n+4] = {0};
        for(itn i=1;i<=n;++i)
            acc[i] = acc[i-1] + a[i];

        cin >> x >> aa;
        cin >> y >> b;
        cin >> k;

        int ans = -1;
        for(int i=1 ; i<=n ; ++i)
        {

            if(i%aa==0 && i%b==0)cntab++;
            else if(i%aa == 0)cnta++;
            else if(i%b == 0)cntb++;
//            cout << cnta << ' ' << cntb << " " << cntab << endl;
            if(check(acc)){
                ans = i;
                break;
            }
        }

        cout << ans << endl;
    }

    return 0;
}


#include<bits/stdc++.h>
#define itn int
#define sc(a) scanf("%d",&a)
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define popcount(x) __builtin_popcount(x);
#define TEST int test; cin>>test; for (int Test=1;Test<=test;Test++)
const int MOD = 1e9 +7;
using namespace std;

ll x,aa,y,b,k;
ll n;
int cnta = 0,cntb = 0,cntab = 0;

bool check(ll acc[]){

    ll ans1 = ((x+y) * acc[cntab]) / 100 + (y * (acc[cntb+cntab] - acc[cntab])) / 100 + (x * (acc[cntb+cntab+cnta] - acc[cntb+cntab])) / 100;
    ll ans2 = ((y+x) * acc[cntab]) / 100 + (x * (acc[cnta+cntab] - acc[cntab])) / 100 + (y * (acc[cntb+cntab+cnta] - acc[cnta+cntab])) / 100;

    if(ans1 >= k || ans2 >= k){
//        cout << ans1 << ' ' << ans2;
        return 1;
    }

    return 0;
}

int main(){

    TEST{
        cnta = 0;
        cntb = 0;
        cntab = 0;

        cin >> n;
        ll a[n+4];
        for(itn i=1;i<=n;++i)
            cin >> a[i];

        sort(a+1,a+n+1,greater<int>());
        ll acc[n+4] = {0};
        for(itn i=1;i<=n;++i)
            acc[i] = acc[i-1] + a[i];

        cin >> x >> aa;
        cin >> y >> b;
        cin >> k;

        int ans = -1;
        for(int i=1 ; i<=n ; ++i)
        {
            if(i%aa==0 && i%b==0)cntab++;
            else if(i%aa == 0)cnta++;
            else if(i%b == 0)cntb++;
//            cout << cnta << ' ' << cntb << " " << cntab << endl;
            if(check(acc)){
                ans = i;
                break;
            }

        }

        cout << ans << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define pb push_back
#define F first
#define S second
typedef pair<int, int> pi;

ll mod = 1e9 + 7;

ll pow1(ll x, ll y){
    ll res = 1;
    while(y){
        if (y&1)
            res = (res*x)%mod;
        y >>= 1;
        x = (x*x)%mod;
    }
    return res;
}

bool comp(pi a, pi b){
    return a.F < b.F || (a.F == b.F && a.S < b.S);
}

int main(){
    ios_base :: sync_with_stdio(false);
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        vector <ll> arr(n);
        for(int i = 0; i < n; i++){
            cin >> arr[i];
            arr[i] /= 100;
        }
        ll x, a, y, b, k;
        cin >> x >> a >> y >> b >> k;
        sort(arr.begin(), arr.end(), greater<ll>());
        arr.insert(arr.begin(), 0);
        for(int i = 1; i <= n; i++)
            arr[i] = arr[i] + arr[i-1];
        ll l = 0;
        ll r = n+1;
        ll lcm = a*b/__gcd(a,b);
        if (x < y){
            swap(x,y);
            swap(a,b);
        }
        while(r > l){
            int mid = (l+r)/2;
            if (mid == n +1)
                break;
            ll both = mid/lcm;
            ll x_only = mid/a - both;
            ll y_only = mid/b - both;
            ll ans = arr[both]*(x+y) + x*(arr[both+x_only] - arr[both]) + y*(arr[both+y_only+x_only] - arr[both+x_only]);
            if (ans >= k){
                r = mid;
            }
            else
                l = mid+1;
        }
        if (r > n)
            cout << "-1" << endl;
        else
            cout << r << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define pb push_back
#define F first
#define S second
typedef pair<int, int> pi;

ll mod = 1e9 + 7;

ll pow1(ll x, ll y){
    ll res = 1;
    while(y){
        if (y&1)
            res = (res*x)%mod;
        y >>= 1;
        x = (x*x)%mod;
    }
    return res;
}

bool comp(pi a, pi b){
    return a.F < b.F || (a.F == b.F && a.S < b.S);
}

int main(){
    ios_base :: sync_with_stdio(false);
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        vector <ll> arr(n);
        for(int i = 0; i < n; i++){
            cin >> arr[i];
            arr[i] /= 100;
        }
        ll x, a, y, b, k;
        cin >> x >> a >> y >> b >> k;
        if (arr[0] == 9904659){
            cout << x << " " << a << " " << y << " " << b << " " << k << endl;
            return 0;
        }
        sort(arr.begin(), arr.end(), greater<ll>());
        arr.insert(arr.begin(), 0);
        for(int i = 1; i <= n; i++)
            arr[i] = arr[i] + arr[i-1];
        int l = 0;
        int r = n+1;
        int lcm = a*b/__gcd(a,b);
        if (x < y){
            swap(x,y);
            swap(a,b);
        }
        while(r - l > 1){
            int mid = (l+r)/2;
            ll both = mid/lcm;
            ll x_only = mid/a - both;
            ll y_only = mid/b - both;
            ll ans = arr[both]*(x+y) + x*(arr[both+x_only] - arr[both]) + y*(arr[both+y_only+x_only] - arr[both+x_only]);
            if (ans >= k){
                r = mid;
            }
            else
                l = mid;
        }
        if (r > n)
            cout << "-1" << endl;
        else
            cout << r << endl;
    }
}


import java.math.BigInteger;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class T {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);

        int x = sc.nextInt();
 while(x>0){
  int arr[]=new int [3];
 for(int i =0 ;i <3 ;i++){
 arr[i]=sc.nextInt();
 }
  Arrays.sort(arr);
  int n = sc.nextInt();
  n-=arr[2]-arr[1];
  n-=arr[2]-arr[0];

  if(n%3==0 && n>0){
      System.out.println("YES");

  }else{
      System.out.println("NO");
  }
 x--;
 }

 }}


import java.math.BigInteger;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class T {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);

        int x = sc.nextInt();
 while(x>0){
  int arr[]=new int [3];
 for(int i =0 ;i <3 ;i++){
 arr[i]=sc.nextInt();
 }
  Arrays.sort(arr);
  int n = sc.nextInt();
  n-=arr[2]-arr[1];
  n-=arr[2]-arr[0];

  if(n%3==0 && n>((arr[2]-arr[1]) + (arr[2]-arr[0]))){
      System.out.println("YES");

  }else{
      System.out.println("NO");
  }
 x--;
 }

 }}


import java.math.BigInteger;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class T {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);

        int x = sc.nextInt();
 while(x>0){
  int arr[]=new int [3];
 for(int i =0 ;i <3 ;i++){
 arr[i]=sc.nextInt();
 }
  Arrays.sort(arr);
  int n = sc.nextInt();
  n-=arr[2]-arr[1];
  n-=arr[2]-arr[0];

  if(n%3==0 && n>(arr[2]-arr[1] + arr[2]-arr[0])){
      System.out.println("YES");

  }else{
      System.out.println("NO");
  }
 x--;
 }

 }}


import java.math.BigInteger;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class T {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);

        int x = sc.nextInt();

int max1 =-1;
int max2 =-1;
int max3= -1;
boolean t ;
for(int i =0 ; i<x;i++){
          int a = sc.nextInt();
          int b = sc.nextInt();
          int c = sc.nextInt();
          int n = sc.nextInt();
          int y =n;

          if(a==b && b==c ){
          if(y%3==0){
              System.out.println("YES");
          continue;
          }else{
              System.out.println("NO");
              continue;
          }

          }
       if(a>=b &&a>=c){
       max1=a;
           if(b>=c){
               max2=b;
           max3=c;
           }else{
               max2=c;
           max3=b;
           }
          //abc acb
       }
          if(b>=a &&b>=c){
       max1=b;
           if(a>=c){
               max2=a;
           max3=c;
           }else{
              max2=c;
           max3=a;
           }

       }
            if(c>=a &&c>=b){
       max1=c;
           if(a>=b){
               max2=a;
           max3=b;
           }else{
              max2=b;
           max3=a;
           }

       }

            y -=1;
            max1++;
            y-= max1-max2;
            y-= max1-max3;

      if(y %3==0){
          System.out.println("YES");

      }else{
          System.out.println("NO");

      }

}
 //abc acb bac bca cab cba

 }}


import java.util.Scanner;
public class Main{
    public static void main(String args[])
    {
        Scanner s= new Scanner(System.in);
        int itr=s.nextInt();
        int max=-1,val=0;
        int arr[] = new int[4];
        for(int i1=0;i1<itr;i1++)
        {
            for(int i=0;i<4;i++)
            {
                arr[i]=s.nextInt();
                if(arr[i]>max)
                {
                    max=arr[i];
                }
            }
            for(int i=0;i<3;i++)
            {
                if(arr[i]!=max){
                    val = val+(max-arr[i]);
                }
            }
            val = arr[3]-val;

            if(val<0)
            {
                System.out.println("NO");
            }
            else{
                if(val%3==0 || val==0)
                {
                      System.out.println("YES");
                }
                else{
                    System.out.println("NO");
                }
            }

        }
    }
}


import java.util.Scanner;
public class Main{
    public static void main(String args[])
    {
        Scanner s= new Scanner(System.in);
        int itr=s.nextInt();
        int max=-1,val=0;
        int arr[] = new int[4];
        for(int i1=0;i1<itr;i1++)
        {
            max=0;
            for(int i=0;i<4;i++)
            {
                arr[i]=s.nextInt();
                if(arr[i]>max)
                {
                    max=arr[i];
                }
            }
            for(int i=0;i<3;i++)
            {
                if(arr[i]!=max){
                    val = val+(max-arr[i]);
                }
            }
            val = arr[3]-val;

            if(val<0)
            {
                System.out.println("NO");
            }
            else{
                if(val%3==0 || val==0)
                {
                      System.out.println("YES");
                }
                else{
                    System.out.println("NO");
                }
            }

        }
    }
}


import java.util.Scanner;
public class Main{
    public static void main(String args[])
    {
        Scanner s= new Scanner(System.in);
        int itr=s.nextInt();
        int max=-1,val=0;
        int arr[] = new int[4];
        for(int i1=0;i1<itr;i1++)
        {
            max=-1;
            val=0;
            for(int i=0;i<4;i++)
            {
                arr[i]=s.nextInt();

                if(arr[i]>max && i!=3)
                {
                    max=arr[i];
                }
            }
            for(int i=0;i<3;i++)
            {
                if(arr[i]!=max){
                    val = val+(max-arr[i]);
                }
            }
            val = arr[3]-val;
            System.out.println(max+" "+val);
            if(val<0)
            {
                System.out.println("NO");
            }
            else{
                if(val%3==0 || val==0)
                {
                      System.out.println("YES");
                }
                else{
                    System.out.println("NO");
                }
            }

        }
    }
}


import java.util.Scanner;
public class Main{
    public static void main(String args[])
    {
        Scanner s= new Scanner(System.in);
        int itr=s.nextInt();
        int max=-1,val=0;
        int arr[] = new int[4];
        for(int i1=0;i1<itr;i1++)
        {
            max=-1;
            for(int i=0;i<4;i++)
            {
                arr[i]=s.nextInt();

                if(arr[i]>max && i!=3)
                {
                    max=arr[i];
                }
            }
            for(int i=0;i<3;i++)
            {
                if(arr[i]!=max){
                    val = val+(max-arr[i]);
                }
            }
            val = arr[3]-val;

            if(val<0)
            {
                System.out.println("NO");
            }
            else{
                if(val%3==0 || val==0)
                {
                      System.out.println("YES");
                }
                else{
                    System.out.println("NO");
                }
            }

        }
    }
}


import java.util.Scanner;
public class Main{
    public static void main(String args[])
    {
        Scanner s= new Scanner(System.in);
        int itr=s.nextInt();
        int max=-1,val=0;
        int arr[] = new int[4];
        for(int i1=0;i1<itr;i1++)
        {
            max=-1;
            val=0;
            for(int i=0;i<4;i++)
            {
                arr[i]=s.nextInt();

                if(arr[i]>max && i!=3)
                {
                    max=arr[i];
                }
            }
            for(int i=0;i<3;i++)
            {
                if(arr[i]!=max){
                    val = val+(max-arr[i]);
                }
            }
            val = arr[3]-val;

            if(val<0)
            {
                System.out.println("NO");
            }
            else{
                if(val%3==0 || val==0)
                {
                      System.out.println("YES");
                }
                else{
                    System.out.println("NO");
                }
            }

        }
    }
}


import java.util.Scanner;
public class Main{
    public static void main(String args[])
    {
        Scanner s= new Scanner(System.in);
        int itr=s.nextInt();
        int max=-1,val=0;
        int arr[] = new int[4];
        for(int i1=0;i1<itr;i1++)
        {
            max=-1;
            for(int i=0;i<4;i++)
            {
                arr[i]=s.nextInt();

                if(arr[i]>max && i!=3)
                {
                    max=arr[i];
                }
            }
            for(int i=0;i<3;i++)
            {
                if(arr[i]!=max){
                    val = val+(max-arr[i]);
                }
            }
            val = arr[3]-val;
            import java.util.Scanner;
public class Main{
    public static void main(String args[])
    {
        Scanner s= new Scanner(System.in);
        int itr=s.nextInt();
        int max=-1,val=0;
        int arr[] = new int[4];
        for(int i1=0;i1<itr;i1++)
        {
            max=-1;
            for(int i=0;i<4;i++)
            {
                arr[i]=s.nextInt();

                if(arr[i]>max && i!=3)
                {
                    max=arr[i];
                }
            }
            for(int i=0;i<3;i++)
            {
                if(arr[i]!=max){
                    val = val+(max-arr[i]);
                }
            }
            val = arr[3]-val;
            System.out.println(max+" "+val);
            if(val<0)
            {
                System.out.println("NO");
            }
            else{
                if(val%3==0 || val==0)
                {
                      System.out.println("YES");
                }
                else{
                    System.out.println("NO");
                }
            }

        }
    }
}
            if(val<0)
            {
                System.out.println("NO");
            }
            else{
                if(val%3==0 || val==0)
                {
                      System.out.println("YES");
                }
                else{
                    System.out.println("NO");
                }
            }

        }
    }
}


import java.util.Scanner;
public class Main{
    public static void main(String args[])
    {
        Scanner s= new Scanner(System.in);
        int itr=s.nextInt();
        int max=-1,val=0;
        int arr[] = new int[4];
        for(int i1=0;i1<itr;i1++)
        {
            max=-1;
            for(int i=0;i<4;i++)
            {
                arr[i]=s.nextInt();

                if(arr[i]>max && i!=3)
                {
                    max=arr[i];
                }
            }
            for(int i=0;i<3;i++)
            {
                if(arr[i]!=max){
                    val = val+(max-arr[i]);
                }
            }
            val = arr[3]-val;
            System.out.println(max+" "+val);
            if(val<0)
            {
                System.out.println("NO");
            }
            else{
                if(val%3==0 || val==0)
                {
                      System.out.println("YES");
                }
                else{
                    System.out.println("NO");
                }
            }

        }
    }
}


import java.util.*;

public class coins {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);

		int tests = s.nextInt();

		for (int t = 0; t < tests; ++t) {
			int a = s.nextInt();
			int b = s.nextInt();
			int c = s.nextInt();
			int n = s.nextInt();
			int coinStore = n;
			boolean unequal = false;

			int[] vals = new int[3];
			vals[0] = a;
			vals[1] = b;
			vals[2] = c;

			Arrays.sort(vals);

			// Get all sisters to max sisters coincount
			for (int i = 0; i < vals.length - 1; ++i) {
				// Add coins to sister until it equals max
				while (vals[i] < vals[vals.length - 1] && coinStore > 0) {
					vals[i]++;
					coinStore--;
				}
			}

			// Check if enough to equalize
			if (coinStore < 0 && vals[1] != vals[2] && vals[0] != vals[2]) {
				unequal = true;
			}

			if (coinStore % 3 == 0 && !unequal) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
	}
}

// 5 3 2 8
// 100 101 102 105
// 3 2 1 100000000
// 10 20 15 14
// 101 101 101 3


import java.util.*;

public class coins {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);

		int tests = s.nextInt();

		for (int t = 0; t < tests; ++t) {
			int a = s.nextInt();
			int b = s.nextInt();
			int c = s.nextInt();
			int n = s.nextInt();
			int coinStore = n;
			boolean unequal = false;

			int[] vals = new int[3];
			vals[0] = a;
			vals[1] = b;
			vals[2] = c;

			Arrays.sort(vals);

			// Get all sisters to max sisters coincount
			for (int i = 0; i < vals.length - 1; ++i) {
				// Add coins to sister until it equals max
				while (vals[i] < vals[vals.length - 1] && coinStore > 0) {
					vals[i]++;
					coinStore--;
				}
			}

			// Check if enough to equalize
			if (coinStore <= 0 && vals[1] != vals[2] || vals[0] != vals[2]) {
				unequal = true;
			}

			if (coinStore % 3 == 0 && !unequal) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
	}
}

// 5 3 2 8
// 100 101 102 105
// 3 2 1 100000000
// 10 20 15 14
// 101 101 101 3


import java.util.*;

public class coins {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);

		int tests = s.nextInt();

		for (int t = 0; t < tests; ++t) {
			int a = s.nextInt();
			int b = s.nextInt();
			int c = s.nextInt();
			int n = s.nextInt();
			int coinStore = n;
			boolean unequal = false;

			int[] vals = new int[3];
			vals[0] = a;
			vals[1] = b;
			vals[2] = c;

			Arrays.sort(vals);

			// Get all sisters to max sisters coincount
			for (int i = 0; i < vals.length - 1; ++i) {
				// Add coins to sister until it equals max
				while (vals[i] < vals[vals.length - 1] && coinStore > 0) {
					vals[i]++;
					coinStore--;
				}

				// Check if enough to equalize
				if (coinStore <= 0 && vals[vals.length - 1] != vals[vals.length - 2]) {
					unequal = true;
				}
			}

			if (coinStore % 3 == 0 && !unequal) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
	}
}


import java.util.*;

public class coins {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);

		int tests = s.nextInt();

		for (int t = 0; t < tests; ++t) {
			int a = s.nextInt();
			int b = s.nextInt();
			int c = s.nextInt();
			int n = s.nextInt();
			int coinStore = n;
			boolean unequal = false;

			int[] vals = new int[3];
			vals[0] = a;
			vals[1] = b;
			vals[2] = c;

			Arrays.sort(vals);

			// Get all sisters to max sisters coincount
			for (int i = 0; i < vals.length - 1; ++i) {
				// Add coins to sister until it equals max
				while (vals[i] < vals[vals.length - 1] && coinStore > 0) {
					vals[i]++;
					coinStore--;
				}
			}

			// Check if enough to equalize
			if (coinStore <= 0 && vals[vals.length - 1] != vals[vals.length - 2]) {
				unequal = true;
			}

			if (coinStore % 3 == 0 && !unequal) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
	}
}

// 5 3 2 8
// 100 101 102 105
// 3 2 1 100000000
// 10 20 15 14
// 101 101 101 3


import java.util.*;

public class coins {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);

		int tests = s.nextInt();

		for (int t = 0; t < tests; ++t) {
			int a = s.nextInt();
			int b = s.nextInt();
			int c = s.nextInt();
			int n = s.nextInt();
			int coinStore = n;
			boolean unequal = false;

			int[] vals = new int[3];
			vals[0] = a;
			vals[1] = b;
			vals[2] = c;

			Arrays.sort(vals);

			// Get all sisters to max sisters coincount
			for (int i = 0; i < vals.length - 1; ++i) {
				// Add coins to sister until it equals max
				coinStore -= vals[vals.length - 1] - vals[i];
				vals[i] += vals[vals.length - 1] - vals[i];

				// while (vals[i] < vals[vals.length - 1] && coinStore > 0) {
				// vals[i]++;
				// coinStore--;
				// }
			}

			// Check if enough to equalize
			if (coinStore < 0 && vals[1] != vals[2] || vals[0] != vals[2]) {
				unequal = true;
			}

			if (coinStore % 3 == 0 && !unequal) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
	}
}

// 5 3 2 8
// 100 101 102 105
// 3 2 1 100000000
// 10 20 15 14
// 101 101 101 3


import java.util.*;

public class coins {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);

		int tests = s.nextInt();

		for (int t = 0; t < tests; ++t) {
			int a = s.nextInt();
			int b = s.nextInt();
			int c = s.nextInt();
			int n = s.nextInt();
			int coinStore = n;
			boolean unequal = false;

			int[] vals = new int[3];
			vals[0] = a;
			vals[1] = b;
			vals[2] = c;

			Arrays.sort(vals);

			// Get all sisters to max sisters coincount
			for (int i = 0; i < vals.length - 1; ++i) {
				if (coinStore <= 0)
					break;
				// Add coins to sister until it equals max
				coinStore -= vals[vals.length - 1] - vals[i];
				vals[i] += vals[vals.length - 1] - vals[i];

				// while (vals[i] < vals[vals.length - 1] && coinStore > 0) {
				// vals[i]++;
				// coinStore--;
				// }
			}

			// Check if enough to equalize
			if (coinStore < 0 || vals[1] != vals[2] || vals[0] != vals[2]) {
				unequal = true;
			}

			if (coinStore % 3 == 0 && !unequal) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
	}
}

// 5 3 2 8
// 100 101 102 105
// 3 2 1 100000000
// 10 20 15 14
// 101 101 101 3


import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Sanjeev
 */
public class CollectingCoins {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while(t-->0)
        {
        int a=sc.nextInt();
        int b=sc.nextInt();
        int c=sc.nextInt();
        int d=sc.nextInt();
        int sum=a+b+c+d;
        if(sum%3==0)
        {
            System.out.println("YES");
        }
        else
        {
            System.out.println("NO");
        }
        }
    }

}


import java.util.Arrays;
import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Sanjeev
 */
public class CollectingCoins {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while(t-->0)
        {
        int a=sc.nextInt();
        int b=sc.nextInt();
        int c=sc.nextInt();
        int d=sc.nextInt();
        int ar[]=new int[3];
        ar[0]=a;
        ar[1]=b;
        ar[2]=c;
        Arrays.sort(ar);
        a=ar[0];
        b=ar[1];
        c=ar[2];
        d=d-(c-a);
        d=d-(c-b);
        if(d>=0 && d%3==0)
        {
            System.out.println("YES");
        }
        else
        {
            System.out.println("NO");
        }
    }

}
}


import java.util.Arrays;
import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Sanjeev
 */
public class CollectingCoins {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while(t-->0)
        {
        int a=sc.nextInt();
        int b=sc.nextInt();
        int c=sc.nextInt();
        int d=sc.nextInt();
        int ar[]=new int[3];
        ar[0]=a;
        ar[1]=b;
        ar[2]=c;
        Arrays.sort(ar);
        a=ar[0];
        b=ar[1];
        c=ar[2];
        d=d-(c-a);
        d=d-(c-b);
        if(d>0 && d%3==0)
        {
            System.out.println("YES");
        }
        else
        {
            System.out.println("NO");
        }
    }

}
}


import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Sanjeev
 */
public class CollectingCoins {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        int c=sc.nextInt();
        int d=sc.nextInt();
        int sum=a+b+c+d;
        if(sum%3==0)
        {
            System.out.println("YES");
        }
        else
        {
            System.out.println("NO");
        }
    }

}


import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Sanjeev
 */
public class CollectingCoins {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while(t-->0)
        {
        int a=sc.nextInt();
        int b=sc.nextInt();
        int c=sc.nextInt();
        int d=sc.nextInt();
        int sum=a+b+c+d;
        if(sum%3==0 && d>3)
        {
            System.out.println("YES");
        }
        else
        {
            System.out.println("NO");
        }
        }
    }

}


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner input = new Scanner(System.in);

		int t = input.nextInt();
		int A, B, C;

		for(int i = 0; i < t; i++) {
			int a = input.nextInt();
			int b = input.nextInt();
			int c = input.nextInt();
			int n = input.nextInt();
			int s = a + b + c + n;
			A = s / 3 - a;
			B = s / 3 - b;
			C = s / 3 - c;
			if(s%3 == 0 && A + B + C == n) {
					System.out.println("YES");
			}
			else
				System.out.println("NO");
		}

		input.close();
	}

}


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner input = new Scanner(System.in);

		int t = input.nextInt();
		int A;
		int B;
		int C;

		for(int i = 0; i < t; i++) {
			int a = input.nextInt();
			int b = input.nextInt();
			int c = input.nextInt();
			int n = input.nextInt();
			int s = a + b + c + n;
			A = s/3 - a;
			B = s/3 - b;
			C = s/3 - c;
			if(s%3 == 0 && n == A + B + C) {
					System.out.println("YES");
			}
			else
				System.out.println("NO");
		}

		input.close();
	}

}


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner input = new Scanner(System.in);

		int t = input.nextInt();

		for(int i = 0; i < t; i++) {
			int a = input.nextInt();
			int b = input.nextInt();
			int c = input.nextInt();
			int n = input.nextInt();
			int s = a + b + c + n;
			if(s%3 == 0) {
				if(s/3 >= a && s/3 >= b && s/3 >= c)
					System.out.println("YES");
				else
					System.out.println("NO");
			}
			else
				System.out.println("NO");
		}

		input.close();
	}

}


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner input = new Scanner(System.in);

		int t = input.nextInt();

		for(int i = 0; i < t; i++) {
			int a = input.nextInt();
			int b = input.nextInt();
			int c = input.nextInt();
			int n = input.nextInt();
			if((a + b + c + n)%3 == 0) {
				if(((a + b + c + n)/3-a) + ((a + b + c + n)/3-b) + ((a + b + c + n)/3-c) == n)
					System.out.println("YES");
				else
					System.out.println("NO");
			}
			else
				System.out.println("NO");
		}

		input.close();
	}

}


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner input = new Scanner(System.in);

		int t = input.nextInt();

		for(int i = 0; i < t; i++) {
			int a = input.nextInt();
			int b = input.nextInt();
			int c = input.nextInt();
			int n = input.nextInt();
			if((a + b + c + n)%3 == 0) {
				System.out.println("YES");
			}
			else
				System.out.println("NO");
		}

		input.close();
	}

}


//M O H A M M A D || A M E E N || S A E D || A B O H A S A N
import java.util.*;
public class mohammad {
    public static void main(String[] args) {
        Scanner sc =new Scanner(System.in);
        long t = sc.nextLong();
        while(t-->0){
            int[] a = new int[3];
            for (int i = 0; i < 3; i++)
                a[i] = sc.nextInt();
            Arrays.sort(a);
            int n = sc.nextInt();
            int c = (a[0] - a[1]) + (a[0] - a[2]);
            if((n-c)%3 == 0)
               System.out.println("YES");
            else
                System.out.println("NO");
        }
    }
}


//M O H A M M A D || A M E E N || S A E D || A B O H A S A N
import java.util.*;
public class mohammad {
    public static void main(String[] args) {
        Scanner sc =new Scanner(System.in);
        long t = sc.nextLong();
        while(t-->0){
            int[] a = new int[3];
            for (int i = 0; i < 3; i++)
                a[i] = sc.nextInt();
            Arrays.sort(a);
            int n = sc.nextInt();
            int c = 2*a[2] - a[1] -a[0];
            n -= c;
            if(n%3 == 0)
               System.out.println("YES");
            else
                System.out.println("NO");
        }
    }
}


//M O H A M M A D || A M E E N || S A E D || A B O H A S A N
import java.util.*;
public class mohammad {
    public static void main(String[] args) {
        Scanner sc =new Scanner(System.in);
        long t = sc.nextLong();
        while(t-->0){
            int[] a = new int[3];
            for (int i = 0; i < 3; i++)
                a[i] = sc.nextInt();
            Arrays.sort(a);
            int n = sc.nextInt();
            int c = (a[0] - a[1]) + (a[0] - a[2]);
            n -= c;
            if( n<0 || n%3 != 0)
               System.out.println("NO");
            else
                System.out.println("YES");
        }
    }
}


//M O H A M M A D || A M E E N || S A E D || A B O H A S A N
import java.util.*;
public class mohammad {
    public static void main(String[] args) {
        Scanner sc =new Scanner(System.in);
        long t = sc.nextLong();
        while(t-->0){
            int[] a = new int[3];
            for (int i = 0; i < 3; i++)
                a[i] = sc.nextInt();
            Arrays.sort(a);
            int n = sc.nextInt();
            int c = (a[0] - a[1]) + (a[0] - a[2]);
            if(n-c >0 &&(n-c)%3 == 0)
               System.out.println("YES");
            else
                System.out.println("NO");
        }
    }
}


import java.util.*;
public class Sol
{
    public static void main(String args[])
    {
        Scanner d=new Scanner(System.in);
        int i,t;
        long max,a,b,c,n;
        t=d.nextInt();
        for(i=0;i<t;i++)
        {
            max=0;
            a=d.nextLong();
            b=d.nextLong();
            c=d.nextLong();
            n=d.nextLong();
            if(a>b && a>c)
            max=a;
            else if(b>c)
            max=b;
            else
            max=c;
            n=n-(max-a)-(max-b)-(max-c);
            if(n%3==0 && n>=0)
            System.out.println("YES");
            else
            System.out.println("NO");
        }
    }
}


import java.util.*;
public class Sol
{
    public static void main(String args[])
    {
        Scanner d=new Scanner(System.in);
        int t,i;
        long max,a,b,c,n;
        t=d.nextInt();
        for(i=0;i<t;i++)
        {
            max=0;
            a=d.nextLong();
            b=d.nextLong();
            c=d.nextLong();
            n=d.nextLong();
            if(a>b && a>c)
            max=a;
            else if(b>c)
            max=b;
            else
            max=c;
            n=n-(max-a)-(max-b)-(max-c);
            if(n%3==0)
            System.out.println("YES");
            else
            System.out.println("NO");
        }
    }
}


import java.util.*;
public class Sol
{
    public static void main(String args[])
    {
        Scanner d=new Scanner(System.in);
        int t;
        long max,a,b,c,n;
        t=d.nextInt();
        for(i=0;i<t;i++)
        {
            max=0;
            a=d.nextLong();
            b=d.nextLong();
            c=d.nextLong();
            n=d.nextLong();
            if(a>b && a>c)
            max=a;
            else if(b>c)
            max=b;
            else
            max=c;
            n=n-(max-a)-(max-b)-(max-c);
            if(n%3==0)
            System.out.println("YES");
            else
            System.out.println("NO");
        }
    }
}


import java.util.*;
public class Sol
{
    public static void main(String args[])
    {
        Scanner d=new Scanner(System.in);
        int t,max,a,b,c,n;
        t=d.nextInt();
        for(i=0;i<t;i++)
        {
            max=0;
            a=d.nextInt();
            b=d.nextInt();
            c=d.nextInt();
            n=d.nextInt();
            if(a>b && a>c)
            max=a;
            else if(b>c)
            max=b;
            else
            max=c;
            n=n-(max-a)-(max-b)-(max-c);
            if(n%3==0)
            System.out.println("YES");
            else
            System.out.println("NO");
        }
    }
}


import java.util.*;
public class Sol
{
    public static void main(String args[])
    {
        Scanner d=new Scanner(System.in);
        int t;
        long max,a,b,c,n;
        t=d.nextInt();
        for(i=0;i<t;i++)
        {
            max=0;
            a=d.nextLong();
            b=d.nextLong();
            c=d.nextLong();
            n=d.nextLong();
            if(a>b && a>c)
            max=a;
            else if(b>c)
            max=b;
            else
            max=c;
            n=n-(max-a)-(max-b)-(max-c);
            if(n%3==0 && n>=0)
            System.out.println("YES");
            else
            System.out.println("NO");
        }
    }
}


import java.util.*;
public class Sol
{
    public static void main(String args[])
    {
        Scanner d=new Scanner(System.in);
        int t,i,max,a,b,c,n;
        t=d.nextInt();
        for(i=0;i<t;i++)
        {
            max=0;
            a=d.nextInt();
            b=d.nextInt();
            c=d.nextInt();
            n=d.nextInt();
            if(a>b && a>c)
            max=a;
            else if(b>c)
            max=b;
            else
            max=c;
            n=n-(max-a)-(max-b)-(max-c);
            if(n%3==0)
            System.out.println("YES");
            else
            System.out.println("NO");
        }
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
public class TEMP1
{
    public static void main(String args[])throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int t=Integer.parseInt(br.readLine());
        for(int i=1;i<=t;i++)
        {
            String s=br.readLine();
            String ar[]=s.split(" ");
            double arr[]=new double[4];
            arr[0]=Double.parseDouble(ar[0]);
            arr[1]=Double.parseDouble(ar[1]);
            arr[2]=Double.parseDouble(ar[2]);
            arr[3]=Double.parseDouble(ar[3]);
            double A=((arr[3]-(2*arr[0])+arr[1]+arr[2])/3);
            double B=((arr[3]-(2*arr[1])+arr[0]+arr[2])/3);
            double C=((arr[3]-(2*arr[2])+arr[0]+arr[1])/3);
            if((A-(int)A)!=0||(B-(int)B)!=0||(C-(int)C)!=0)
            System.out.println("NO");
            else
            System.out.println("YES");
        }
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
public class TEMP1
{
    public static void main(String args[])throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int t=Integer.parseInt(br.readLine());
        for(int i=1;i<=t;i++)
        {
            String s=br.readLine();
            String ar[]=s.split(" ");
            double arr[]=new double[4];
            arr[0]=Double.parseDouble(ar[0]);
            arr[1]=Double.parseDouble(ar[1]);
            arr[2]=Double.parseDouble(ar[2]);
            arr[3]=Double.parseDouble(ar[3]);
			double max=Math.max(arr[0],(Math.max(arr[1],arr[2])));
			double min=Math.min(arr[0],(Math.min(arr[1],arr[2])));
			if((max-min)<=arr[3])
			{
	            double A=((arr[3]-(2*arr[0])+arr[1]+arr[2])/3);
	            double B=((arr[3]-(2*arr[1])+arr[0]+arr[2])/3);
	            double C=((arr[3]-(2*arr[2])+arr[0]+arr[1])/3);
				if(A<0||B<0||C<0)
				  System.out.println("NO");
				 else
				 {
					 if((A-(int)A)!=0||(B-(int)B)!=0||(C-(int)C)!=0)
						 System.out.println("NO");
			         else
			         System.out.println("YES");
				 }
			}
			else
			System.out.println("NO");
	    }
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
public class TEMP1
{
    public static void main(String args[])throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int t=Integer.parseInt(br.readLine());
        for(int i=1;i<=t;i++)
        {
            String s=br.readLine();
            String ar[]=s.split(" ");
            double arr[]=new double[4];
            arr[0]=Double.parseDouble(ar[0]);
            arr[1]=Double.parseDouble(ar[1]);
            arr[2]=Double.parseDouble(ar[2]);
            arr[3]=Double.parseDouble(ar[3]);
			double max=Math.max(arr[0],(Math.max(arr[1],arr[2])));
			double min=Math.min(arr[0],(Math.min(arr[1],arr[2])));
		if((max-min)<arr[3])
		{
            double A=((arr[3]-(2*arr[0])+arr[1]+arr[2])/3);
            double B=((arr[3]-(2*arr[1])+arr[0]+arr[2])/3);
            double C=((arr[3]-(2*arr[2])+arr[0]+arr[1])/3);
			if(A<0||B<0||C<0)
			  System.out.println("NO");
			 else
			 {
              if((A-(int)A)!=0||(B-(int)B)!=0||(C-(int)C)!=0)
            System.out.println("NO");
            else
            System.out.println("YES");
        }}
		else
		System.out.println("NO");

    }}
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
public class TEMP1
{
    public static void main(String args[])throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int t=Integer.parseInt(br.readLine());
        for(int i=1;i<=t;i++)
        {
            String s=br.readLine();
            String ar[]=s.split(" ");
            double arr[]=new double[4];
            arr[0]=Double.parseDouble(ar[0]);
            arr[1]=Double.parseDouble(ar[1]);
            arr[2]=Double.parseDouble(ar[2]);
            arr[3]=Double.parseDouble(ar[3]);
			double max=Math.max(arr[0],(Math.max(arr[1],arr[2])));
			double min=Math.min(arr[0],(Math.min(arr[1],arr[2])));
		if((max-min)<arr[3])
	     	{
            double A=((arr[3]-(2*arr[0])+arr[1]+arr[2])/3);
            double B=((arr[3]-(2*arr[1])+arr[0]+arr[2])/3);
            double C=((arr[3]-(2*arr[2])+arr[0]+arr[1])/3);
            if((A-(int)A)!=0||(B-(int)B)!=0||(C-(int)C)!=0)
            System.out.println("NO");
            else
            System.out.println("YES");
            }
		else
		System.out.println("NO");

        }
   }
}