for (int t = 1; t <= n; t++) { for (int a = 0; a <= t; a++) for (int b = 0; b <= t; b++) for (int c = 0; c <= t; c++) for (int d = 0; d <= t; d++) dp[a][b][c][d][t & 1] = 0; for (int a = 0; a <= t; a++) for (int b = 0; b <= t; b++) for (int c = 0; c <= t; c++) for (int d = 0; d <= t; d++) { dp[t + 1][b][c][d][t & 1] += dp[a][b][c][d][t ^ 1]; dp[a][t + 1][c][d][t & 1] += dp[a][b][c][d][t ^ 1]; dp[a][b][t + 1][d][t & 1] += dp[a][b][c][d][t ^ 1]; dp[a][b][c][t + 1][t & 1] += dp[a][b][c][d][t ^ 1]; } }
dp[0][0][0][0] = 1; int cur = 1; int last = 0; for (int i = 1; i <= n; i++) for (int x = 0; x <= i; x++) for (int y = 0; y <= x; y++) for (int z = 0; z <= y; z++) dp[x][y][z][cur] = 0; for (int x = 0; x < i; x++) for (int y = 0; y <= x; y++) for (int z = 0; z <= y; z++) { dp[x][y][z][cur] += dp[x][y][z][last]; dp[i - 1][y][z][cur] += dp[x][y][z][last]; dp[i - 1][x][z][cur] += dp[x][y][z][last]; dp[i - 1][x][y][cur] += dp[x][y][z][last];
intmain() { #ifdef ACM_LOCAL freopen("./in.txt", "r", stdin); freopen("./out.txt", "w", stdout); #endif ios::sync_with_stdio(false); int t; cin >> t; while (t--) { int n, m; cin >> n >> m; int a, b, c; for (int i = 0; i < MAXN; i++) { conditions[i].clear(); } for (int i = 0; i < m; i++) { cin >> a >> b >> c; conditions[b].push_back(Conditions(a, c)); // 要求按照 r 的不同来保存 } dp[0][0][0][0] = 1; int cur = 1; int last = 0; for (int i = 1; i <= n; i++) { for (int x = 0; x <= i; x++) { for (int y = 0; y <= x; y++) { for (int z = 0; z <= y; z++) { dp[x][y][z][cur] = 0; } } } for (int x = 0; x < i; x++) { for (int y = 0; y <= x; y++) { for (int z = 0; z <= y; z++) { dp[x][y][z][cur] += dp[x][y][z][last]; dp[i - 1][y][z][cur] += dp[x][y][z][last]; dp[i - 1][x][z][cur] += dp[x][y][z][last]; dp[i - 1][x][y][cur] += dp[x][y][z][last];
dp[x][y][z][cur] %= mod; dp[i - 1][y][z][cur] %= mod; dp[i - 1][x][z][cur] %= mod; dp[i - 1][x][y][cur] %= mod; } } } for (int s = 0; s < conditions[i].size(); s++) { for (int x = 0; x < i; x++) { for (int y = 0; y <= x; y++) { for (int z = 0; z <= y; z++) { int cnt = 1 + (x >= conditions[i][s].l ? 1 : 0) + (y >= conditions[i][s].l ? 1 : 0) + (z >= conditions[i][s].l ? 1 : 0); // 判断剩下三个位置是否满足条件 if (cnt != conditions[i][s].x) dp[x][y][z][cur] = 0; } } } } swap(cur, last); } longlong ans = 0; // 求算最终答案。需要把所有的情况都加起来 for (int x = 0; x < n; x++) { for (int y = 0; y <= x; y++) { for (int z = 0; z <= y; z++) { ans += dp[x][y][z][last]; ans %= mod; } } } cout << ans << endl; } return0; }