Problem: Berland Government decided to improve relations with neighboring countries. First of all, it was decided to build new roads so that from each city of Berland and neighboring countries it became possible to reach all the others. There are n cities in Berland and neighboring countries in total and exactly n - 1 two-way roads. Because of the recent financial crisis, the Berland Government is strongly pressed for money, so to build a new road it has to close some of the existing ones. Every day it is possible to close one existing road and immediately build a new one. Your task is to determine how many days would be needed to rebuild roads so that from each city it became possible to reach all the others, and to draw a plan of closure of old roads and building of new ones.

Input

The first line contains integer n (2 ≤ n ≤ 1000) — amount of cities in Berland and neighboring countries. Next n - 1 lines contain the description of roads. Each road is described by two space-separated integers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — pair of cities, which the road connects. It can't be more than one road between a pair of cities. No road connects the city with itself.

Output

Output the answer, number t — what is the least amount of days needed to rebuild roads so that from each city it became possible to reach all the others. Then output t lines — the plan of closure of old roads and building of new ones. Each line should describe one day in the format i j u v — it means that road between cities i and j became closed and a new road between cities u and v is built. Cities are numbered from 1. If the answer is not unique, output any.

Examples

Input

2
1 2


Output

0


Input

7
1 2
2 3
3 1
4 5
5 6
6 7


Output

1
3 1 3 7

Solution (in PYTHON3):

Solution:
import sys
from array import array  # noqa: F401


def input():
    return sys.stdin.buffer.readline().decode('utf-8')


n = int(input())
adj = [[] for _ in range(n)]
deg = [0] * n

for u, v in (map(int, input().split()) for _ in range(n - 1)):
    adj[u - 1].append(v - 1)
    adj[v - 1].append(u - 1)
    deg[u - 1] += 1
    deg[v - 1] += 1

groups = []
remove_edge = []
visited = [0] * n
visited2 = [0] * n


def dfs(stack: list):
    while stack:
        v = stack.pop()
        deg[v] = 0
        visited2[v] = 1
        for dest in adj[v]:
            if not deg[dest]:
                continue
            deg[dest] -= 1
            if deg[dest] == 1:
                stack.append(dest)


for i in range(n):
    if visited[i]:
        continue
    visited[i] = 1
    groups.append(i + 1)
    vs = [i]
    stack = [i]
    nstack = []

    while stack:
        v = stack.pop()
        if deg[v] <= 1:
            nstack.append(v)
        for dest in adj[v]:
            if not visited[dest]:
                visited[dest] = 1
                stack.append(dest)
                vs.append(dest)

    dfs(nstack)

    vs = [v for v in vs if not visited2[v]]

    while vs:
        u, v = vs[-1], [x for x in adj[vs[-1]] if not visited2[x]][0]
        adj[u].remove(v)
        adj[v].remove(u)
        deg[u] -= 1
        deg[v] -= 1
        remove_edge.append(f'{u+1} {v+1} ')
        if deg[u] == 1:
            nstack.append(u)
        if deg[v] == 1:
            nstack.append(v)

        dfs(nstack)
        vs = [v for v in vs if not visited2[v]]


ans = []
for i, s in enumerate(remove_edge):
    ans.append(s + f'{groups[i]} {groups[i+1]}')

sys.stdout.buffer.write((str(len(ans)) + '\n' + '\n'.join(ans)).encode('utf-8'))