#include<bits/stdc++.h>
using namespace std;
#define go(i,a,b) for(int i=a;i<=b;++i)
#define int long long
typedef long long ll;
const int N=1e5+10;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[1<<21],*p1=buf,*p2=buf;
int n,m,mod,jc[N],inv[N];
template<typename T> inline void read(T &x){
x=0;char f=1,c=getchar();
while(!isdigit(c)){ if(c=='-') f=-1; c=getchar(); }
while(isdigit(c)){ x=x*10+c-'0'; c=getchar(); }
x*=f;
}
int qpow(int x,int p){
int ans=1;
for(;p;p>>=1){
if(p&1) ans=ans*x%mod;
x=x*x%mod;
}
return ans;
}
int C(int n,int m){
if(m>n) return 0;
return jc[n]*inv[m]%mod*inv[n-m]%mod;
}
int lucas(int n,int m){
if(!m) return 1;
return lucas(n/mod,m/mod)*C(n%mod,m%mod)%mod;
}
signed main(){
//freopen("input.txt","r",stdin);
int T;read(T);
jc[0]=1;inv[0]=1;
while(T--){
read(n),read(m),read(mod);
go(i,1,mod){
jc[i]=jc[i-1]*i%mod;
inv[i]=qpow(jc[i],mod-2);
}
cout<<lucas(n+m,m)<<endl;
}
return 0;
}