#include <bits/stdc++.h>
 
#define ll long long
#define maxi(a, b) (a > b ? a : b)
#define mini(a, b) (a < b ? a : b)
#define MOD 1000000007
 
using namespace std;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 
	//freopen("test_input.txt","r",stdin);

	ll t = 1;
	//cin >> t;


	while(t--) {
		
		ll n, q, a, b, c;
		cin >> n >> q;

		set<ll> st;

		for(ll i = 0; i < n; i++) {
			ll e;
			cin >> e;
			st.insert(e);
		}

		vector<ll> lw, num;

		ll prev = 0;
		ll running = 0;

		for(ll e : st) {
			if(e > prev+1) {
				lw.push_back(prev);
				num.push_back(running+e-prev-1);
			}
			running = running+e-prev-1;
			prev = e;
		}

		lw.push_back(prev);
		num.push_back(LONG_LONG_MAX/2);	

		while(q--) {
			ll k;
			cin >> k;

			ll idx = lower_bound(num.begin(), num.end(), k) - num.begin();

			ll temp = idx > 0 ? num[idx-1] : 0;
			ll res = lw[idx] + k-temp;

			//cout << lw[idx] << " " << num[idx] << "\n";

			cout << res << "\n";



		}

		

		

        
	}


 
	return 0;

}
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#define ll long long
#define MAXN 200005
#define uns unsigned
#define MOD 998244353ll
#define INF 0x7f7f7f7f
using namespace std;
inline ll read(){
	ll x=0;bool f=1;char s=getchar();
	while((s<'0'||s>'9')&&s>0){if(s=='-')f^=1;s=getchar();}
	while(s>='0'&&s<='9')x=(x<<1)+(x<<3)+s-'0',s=getchar();
	return f?x:-x;
}
ll x,y,p,q;
inline ll ksm(ll a,ll b,ll mo){
	ll res=1;
	for(;b;b>>=1,a=a*a%mo)if(b&1)res=res*a%mo;
	return res;
}
inline ll gcd(ll a,ll b){
	return b==0?a:gcd(b,a%b);
}
inline ll exgcd(ll a,ll b,ll&x,ll&y){
	if(b==0){x=1,y=0;return a;}
	ll res=exgcd(b,a%b,y,x);
	y-=a/b*x;return res;
}
signed main()
{
	for(int T=read();T--;){
		x=read(),y=read(),p=read(),q=read();
		ll md=(x+y)<<1,lim=md*(p+q)+1,ans=lim;
		for(ll i=x;i<x+y;i++){
			ll b=p,a=p+q,c=((i-b)%md+md)%md;
			ll k,f,g=exgcd(a,md,k,f);
			if(c%g!=0)continue;
			c/=g,k=(k*c%md+md)%md,f=md/g,k%=f;
			a=p+q,b=p;
			if((k*a+b)%md>=x&&(k*a+b)%md<x+y)ans=min(ans,k*a+b);
//			printf("  %lld %lld  %lld  %lld\n",i,k,k*a+b,ans);
		}
		md=p+q;
		for(ll i=p;i<p+q;i++){
			ll b=x,a=(x+y)<<1,c=((i-b)%md+md)%md;
			ll k,f,g=exgcd(a,md,k,f);
			if(c%g!=0)continue;
			c/=g,k=(k*c%md+md)%md,f=md/g,k%=f;
			a=(x+y)<<1,b=x;
			if((k*a+b)%md>=p&&(k*a+b)%md<p+q)ans=min(ans,k*a+b);
//			printf("  %lld %lld  %lld  %lld\n",i,k,k*a+b,ans);
		}
		if(ans>=lim)printf("infinity\n");
		else printf("%lld\n",ans);
	}
	return 0;
}
/*
1
93 5 52 8
292
*/