#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <string>

#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    int temp;
    ll sum=0;
    rep(i,N) cin >> A[i];
    rep(i,N){
        cin >> temp;
        sum += A[i]*temp;
    }
    if(sum==0) cout << "Yes" << endl;
    else cout << "No" << endl;
}
#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i, n) _rep2(i, 0, n)
#define _rep2(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using i64 = long long;
template<class T>
bool chmin(T& a, const T& b) { return (b < a) ? (a = b, true) : false; }
template<class T>
bool chmax(T& a, const T& b) { return (b > a) ? (a = b, true) : false; }

template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(vector<T>&v){stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v){if(v.size())o<<join(v);return o;}
template<typename T>string join(vector<vector<T>>&vv){string s="\n";rep(i,vv.size())s+=join(vv[i])+"\n";return s;}
template<typename T>ostream& operator<<(ostream&o,vector<vector<T>>&vv){if(vv.size())o<<join(vv);return o;}

long long gcdsolve(long long a, long long b, long long &x, long long &y)
{
    if(b == 0)
    {
        x = 1;
        y = 0;
        return a;
    }
    long long d = gcdsolve(b, a % b, y, x);
    y -= a / b * x;
    return d;
}

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        i64 ans = LLONG_MAX / 2;
        i64 x, y, p, q;
        cin >> x >> y >> p >> q;
        rep(i, y)
        {
            rep(j, q)
            {
                i64 n, m;
                i64 c = p - x - i + j;
                i64 a = 2 * (x + y);
                i64 b = -(p + q);
                auto d = gcdsolve(a, b, n, m);
                if(c % d) continue;
                a /= d;
                b /= d;
                m *= (c / d);
                auto u = m % a;
                if (u < 0)
                {
                    if(a < 0) u -= a;
                    else u += a;
                }
                i64 v = ((p + q) * u + p + j);
                chmin(ans, v);
            }
        }
        cout << (ans != (LLONG_MAX / 2)? to_string(ans): "infinity") << endl;
    }
}