PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#LCA0000081. Đếm số hành trình qua từng con đường (Fools and Roads)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đếm số hành trình qua từng con đường (Fools and Roads)

Fools and Roads

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn cities connected by n−1n-1 bidirectional roads that form a tree. Each of kk journeys travels along the unique simple path from city aa to city bb. For every road, count the journeys that use it. Roads retain their input order.

Input

First line: nn. Next n−1n-1 lines: u,vu,v. Then integer kk, followed by kk lines a,ba,b.

Output

Print n−1n-1 integers in the same order as the input edges.

Subtasks

  • Subtask 1 (20 points): 2≤n≤352\le n\le 35; 0≤k≤350\le k\le 35; 1≤u,v,a,b≤n1\le u,v,a,b\le n; u≠vu\ne v for every edge; edges form a tree vô hướng.

  • Subtask 2 (30 points): 2≤n≤12002\le n\le 1200; 0≤k≤12000\le k\le 1200; 1≤u,v,a,b≤n1\le u,v,a,b\le n; u≠vu\ne v for every edge; edges form a tree vô hướng.

  • Subtask 3 (50 points): 2≤n≤1000002\le n\le 100000; 0≤k≤1000000\le k\le 100000; 1≤u,v,a,b≤n1\le u,v,a,b\le n; u≠vu\ne v for every edge; edges form a tree vô hướng.

Examples

Input

5
1 2
1 3
2 4
2 5
2
1 4
3 5

Output

2 1 1 1

Explanation

Path 1→41\to4 uses roads 1,31,3; path 3→53\to5 uses roads 2,1,42,1,4. Road 11 is used twice.