def solve():
    n, m = map(int, input().split())
    dp = [0] * (m + 1)
    mod = 998244353
    for i in range(m, 0, -1):
        dp[i] = pow(m // i, n, mod)
        for j in range(2 * i, m + 1, i):
            dp[i] -= dp[j]
            dp[i] %= mod
    print(dp[1])

def main():
    t = int(input())
    for _ in range(t):
        solve()

if __name__ == '__main__':
    main()

