思路:

#define ll  long long
const ll m = 998244353;
ll fast_pow(ll a, ll b) {
	a %= m;
	ll res = 1;
	while(b) {
		if(b & 1) res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}

ll work(ll a, ll b, ll c, ll d) {
	ll x = gcd(a, c);
	if(x == 1 || b == 0 || d == 0) return 1;
	if(b > d) swap(a, c), swap(b, d);
	return fast_pow(x, b) * work(a / x, b, x, d - b) % m;
}

signed main() {
	int t; cin >> t;
	while(t--) {
		ll a, b, c, d; cin >> a >> b >> c >> d;
		cout << work(a, b, c, d) << endl;
	}
}