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:
# Link: http://codeforces.com/contest/25/problem/D

import os
import sys
import math
import itertools
from io import BytesIO, IOBase

#<fast I/O>
BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
#</fast I/O>

#<template>
mod=(10**9)+7
pi=3.14159265358979323846264338327950

def i1():   #int(input())
    return int(sys.stdin.readline())

def sf():   #input()
    return sys.stdin.readline()

def mi():   #map(int(input()))
    return map(int,sys.stdin.readline().split())

def arr():  #list(map(int,input().split()))
    return list(map(int,sys.stdin.readline().split()))

def pf(ans): #print(x)
    return sys.stdout.write(str(ans)+"\n")

def gcd(a,b):
    if a==0:
        return b
    elif b==0:
        return a
    if a>b:
        return gcd(a%b,b)
    else:
        return gcd(a,b%a)

def lcm(a,b):
    return (a*b)//gcd(a,b)
#</template>

#<testcases>
#sys.stdin=open('input.txt','r')
#sys.stdout=open('output.txt','w')
#</testcases>



#<solve>
def solve():
    n = int(input())
    parent = [i for i in range(n+1)]
    rank = [0] * (n+1)
    close = []
    build = []

    def find(vertex):
        if vertex != parent[vertex]:
            parent[vertex] = find(parent[vertex])
        return parent[vertex]

    def union(x, y):
        parent_x = find(x)
        parent_y = find(y)
        if rank[parent_x] < rank[parent_y]:
            parent[parent_x] = parent_y
        elif rank[parent_y] < rank[parent_x]:
            parent[parent_y] = parent_x
        else:
            parent[parent_y] = parent_x
            rank[parent_x] += 1

    def roads():
        for i in range(n-1):
            u, v = map(int, input().split())
            if find(u) == find(v):
                close.append([u, v])
            else:
                union(u, v)
        for i in range(2, n+1):
            if find(i) != find(1):
                union(i, 1)
                build.append([1, i])
    roads()
    print(len(build))
    for i in range(len(close)):
        print(close[i][0], close[i][1], build[i][0], build[i][1])
#</solve>

#<solution>
#tc=i1()
#for t in range (tc):
solve()
#<solution>