#include <bits/stdc++.h>
using namespace std;

#define int ll
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define F first
#define S second
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

signed main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);
  
  int t; cin >> t;
  while (t--) {
      int n,m;cin>>n>>m;
      vi a(n);rep(i,0,n)cin>>a[i];
      vi b(m);rep(i,0,m)cin>>b[i];
      sort(all(a));
      sort(all(b));
      vi psa(n+1), psb(m+1);
      rep(i,0,n) psa[i+1]=psa[i]+a[i];
      rep(i,0,m) psb[i+1]=psb[i]+b[i];
      set<int> candss;
      for(int x : a) candss.insert(x-1), candss.insert(x), candss.insert(x+1);
      for(int x : b) candss.insert(x-1), candss.insert(x), candss.insert(x+1);
    
      vi cands(all(candss));
      array<vi, 2> dice = {a,b};
      array<int, 2> bnds = {n,m};
      
      int z = sz(cands);
      vector<double> maxs(z+1), mins(z+1);
      // precomp prefix expected max
      {
        array<int, 2> lt={0,0};
        double em = 0;
        rep(i,0,sz(cands)){
          array<int,2> eq={0,0};
          rep(j,0,2){
            while(lt[j] + eq[j] < bnds[j] && dice[j][lt[j]+eq[j]] == cands[i]) eq[j]++;
          }
          if(eq[0] || eq[1]){
            double prob = 0;
            rep(j,0,2)if(eq[j]){
              prob += eq[j] / (double) (eq[j] + lt[j]);
            }
            if(eq[0] && eq[1]){
              prob -= eq[0] * eq[1] / (double)((eq[0]+lt[0])*(eq[1]+lt[1]));
            }
            em = (1 - prob) * em + prob * cands[i];
          }
          rep(j,0,2){
            lt[j] += eq[j];
          }
          maxs[i+1]=em;
        }
      }
      // precomp suffix expected min
      {
        array<int, 2> lt={0,0};
        array<vi,2> dice2 = dice;
        rep(i,0,2)reverse(all(dice2[i]));
        double em = max(a.back(), b.back());
        mins[z]=em;
        for(int i = z-1; i >= 0; i--){
          array<int,2> eq={0,0};
          rep(j,0,2){
            while(lt[j] + eq[j] < bnds[j] && dice2[j][lt[j]+eq[j]] == cands[i]) eq[j]++;
          }
          double prob = 0;
          if(eq[0] || eq[1]){
            rep(j,0,2)if(eq[j]){
              prob += (double) eq[j] / (double) (eq[j] + lt[j]);
              // cerr<<'\t'<<i<<' '<<cands[i]<<' '<<j<<' '<<eq[j]<<' '<<lt[j]<<endl;
            }
            if(eq[0] && eq[1]){
              prob -= (eq[0] * eq[1]) / (double)((eq[0]+lt[0])*(eq[1]+lt[1]));
            }
            em = (1 - prob) * em + prob * cands[i];
          }
          // cerr<<i<<' '<<cands[i]<<' '<<em<<' '<<prob<<endl;
    
          rep(j,0,2){
            lt[j] += eq[j];
          }
          mins[i]=em;
        }
      }
      // rep(i,0,z+1)cout<<i<<' '<<mins[i]<<endl;
      // exit(0);
    
      int lta = 0;
      int ltb = 0;
      double best = 0;
      rep(i,0,z){
        int x = cands[i];
        int eqa = 0;
        int eqb = 0;
        while(lta + eqa < n && a[lta + eqa] == x) eqa++;
        while(ltb + eqb < m && b[ltb + eqb] == x) eqb++;
    
        double score = 0;
    
        { // bottom gain
          double aweight = (2*(n-lta)-eqa)/(double)n;
          double bweight = (2*(m-ltb)-eqb)/(double)m;
          score += bweight * (x * lta - psa[lta]) / (double) n;
          score += aweight * (x * ltb - psb[ltb]) / (double) m;
        }
    
        { // top gain
          double aweight = (2*lta+eqa)/(double)n;
          double bweight = (2*ltb+eqb)/(double)m;
          score += bweight * (psa[n] - psa[lta] - x * (n-lta)) / (double) n;
          score += aweight * (psb[m] - psb[ltb] - x * (m-ltb)) / (double) m;
        }
    
    
        // case x < a, b
        score -= 2 * (mins[i+1]-x) * (n-lta-eqa) * (m-ltb-eqb) / (double)(n*m);
        
        // case a, b < x
        score -= 2 * (x-maxs[i]) * lta * ltb / (double)(n*m);
        // cerr<<x<<' '<<score<<endl;
    
        best=max(best, score);
    
        lta += eqa;
        ltb += eqb;
      }
    
      cout<<fixed<<setprecision(8)<<best<<'\n';
  }
 
}
