#include<bits/stdc++.h>
using namespace std;

inline int read(){
	int n=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-') f=-1;ch=getchar();}
	while(isdigit(ch)){n=n*10+ch-'0';ch=getchar();}
	return n*f;
}
const int N=2e6+10,SUM=4;
int T,n,m,k;
int a[N],lst[N],lst1[N];
int stk[SUM][N],tp[SUM],down[SUM];
void solve(){
	n=read(),m=read(),k=read();
	for(int i=1;i<=n;i++){
		a[i]=read();
		if(!lst[a[i]]){
			lst[a[i]]=i;
		}
		if(!lst1[a[i]]&&lst[a[i]]){
			lst1[a[i]]=lst[a[i]];
		}
	}
	int op=rand()%(m*2)+m;
	op%=(2*m);
	cout<<op<<endl;
}
int main(){	
	freopen("meow.in","r",stdin);
	freopen("meow.out","w",stdout);
	srand(time(NULL));
	T=read();
	while(T--) solve();
	return 0;
}
/*
1
2 4 2
1 2 1 2
*/