llqpow(llx,lln,llmod){llres=1LL;for(x%=mod;n>0LL;n>>=1,x=x*x%mod){if(n&1LL)res=res*x%mod;}return(res+mod)%mod;}// a^x EQUIV n (MOD mod), and gcd(a, mod) = 1
llBSGS(lla,lln,llmod){a%=mod,n%=mod;if(n==1LL||mod==1LL)return0LL;unordered_map<ll,ll>bs;llS=sqrt(mod)+1;llbase=n;for(llk=0,val=base;k<=S;k++){bs[val]=k,val=val*a%mod;}base=qpow(a,S,mod);for(llx=1,val=base;x<=S;x++){if(bs.count(val))returnx*S-bs[val];val=val*base%mod;}return-1;// No solution
}pair<ll,ll>exgcd(lla,llb){boolneg_a=(a<0),neg_b=(b<0);llx=1,y=0,r=0,s=1;while(b!=0LL){llt=a/b;r^=x^=r^=x-=t*r;s^=y^=s^=y-=t*s;b^=a^=b^=a%=b;}return{neg_a?-x:x,neg_b?-y:y};}llinv(lla,llmod){auto[res,_]=exgcd(a,mod);return(res%mod+mod)%mod;}// a^x EQUIV n (MOD mod), and gcd(a, mod) != 1
llexBSGS(lla,lln,llmod){a%=mod,n%=mod;if(n==1LL||mod==1LL)return0LL;llk=0,val=1;for(llg=__gcd(a,mod);g!=1LL;g=__gcd(a,mod)){if(n%g!=0LL)return-1;// No solution
mod/=g,n/=g;val=val*(a/g)%mod,k++;if(val==n)returnk;}llres=BSGS(a,n*inv(val,mod)%mod,mod);return~res?res+k:res;}
#include<bits/stdc++.h>usingnamespacestd;usingll=longlong;#define all(a) begin(a), end(a)
llqpow(llx,lln,llmod){llres=1LL;for(x%=mod;n>0LL;n>>=1,x=x*x%mod){if(n&1LL)res=res*x%mod;}return(res+mod)%mod;}// a^x EQUIV n (MOD mod), and gcd(a, mod) = 1
llBSGS(lla,lln,llmod){a%=mod,n%=mod;if(n==1LL||mod==1LL)return0LL;unordered_map<ll,ll>bs;llS=sqrt(mod)+1;llbase=n;for(llk=0,val=base;k<=S;k++){bs[val]=k,val=val*a%mod;}base=qpow(a,S,mod);for(llx=1,val=base;x<=S;x++){if(bs.count(val))returnx*S-bs[val];val=val*base%mod;}return-1;// No solution
}tuple<ll,ll>exgcd(lla,llb){llx=1,y=0,r=0,s=1;while(b!=0LL){llt=a/b;r^=x^=r^=x-=t*r;s^=y^=s^=y-=t*s;b^=a^=b^=a%=b;}return{a,x};}voidsolve(){lla,b,p;cin>>p>>a>>b;llphi=p-1;// p is a prime number
b%=p,a%=phi;vector<int>fact=[](intn){vector<int>res;for(inti=2;i*i<=n;i++){if(n%i==0){res.push_back(i);while(n%i==0)n/=i;}}if(n!=1)res.push_back(n);returnres;}(phi);llroot=[&fact,&phi](intp){for(llres=2;res<p;res++){boolok=true;for(constll&x:fact){if(qpow(res,phi/x,p)!=1)continue;ok=false;break;}if(ok)returnres;}return-1LL;}(p);llL=BSGS(root,b,p);auto[g,inv]=exgcd(a,phi);/**
* root^log(b) \equiv b (mod p)
*
* a * log(ans) \equiv log(b) (mod phi)
**/if(L%g!=0)returncout<<"No Solution\n",void();a/=g,L/=g;llmod=phi/g;L=(inv*L%mod+mod)%mod;vector<ll>ans;for(;L<phi;L+=mod){ans.push_back(qpow(root,L,p));}sort(all(ans));for(constll&x:ans)cout<<x<<' ';cout<<'\n';}intmain(){cin.tie(nullptr)->sync_with_stdio(false);intT;cin>>T;while(T--)solve();return0;}