#include <iostream>
#include <fstream>

#define ABS(a) ((a)<0?(-(a)):(a))

using namespace std;

void solve(){
	long long K, l, r, c, d;
	int p1, p2, p3;
	cin>>K>>p1>>p2>>p3;
	p2=100-p2;
	l=1;
	r=K-1;
	while(l<r){
		c = l + (r-l)/3;
		d = r - (r-l)/3;
		if(ABS(2*c*p1+2*(K-c)*p2+c*p3 - 100*K) <= ABS(2*d*p1+2*(K-d)*p2+d*p3 - 100*K))
			r = d-1;
		else
			l = c+1;
	}
	cout<<l<<endl;
}

int main(){
	freopen("joust.in","r",stdin);
	int N;
	cin>>N;
	while(N-->0) solve();
	return 0;
}
