#include<cstdio> #include<cstdlib> #include<cstring> #include<string> #include<algorithm> #include<iostream> #include<queue> #include<map> #include<cmath> #include<set> #include<stack> #define ll long long #define pb push_back #define max(x,y) ((x)>(y)?(x):(y)) #define min(x,y) ((x)>(y)?(y):(x)) #define cls(name,x) memset(name,x,sizeof(name))//0或-1 #define fs first #define sc second #define mp make_pair #define L(x) (1<<x) #define next Next using namespace std; const int inf=1e9+10; const ll llinf=1e18+10; const int maxn=1e6+10; const int maxm=2e5+10; const int mod=998244353; //const int mod=1e9+7; ll n,k; ll l,r; ll fac[maxn]; ll A[maxn],B[maxn]; void init() { int t=0; bool prime[maxn]; cls(prime,0); for(int i=2;i<maxn;i++) { if(prime[i]==0) { fac[t++]=i; for(int j=2;j*i<maxn;j++) prime[i*j]=1; } } } int main() { //freopen("in.txt","r",stdin); //freopen("wa.txt","w",stdout); init(); int ncas; scanf("%d",&ncas); while(ncas--) { scanf("%lld %lld %lld",&l,&r,&k); for(ll i=l;i<=r;i++) { A[i-l]=1; B[i-l]=i; } for(int i=0;fac[i]*fac[i]<=r;i++) for(ll j=l/fac[i]+(l%fac[i]!=0);j*fac[i]<=r;j++) { ll c=0; while(B[fac[i]*j-l]%fac[i]==0) { B[fac[i]*j-l]/=fac[i]; c++; } A[fac[i]*j-l]=( A[fac[i]*j-l] * ( c*k+1) )%mod; } ll ans=0; for(ll i=l;i<=r;i++) { if(B[i-l]>1) A[i-l]=(A[i-l]*(k+1))%mod; ans=(ans+A[i-l])%mod; } printf("%lld ",ans); } return 0; }