#LCA0000015. Tổ tiên trên cây Fibonacci (Fibonacci)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tổ tiên trên cây Fibonacci (Fibonacci)
Fibonacci
Source: Luogu
Version: Phuoc Hung OJ Extended
Problem Statement
A breeder observes that rabbit pairs reproduce according to the Fibonacci model: starting in their second month, each pair gives birth to one new pair at the beginning of every month, and no pair ever disappears.
Rabbit pairs are numbered in order of birth, starting from . When several pairs are born simultaneously, the offspring of the pair with a smaller label receives the smaller label. All pairs descend from pair , forming a rooted family tree.
For each pair of labels , find their lowest common ancestor. Every pair is considered an ancestor of itself.
Input
- The first line contains the number of queries .
- Each of the next lines contains positive integers .
Output
Print the lowest common ancestor label on one line per query.
Subtasks
- Subtask 1 (20 points): ; ; ; .
- Subtask 2 (30 points): ; ; ; .
- Subtask 3 (50 points): ; .
Examples
Input
3
5 7
1 2
6 6
Output
2
1
6
Explanation
For , the parent chain of reaches and the chain of also reaches ; their lowest common ancestor is . Identical vertices have themselves as LCA.