#include <cstdio>

inline int read()
{
	int data = 0, w = 1; char ch = getchar();
	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
	if (ch == '-') w = -1, ch = getchar();
	while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();
	return data * w;
}

const int N(105);
int n, K, M, f[N][N * N * N], s[N];
inline void Add(int &x, int y) { x = (x + y) % M; }

int main()
{
	n = read(), K = read(), M = read(), f[0][0] = 1;
	for (int i = 1; i <= n; i++)
		for (int j = 0; j <= n * n * K; j++)
		{
			Add(s[j % i], f[i - 1][j]);
			if (j >= (K + 1) * i) Add(s[j % i], M - f[i - 1][j - (K + 1) * i]);
			f[i][j] = s[j % i];
		}
	for (int i = 1; i <= n; i++)
	{
		int ans = 0;
		for (int j = 1; j <= n * n * K; j++)
			Add(ans, 1ll * f[i - 1][j] * f[n - i][j] % M);
		printf("%lld\n", (K + 1ll * ans * (K + 1)) % M);
	}
	return 0;
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;

tuple<ll,ll,ll> extgcd(ll a, ll b) {
  if (b == 0) return {a, 1, 0};
  ll g, x, y;
  tie(g,x,y) = extgcd(b, a%b);

  return {g, y, x-a/b*y};
}

void solve() {
  int n, s, k;
  cin >> n >> s >> k;
  ll x,y,g;
  tie(g,x,y) = extgcd(k,n);

  if (s % g != 0) {
    cout << -1 << endl;
    return;
  }
  n /= g;
  s /= g;
  k /= g;
  ll ans = ((x*-s)%n+n)%n;
  cout << ans << endl;
}

int main() {
  int t;
  cin >> t;
  rep(i,t) solve();
  return 0;
}