#include<iostream>
#include<queue>
#include<cstring>
#include<vector>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<set>
#include<cstdlib>
#include<stack>
typedef long long LL;
const int maxsize = 1e6+7;
using namespace std;
int Ans[maxsize];
LL D[maxsize];
const int mood = 998244353;
bool Prime[maxsize];
LL PrimeT[maxsize];
int pcnt;
void primeFun(int n)//筛选法构造素数
{
pcnt = 0;
Prime[0] = Prime[1] = 1;
for(int i=2;i*i<=n+1;i++)
{
if(!Prime[i])
{
for(int j=i+i;j<=n;j+=i)
{
Prime[j] = 1;
}
}
}
for(int i=0;i<=n;i++)
{
if(!Prime[i])
{
PrimeT[pcnt++] = i;
//cout<<i<<" ";
}
}
}
int main()
{
//freopen("finput.txt","r",stdin);
primeFun(1e6+1);
int t;
scanf("%d",&t);
while(t--)
{
LL l,r,k;
scanf("%lld%lld%lld",&l,&r,&k);
LL n = r-l+1;
fill(Ans,Ans+n,1);//赋值为1
for(int i=0;i<n;i++)
{
D[i] = l+i;
}
for(int i=0;i<pcnt;i++)
{
LL primenow = PrimeT[i];
LL t = l/primenow;
if(l%primenow) t++;
t *= primenow;
for(LL j=t-l;j<n;j+=primenow)//算法的关键所在,应为是跳着取得,所以只有prime是这个数的因子的时候才进行操作
{
int cnt = 0;
while(D[j]%primenow==0)
{
cnt++;
D[j]/=primenow;
}
Ans[j] = (Ans[j]*(cnt*k+1))%mood;
}
}
LL sum = 0;
for(int i=0;i<n;i++)
{
if(D[i]!=1)//对于大于10^6的整数进行特殊处理
{
Ans[i] = (Ans[i]*(k+1))%mood;
}
//cout<<Ans[i]<<" ";
sum = (sum+Ans[i])%mood;
}
printf("%lld\n",sum);
}
return 0;
}