#include using namespace std ; typedef long long ll ; typedef unsigned long long ull ; typedef pair < int , int > pii ; typedef vector < int > vi ; #define fi first #define se second mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); #define rep(i, a, b) for(int i = a; i < (b); ++i) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() const int MOD = 998244353 ; ll fastpow ( ll x , ll pw ) { ll ret = 1 ; while ( pw > 0 ) { if ( ( pw % 2 ) == 0 ) { x = ( x * x ) % MOD ; pw /= 2 ; } else { ret = ( ret * x ) % MOD ; -- pw ; } } return ret ; } void solve ( ) { int n , k ; cin >> n >> k ; ll ans = 0 ; for ( int i = 2 ; i <= k + 1 ; ++ i ) { ans = ( ans + fastpow ( i , n ) ) % MOD ; } cout << ans << "\n" ; } int main ( ) { ios_base :: sync_with_stdio ( false ) ; cin.tie ( NULL ) ; int t = 1 ; cin >> t ; while ( t -- ) { solve ( ) ; } return 0 ; }