//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int,int>;
using PL = pair<ll,ll>;
using PPL = pair<pair<ll,ll>,ll>;
#define INF 1000000000
#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define repp(i, n, s) for (int i = (int)(n); i >= (int)(s); i--)
#define mp make_pair
#define tp make_tuple
#define ALL(vec) vec.begin(), vec.end()

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll INFLL = numeric_limits<ll>::max();
    ll t;cin>>t;
    rep(_,0,t){
        ll x,y,p,q;cin>>x>>y>>p>>q;
        ll mod1 = (2*x+2*y)%(p+q);
        ll ans = INFLL;
        
        rep(i,x,x+y){
            if (mod1==0 && p<=i%(p+q) && i%(p+q) <p+q){
                ans = min(ans, (ll)i);
                continue;
            }
            rep(j,p,p+q){
                ll num = i%(p+q);
                ll num2 = j%(p+q);
                ll num3 = (num2-num+p+q)%(p+q);

                ll d = __gcd(__gcd((ll)num3,mod1),p+q);
                ll mod3 = mod1 / d;
                num3/=d;
                ll mod2 = (p+q)/d;
                if (__gcd(mod3,mod2)==1){
                    ll a1 = modinv(mod3, mod2);
                    ans = min(ans, (a1*num3)%mod2*(2*x+2*y)+i);
                }
            }
        }
        if (ans==INFLL){
            cout<<"infinity"<<endl;
            continue;
        }
        cout<<ans<<endl;
    }
}
/**
 * author : cuber_coder
 * created : 09/05/2021 19:43:08
 **/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"

void Solve() {
    int k, n, m;
    cin >> k >> n >> m;
    vector<int> a(k);
    for (auto &i : a) {
        cin >> i;
    }
    set<pair<long double, int>> b;
    for (int i = 0; i < k; i++) {
        long double val = 1.0 * a[i] * m / n;
        a[i] = (a[i] * m) / n;
        b.insert({val - a[i], i});
    }
    m -= accumulate(begin(a), end(a), 0LL);
    for (int i = 0; i < m; i++) {
        int idx = (*b.rbegin()).second;
        b.erase(*b.rbegin());
        a[idx] += 1;
    }
    for (auto i : a) cout << i << " ";
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int testcases = 1;
    // cin >> testcases;

    for (int i = 1; i <= testcases; i++) {
        Solve();
    }
    return 0;
}