#include #include #include #include #include #include #include #include #include #include #define LL long long #define pii pair #define piii pair #define xx first #define yy second //#define ls rt << 1 //#define rs rt << 1 | 1 #define lson ls, l, m #define rson rs, m + 1, r #define pdi pair using namespace std; const int N = 110000, mod = 1e9 + 7; int T[N], num[N], san[N], ls[N*20], rs[N*20], sum[N*20], l[N], r[N], a[N]; pii res[N]; int tot,rt, nn, cc; //int n, m; inline int read() { int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int head[N]; struct edge { int v, nx; edge (int v = 0, int nx = 0) : v (v) , nx (nx) {} } e[N * 2]; void add (int u, int v) { // cout <>1; Build(l,m,ls[rt]); Build(m+1,r,rs[rt]); } void Update(int last,int p,int l,int r,int &rt) { rt=++tot; ls[rt]=ls[last]; rs[rt]=rs[last]; sum[rt]=sum[last]+1; if(l==r) return ; int m=(l+r)>>1; if(p<=m) Update(ls[last],p,l,m,ls[rt]); else Update(rs[last],p,m+1,r,rs[rt]); } int Query(int ss,int tt,int l,int r,int k) { if(l==r) return l; int m=(l+r)>>1; int cnt=sum[ls[tt]]-sum[ls[ss]]; if(k<=cnt) return Query(ls[ss],ls[tt],l,m,k); else return Query(rs[ss],rs[tt],m+1,r,k-cnt); } void gogogo() { // int l,r,k; // for(int i=1;i<=n;i++) // { // scanf("%d",&num[i]); // san[i]=num[i]; // } tot=0; sort(san+1,san+nn+1); // for (int i = 1; i <= nn; i++) cout << san[i] << endl; int cnt=std::unique(san+1,san+nn+1)-san-1; Build(1,cnt,T[0]); for(int i=1;i<=nn;i++) num[i]=std::lower_bound(san+1,san+cnt+1,num[i])-san; for(int i=1;i<=nn;i++) Update(T[i-1],num[i],1,cnt,T[i]); for (int i = 1; i <= nn; i++) { if (sz[i] & 1) res[i] = pii (san[Query(T[l[i]-1],T[r[i]],1,cnt,sz[i] / 2 + 1 )], 0); else { int tmp = san[Query(T[l[i]-1],T[r[i]],1,cnt,sz[i] / 2)] + san[Query(T[l[i]-1],T[r[i]],1,cnt,sz[i] / 2 + 1 )]; res[i] = pii (tmp / 2, tmp & 1); } } // while(m--) // { // scanf("%d%d%d",&l,&r,&k); // int id=Query(T[l-1],T[r],1,cnt,k); // printf("%d\n",san[id]); // } } int main () { // freopen ("in.txt", "r", stdin); int T; cin >> T; while (T--) { int n, m, u, v, x; cin >> n >> m; cc = nn = 0; for (int i = 1; i <= n; i++) { a[i] = read (); } memset (head, -1, sizeof head); tot = 0; for (int i = 1; i < n; i++) { u = read (); v = read (); // cout << u << ' ' << v << endl; add (u, v); add (v, u); } dfs (1, 0); gogogo (); pii ans = pii (0, 0); while (m--) { x = read (); ans.xx *= 10; if (ans.yy) ans.yy = 0, ans.xx += 5; // cout << res[x].xx << ' ' << res[x].yy << endl; ans.xx += res[x].xx; ans.yy += res[x].yy; ans.xx %= mod; } cout << ans.xx; if (ans.yy) cout << ".5"; else cout << ".0"; cout << endl; } }