#include #include #include using namespace std; bool vis[2<<17]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T;cin>>T; for(;T--;) { int K,M,N; cin>>K>>M>>N; for(int i=0;iA; for(int i=0;icur; cur.push_back(i); while(true) { int u=cur.back(); vis[u]=true; u=(u+M-1)%K; if(vis[u])break; cur.push_back(u); } for(int j=0;j+1