#include<bits/stdc++.h>
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
using ll = long long;
using namespace std;

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
//main関数内に extGCD(a, b, x, y); でx, yに解が格納
ll extGCD(ll a, ll b, ll& x, ll& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	ll d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

signed main() {
	//input
	ll t; cin >> t;
	rep(zz, t) {
		//n(x) - k(y) = s
		ll n, s, k; cin >> n >> s >> k; ll g = gcd(n, k);
		if (s % g != 0) { cout << "-1\n"; continue; }
		ll x, y; extGCD(n, k, x, y);
		//cout << x << ' ' << y << endl;
		x *= (s / g); y *= (s / g); y = 0 - y;
		k /= g; n /= g;
		if (y > 0) { y -= n * min(x / k, y / n); }
		else { y += n * max((0 - x + k - 1) / k, (0 - y + n - 1) / n); }
		cout << y << endl;
	}
	return 0;
}
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define mod 1000000007
#define ad(a,b) a=(a+b)%mod;
ll po(ll x,ll y){
	ll res=1;
	for(;y;y>>=1){
		if(y&1)res=res*x%mod;
		x=x*x%mod;
	}
	return res;
}
ll gcd(ll a,ll b){
	return (b?gcd(b,a%b):a);
}
#define X 200010
ll fac[X],ivf[X];
void initfac(){
	fac[0]=1;
	for(ll i=1;i<X;i++)fac[i]=fac[i-1]*i%mod;
	for(ll i=0;i<X;i++)ivf[i]=po(fac[i],mod-2);
}
ll C(ll n,ll k){
	return fac[n]*ivf[n-k]%mod*ivf[k]%mod;
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	ll n,p[200010],place[200010];
	cin>>n;
	rep(i,n){
		cin>>p[i]; p[i]--;
		place[p[i]]=i;
	}
	vector<ll> v;
	bool ok=1;
	ll s=0;
	while(1){
		ll i=place[s]-1;
		if(i<s){ok=0;break;}
		for(;i>=s;i--){
			v.push_back(i);
			swap(p[i+1],p[i]);
		}
		s=place[s];
		if(s==n-1)break;
	}
	rep(i,n)ok&=(p[i]==i);
	if(ok){
		rep(i,v.size())cout<<v[i]+1<<"\n";
	}
	else cout<<-1<<endl;
}
