#include <bits/stdc++.h>
using namespace std;
using gg = long long;
// MAX
// constexpr gg MAX = 25;
constexpr gg MAX = 1e6 + 5;
constexpr gg mod = 998244353;
constexpr gg INF = 2e18;
constexpr double thre = 1e-7;
gg ti, ni, mi, ki, di, pi, xi, yi;
//返回a^b%m
gg powMod(gg a, gg b, gg m) {
    if (m == 1) {
        return 0;
    }
    a %= m;
    gg ans = 1;
    while (b > 0) {
        if (b & 1)
            ans = ans * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return ans;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> ni >> mi >> ki;
    if (ni == 1 or mi == 1) {
        cout << powMod(ki, max(ni, mi), mod) << "\n";
        return 0;
    }
    gg ans = 0;
    for (gg x = 1; x <= ki; ++x) {
        ans = (ans + (powMod(x, ni, mod) - powMod(x - 1, ni, mod) + mod) % mod *
                         powMod(ki - x + 1, mi, mod) % mod) %
              mod;
    }
    cout << ans;
    return 0;
}
#include <bits/stdc++.h>
#define ll long long
#define V vector<long long>
#define VV vector<vector<long long>>
#define VVV vector<vector<vector<long long>>>
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0;(i)<(n);++(i))
#define per(i,n) for(ll (i)=(n)-1;(i)>=0;--(i))
#define inf 9223372036854775807
#ifdef LOCAL
#define debug(x) cerr<<__LINE__<<": "<<#x<<"="<<x<<endl;
#define debugALL(x) cerr<<__LINE__<<": "<<#x<<"=";for(auto i=(x).begin();i!=--(x).end();i++)cerr<<*i<<" ";cerr<<*--(x).end()<<endl;
#else
#define debug(x) true
#define debugALL(x) true
#endif
using namespace std;

inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}

// 拡張 Euclid の互除法
// ap + bq = gcd(a, b) となる (p, q) を求め、d = gcd(a, b) をリターンします
long long extGcd(long long a, long long b, long long &p, long long &q) {  
    if (b == 0) { p = 1; q = 0; return a; }  
    long long d = extGcd(b, a%b, q, p);  
    q -= a/b * p;  
    return d;  
}

// 中国剰余定理
// リターン値を (r, m) とすると解は x ≡ r (mod. m)
// 解なしの場合は (0, -1) をリターン
pair<long long, long long> ChineseRem(long long b1, long long m1, long long b2, long long m2) {
  long long p, q;
  long long d = extGcd(m1, m2, p, q); // p is inv of m1/d (mod. m2/d)
  if ((b2 - b1) % d != 0) return make_pair(0, -1);
  long long m = m1 * (m2/d); // lcm of (m1, m2)
  long long tmp = (b2 - b1) / d * p % (m2/d);
  long long r = mod(b1 + m1 * tmp, m);
  return make_pair(r, m);
}

int main(){
    ll t;
    cin>>t;
    rep(i,t){
        ll x,y,p,q;
        cin>>x>>y>>p>>q;
        ll c=2*x+2*y;
        ll d=p+q;
        ll ans=inf;
        rep(i,y){
            rep(j,q){
                ll a=x+i;
                ll b=p+j;
                auto p=ChineseRem(a,c,b,d);
                if(p.second!=-1)ans=min(ans,p.first);
            }
        }
        if(ans==inf)cout<<"infinity"<<endl;
        else cout<<ans<<endl;
    }
}
