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

#define ll long long int
#define absdiff(a,b) (a>b)?a-b:b-a
#define mp make_pair 
#define pb push_back
#define ff first
#define ss second
#define fast  ios_base::sync_with_stdio(false);cin.tie(0);
const ll MOD = 1000000007;
const ll ll_MAX = 1e15;
ll fast_expo(ll x,ll p){
  if(p==0) return 1;
  else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} 
  else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
ll invMod(ll num){
  return fast_expo(num, MOD - 2)%MOD;
}

const ll N = 3e3 + 5;
ll dp[N][N], pre[N], sum[N][N];

int main(){
  fast
  #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
  #endif

  ll t_c; t_c = 1;
  // cin >> t_c;

  for(ll t_i = 0; t_i < t_c; ++t_i){
    ll n; cin >> n;
    ll arr[n + 1]{};
    for(ll i = 1; i <= n; ++i){
      cin >> arr[i];
      pre[i] = pre[i - 1] + arr[i];
    }

    dp[0][0] = 1;
    sum[0][0] = 1;

    for(ll i = 1; i <= n; ++i){
      for(ll j = n; j > 0; --j){
        dp[i][j] = sum[j - 1][pre[i]%j];
        sum[j][pre[i]%(j + 1)] = (sum[j][pre[i]%(j + 1)] + dp[i][j])%MOD;
      }
    }

    ll ans = 0;
    for(ll i = 1; i <= n; ++i){
      ans = (ans + dp[n][i])%MOD;
    }
    cout << ans << endl;
  }
  return 0;
}

#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

using namespace std;

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}
template <class Con>
string concat(const Con &c, const string &spr){
	stringstream ss;
	typename Con::const_iterator it = c.begin(), en = c.end();
	bool fst = true;
	for(; it != en; ++it){
		if(!fst){ ss << spr; }
		fst = false;
		ss << *it;
	}
	return ss.str();
}

template <class Con, class Fun>
vector<typename Con::value_type> cfilter(const Con &c, Fun f) {
	vector<typename Con::value_type> ret;
	typename Con::const_iterator it = c.begin(), en = c.end();
	for(; it != en; ++it){
		if(f(*it)){
			ret.emplace_back(*it);
		}
	}
	return ret;
}
#if __cplusplus >= 201103L
template <class Con, class Fun>
auto cmap(const Con &c, Fun f) -> vector<decltype(f(*c.begin()))> {
	vector<decltype(f(*c.begin()))> ret;
	ret.reserve(c.size());
	for(const auto &x: c){
		ret.emplace_back(f(x));
	}
	return ret;
}
#endif

#if __cplusplus >= 201402L
#define lambda(e) ([&](const auto &_){ return (e); })
#define lambda2(e) ([&](const auto &_a, const auto &_b){ return (e); })
#endif


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()
#define tget(t,i) get<i>(t)

#define MOD 1000000007LL
#define EPS 1e-8

LL extgcd(LL a, LL b, LL &x, LL &y){
	LL d = a;
	if(b){ d = extgcd(b, a % b, y, x); y -= a / b * x; }
	else{ x = 1; y = 0; }
	return d;
}
LL modinv(LL a, LL m = MOD){
	LL x, y; extgcd(a, m, x, y); return (m + x % m) % m;
}


LL gcd(LL x, LL y){
	while(y){
		LL r = x % y;
		x = y;
		y = r;
	}
	return x;
}

// a * x = b (mod m)
pair<LL,LL> linear_congruence(
	const vector<LL> &va,
	const vector<LL> &vb,
	const vector<LL> &vm
){
	LL x = 0, m = 1;
	for(size_t i = 0; i < va.size(); ++i){
		LL a = va[i] * m;
		LL b = vb[i] - va[i] * x;
		LL d = gcd(vm[i], a);
		if(b % d != 0){
			return make_pair(0, -1); // NA
		}
		LL t = b / d * modinv(a / d, vm[i] / d) % (vm[i] / d);
		x = x + m * t;
		m *= vm[i] / d;
	}
	x = (x % m + m) % m;
	return make_pair(x, m);
}

LL solve(){
	LL x, y, p, q;
	cin >> x >> y >> p >> q;

	LL ans = LLONG_MAX;
	vector<LL> va, vb, vm;
	for(LL i = 0; i < y; ++i)
	for(LL j = 0; j < q; ++j){
		va = {1, 1};
		vb = {x + i, p + j};
		vm = {2 * (x + y), p + q};
		
		auto r = linear_congruence(va, vb, vm);
		if(r.second != -1){
			chmin(ans, r.first);
		}
	}
	return ans;
}

void mainmain(){
	int t;
	for(cin >> t; t--; ){
		LL ans = solve();
		if(ans == LLONG_MAX){ cout << "infinity\n"; }
		else{ cout << ans << '\n'; }
	}
}



}
int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
