#include <bits/stdc++.h>
using namespace std;
 
#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << (a) << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair
 
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1e9 + 7;
const int N = 2020;


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);

    int n,m; cin >> n >> m;
    int s = 0;
    forn(_,n) {
        int x; cin >> x;
        s += x;
    }

    vi inv(s+n+1);
    inv[1] = 1;
    forsn(x,2,si(inv)) {
        inv[x] = ll(MOD - MOD/x) * inv[MOD%x] % MOD;
        assert(ll(inv[x]) * x % MOD == 1);
    }

    ll ans = 1;
    forn(k,s+n) {
        ans = ans * (m+n-k) % MOD;
        ans = ans * inv[k+1] % MOD;
    }
    cout << ans << endl;

    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 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;
		ll K,F,G=exgcd(p+q,md,K,F);
		for(ll i=x;i<x+y;i++){
			ll b=p,a=p+q,c=((i-b)%md+md)%md;
			ll k=K,f=F,g=G;
			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);
		}
		md=p+q,G=exgcd((x+y)<<1,md,K,F);
		for(ll i=p;i<p+q;i++){
			ll b=x,a=(x+y)<<1,c=((i-b)%md+md)%md;
			ll k=K,f=F,g=G;
			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);
		}
		if(ans>=lim)printf("infinity\n");
		else printf("%lld\n",ans);
	}
	return 0;
}