1 #include <iostream>
2 #include <cstdio>
3 #include <cstring>
4 #include <cmath>
5 #include <algorithm>
6 #include <climits>
7 #include <vector>
8 #include <queue>
9 #include <cstdlib>
10 #include <string>
11 #include <set>
12 #include <stack>
13 #define LL long long
14 #define pii pair<int,int>
15 #define INF 0x3f3f3f3f
16 using namespace std;
17 const int maxn = 55;
18 double dp[maxn][maxn][maxn*maxn];
19 int main() {
20 int t,n,m;
21 scanf("%d",&t);
22 while(t--){
23 scanf("%d %d",&n,&m);
24 memset(dp,0,sizeof(dp));
25 dp[0][0][0] = 1;
26 for(int i = 1; i <= n; ++i){
27 for(int j = 1; j <= m; ++j){
28 for(int k = max(i,j);k <= i*j; ++k){
29 double p1 = dp[i][j][k-1]*(i*j - k + 1);//行列覆盖都不增加
30 double p2 = dp[i-1][j][k-1]*(n-i+1)*j;//增加行
31 double p3 = dp[i][j-1][k-1]*i*(m - j + 1);//增加列
32 double p4 = dp[i-1][j-1][k-1]*(n - i + 1)*(m - j + 1);//既增加行 又增加列
33 dp[i][j][k] = (p1 + p2 + p3 + p4)/(n*m - k + 1);
34 }
35 }
36 }
37 double ans = 0;
38 for(int i = max(n,m); i <= n*m; ++i)
39 ans += dp[n][m][i]*i - dp[n][m][i-1]*i;
40 printf("%.9f\n",ans);
41 }
42 return 0;
43 }