// i wants to take ioi
//binhtinhtutinkhongcaycunhungmotkhikhongcontutinnualatuyetvong
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define nn "\n"
#define pi pair<int, int>
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define eb emplace_back
#define pb push_back
#define TASK " "

#define ms(a, x) memset(a, x, sizeof(a))
#define all(a) a.begin(), a.end()
#define All(a, n) a + 1, a + 1 + n

#define LOG 19


const int INF = 1e18;
const int mod = 1e9;
const int N = 1e3  + 5;
int MOD = 998244353;
int bit[200000];
struct node{
	int kc, u, hk;
	bool operator<(const node& other) const {
        return kc > other.kc;
    }
};
struct edge{
	int v, w, h;
};
int n;
struct edges{
    int a, b;
} canh[N];
int sz[N], par[N];

void make_set(int s){
    sz[s] = 1;
    par[s] = s;
}
int get(int s){
    if(par[s] == s) return s;
    return par[s] = get(par[s]);
}
void union_set(int a, int b){
    a = get(a);
    b = get(b);
    if(a != b){
        if(sz[a] < sz[b]) swap(a, b);
        par[b] = a;
        sz[a] += sz[b];
    }
}
void nhap(){
    cin >> n;
    for(int i = 1; i <= n - 1; i++){
        cin >> canh[i].a >> canh[i].b;
    }
}
vector<pi> v;
vector<pi> vt;
void solve(){
    for(int i = 1; i <= n; i++){
        make_set(i);
    }
    for(int i = 1; i < n; i++){
        if(get(canh[i].a) != get(canh[i].b)){
            union_set(canh[i].a, canh[i].b);
        }
        else{
            v.eb(canh[i].a, canh[i].b);
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            if(i != j){
                if(get(i) != get(j)){
                    union_set(i, j);
                    vt.eb(i, j);
                }
            }
        }
    }
    cout << v.size() << nn;
    for(int i = 0; i < v.size(); i++){
        cout << v[i].fi << " " << v[i].se << " " << vt[i].fi << " " << vt[i].se << nn;
    }
}
signed main() {
	// freopen("piggyback.in", "r", stdin);
	// freopen("piggyback.out", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	nhap();
	solve();
	return (0 ^ 0);

}
