dp
dp[k][i][j]表示放k个棋子用了i行j列的方法数。
从小到大放,每次必须放在已经放过的行或列上,否则会出现多个纳什均衡点。
转移方式有三种,新放一行,新放一列,放在已经放过的行和列。
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define full(a, b) memset(a, b, sizeof a)
#define FAST_IO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
inline int lowbit(int x){ return x & (-x); }
inline int read(){
int X = 0, w = 0; char ch = 0;
while(!isdigit(ch)) { w |= ch == '-'; ch = getchar(); }
while(isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
return w ? -X : X;
}
inline int gcd(int a, int b){ return b ? gcd(b, a % b) : a; }
inline int lcm(int a, int b){ return a / gcd(a, b) * b; }
template<typename T>
inline T max(T x, T y, T z){ return max(max(x, y), z); }
template<typename T>
inline T min(T x, T y, T z){ return min(min(x, y), z); }
template<typename A, typename B, typename C>
inline A fpow(A x, B p, C lyd){
A ans = 1;
for(; p; p >>= 1, x = 1LL * x * x % lyd)if(p & 1)ans = 1LL * x * ans % lyd;
return ans;
}
const int N = 105;
int _, n, m, p;
ll dp[81*81][81][81];
int main(){
for(_ = read(); _; _ --){
n = read(), m = read(), p = read();
full(dp, 0);
dp[1][1][1] = n * m;
for(int k = 2; k <= n * m; k ++){
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= m; j ++){
if(k > i * j) continue;
dp[k][i][j] += 1LL * dp[k - 1][i - 1][j] * j % p * (n - i + 1) % p;
dp[k][i][j] += 1LL * dp[k - 1][i][j - 1] * i % p * (m - j + 1) % p;
dp[k][i][j] += 1LL * dp[k - 1][i][j] % p * (i * j - k + 1) % p;
}
}
}
printf("%lld\n", dp[n*m][n][m]);
}
return 0;
}