| 261 | } |
| 262 | |
| 263 | public static void main(String[] args) throws Exception { |
| 264 | FastReader in = new FastReader(System.in); |
| 265 | PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); |
| 266 | t = in.nextInt(); |
| 267 | for (int c = 1; c <= t; c++) { |
| 268 | n = in.nextInt(); |
| 269 | cntt = n << 1; |
| 270 | for (int i = 1; i <= n; i++) { |
| 271 | startTag[i] = i; |
| 272 | endTag[i] = i + n; |
| 273 | } |
| 274 | for (int i = 1, u, v; i < n; i++) { |
| 275 | u = in.nextInt(); |
| 276 | v = in.nextInt(); |
| 277 | addEdge1(u, v); |
| 278 | addEdge1(v, u); |
| 279 | } |
| 280 | // build1(1, 1); |
| 281 | build2(1, 1); |
| 282 | m = in.nextInt(); |
| 283 | for (int i = 1, x, y; i <= m; i++) { |
| 284 | x = in.nextInt(); |
| 285 | y = in.nextInt(); |
| 286 | link(x, y); |
| 287 | } |
| 288 | boolean ans = topo(); |
| 289 | out.println(ans ? "Yes" : "No"); |
| 290 | clear(); |
| 291 | } |
| 292 | out.flush(); |
| 293 | out.close(); |
| 294 | } |
| 295 | |
| 296 | // 读写工具类 |
| 297 | static class FastReader { |