import java.util.*; import java.io.*; import java.text.*; //Solution Credits: Taranpreet Singh public class Main{ //SOLUTION BEGIN int BIT = 18; void solve(int TC) throws Exception{ int n = ni(), K = ni(), L = ni(); int[][] g = new int[n][], edge = new int[n-1][];int[] cnt = new int[n]; for(int i = 0; i< n- 1; i++){ edge[i] = new int[]{ni()-1, ni()-1}; cnt[edge[i][0]]++;cnt[edge[i][1]]++; } for(int i = 0; i< n; i++)g[i] = new int[cnt[i]]; for(int i = 0; i< n-1; i++){ g[edge[i][0]][--cnt[edge[i][0]]] = edge[i][1]; g[edge[i][1]][--cnt[edge[i][1]]] = edge[i][0]; } int[][] par = new int[BIT][n];int[] d = new int[n]; //DFS for calculating depth and parent of each node. dfs(g, par, d, 0); //Filling sparse table for Binary Lifting for(int b = 1; b< BIT; b++) for(int i = 0; i< n; i++) if(par[b][i]!=-1) par[b][i] = par[b-1][par[b-1][i]]; int k = 0, l = 0; int[] A = new int[2*K], B = new int[2*L]; for(int i = 0; i< K; i++){ int x = ni()-1; if(i>0){ int lca = lca(par, d, A[k-1], x); //Splitting path of person A into two paths, one going up, other going down. if(lca!=A[k-1] && lca!=x)A[k++] = lca; } A[k++] = x; } for(int i = 0; i< L; i++){ int x = ni()-1; if(i>0){ int lca = lca(par, d, B[l-1], x); //Splitting path of person B into two paths, one going up, other going down. if(lca!=B[l-1] && lca!=x)B[l++] = lca; } B[l++] = x; } if((d[A[0]]+d[B[0]])%2==1){ //If distance between A and B initally is odd, printing 0. pn(0);return; } //Note: //If path is a to b, i will count meeting points at all positions, except a, because it is already counted at previous step. int ca = 1, cb = 1; long ans = (A[0]==B[0]?1:0);//If starting point match. //curA = current position of A, curB = current position of B int curA = A[0], curB = B[0]; //dir: 0 = down, 1 = up //While both persons have path remaining while(cadb){ //Path A split if(dirA==1)nxtA = lift(par, curA, db); else nxtA = lift(par, nxtA, da-db); //B's pointer moved cb++; }else { //Both pointers moved, if no path split. ca++;cb++; } //Distance to be covered at current step int dist = Math.min(da,db); if(dirA != dirB && dist>=Math.abs((d[curA]-d[curB])/2)){ //Opposite direction, the distance to be covered is atleast D/2, condition 1 in editorial if((dirA==0 && d[curA]= d[nxtA])ans+=d[lca]-d[nxtA]+1; //I do not count start vertex, to avoid double-counting if(lca==curA)ans--; }else if(dirA==0 && curA==curB){ //Both moving down int lca = lca(par, d, nxtA, nxtB); //Vertices from current to lca counted, excluding current. ans+=d[lca]-d[curA]; } } //Current positions updated for next step curA = nxtA;curB = nxtB; } //Most important comment, Printed answer XD pn(ans); } int lift(int[][] par, int u, int st){ for(int b = BIT-1; b>=0; b--)if(((st>>b)&1)==1)u=par[b][u]; return u; } void dfs(int[][] g, int[][] par, int[] d, int u){ for(int v:g[u]){ if(v==par[0][u])continue; par[0][v] = u; d[v]=d[u]+1; dfs(g,par,d,v); } } int lca(int[][] par, int[] d, int u, int v){ if(d[u]>d[v]){int t=u;u=v;v=t;} int dif = d[v]-d[u]; for(int b = BIT-1; b>=0; b--)if(((dif>>b)&1)==1)v=par[b][v]; if(u==v)return u; for(int b = BIT-1; b>=0; b--){ if(par[b][u]!=par[b][v]){ u=par[b][u]; v=par[b][v]; } } return par[0][u]; } long mod = (long)1e9+7, IINF = (long)1e17; final int MAX = (int)1e6+1, INF = (int)2e9, root = 3; DecimalFormat df = new DecimalFormat("0.000000000000"); double PI = 3.1415926535897932384626433832792884197169399375105820974944, eps = 1e-8; static boolean multipleTC = true, memory = false; FastReader in;PrintWriter out; void run() throws Exception{ in = new FastReader(); out = new PrintWriter(System.out); int T = (multipleTC)?ni():1; //Solution Credits: Taranpreet Singh for(int i = 1; i<= T; i++)solve(i); out.flush(); out.close(); } public static void main(String[] args) throws Exception{ if(memory)new Thread(null, new Runnable() {public void run(){try{new Main().run();}catch(Exception e){e.printStackTrace();}}}, "1", 1 << 28).start(); else new Main().run(); } long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);} int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);} int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));} void p(Object o){out.print(o);} void pn(Object o){out.println(o);} void pni(Object o){out.println(o);out.flush();} String n(){return in.next();} String nln(){return in.nextLine();} int ni(){return Integer.parseInt(in.next());} long nl(){return Long.parseLong(in.next());} double nd(){return Double.parseDouble(in.next());} class FastReader{ BufferedReader br; StringTokenizer st; public FastReader(){ br = new BufferedReader(new InputStreamReader(System.in)); } public FastReader(String s) throws Exception{ br = new BufferedReader(new FileReader(s)); } String next(){ while (st == null || !st.hasMoreElements()){ try{ st = new StringTokenizer(br.readLine()); }catch (IOException e){ e.printStackTrace(); } } return st.nextToken(); } String nextLine(){ String str = ""; try{ str = br.readLine(); }catch (IOException e){ e.printStackTrace(); } return str; } } }