推式子
题目给了唯一分解: ,所以我们枚举
最终:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T>
void out(T x) { cout << x << endl; }
ll fast_pow(ll a, ll b, ll p) {ll c = 1; while(b) { if(b & 1) c = c * a % p; a = a * a % p; b >>= 1;} return c;}
ll exgcd(ll a, ll b, ll &x, ll &y) { if(!b) {x = 1; y = 0; return a; } ll gcd = exgcd(b, a % b, y, x); y-= a / b * x; return gcd; }
const ll mod = 998244353;
int main()
{
ios::sync_with_stdio(false);
int t;
cin >> t;
while(t --)
{
int m;
cin >> m;
ll ans = 1;
for(int i = 0; i < m; i ++)
{
ll p, q;
cin >> p >> q;
ll dd = fast_pow(p, q - 1, mod);
ans = (ans * dd % mod * (p * (q + 1) % mod - q + mod) % mod) % mod;
}
cout << ans << endl;
}
//system("pause");
}