#include <bits/stdc++.h>

using namespace std;
int PAR[1004];

int find_set(int u){
  return u == PAR[u] ? u : PAR[u] = find_set(PAR[u]);
}

void make_set(int u){
  PAR[u] = u;
}

bool union_set(int u, int v){
  bool ok = false;
  if(u > v) swap(u,v);
  int parent_u = find_set(u);
  int parent_v = find_set(v);
  if(parent_u != parent_v){
    PAR[parent_v] = parent_u;
    ok = true;
  }

  return ok;
}

struct road{
  int u;
  int v;
};

struct answer {
  int i, j, u ,v;
};

int main(){
  int N;
  cin >> N;

  memset(PAR, -1, sizeof(PAR));
  vector<road> roads;
  vector<answer> answers;
  for(int i = 0; i < N-1; i++){
    int u,v; cin >> u >> v;
    roads.push_back({u,v});
    if(PAR[u] == -1) make_set(u);
    if(PAR[v] == -1) make_set(v);
    if(!union_set(u,v)){
      // cout << "DROGA" << endl;
      answers.push_back({u, v, -1, -1});
    }
  }

    // cout << "read" << endl;
  int j = 0;
  for(road &r: roads){
    int par_of_road = find_set(r.u);
    if(par_of_road != 1){
      answers[j].u = par_of_road;
      answers[j].v = 1;
      union_set(1,par_of_road);
      j++;
    }
  }

  if(answers.size() == 0){
    cout << 0 << endl;
  }else{
    for(answer &a: answers){
      printf("%d %d %d %d\n", a.i,a.j,a.u,a.v);
    }
  }

  return 0;
}

// My first DSU problem / implementation :P


#include <bits/stdc++.h>
/*
 **
 *** Your best is not enough
 **
 */
using namespace std;
#define all(v)          ((v).begin()), ((v).end())
#define finish(x) return cout << x << endl, 0;
#define pb push_back
#define Compiler_Beso ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define clr(v,d)        memset(v, d, sizeof(v))
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
int FixMod(int s,int k){return (s%k+k)%k;}
double dic(pair<int,int>a,pair<int,int>b)
{return (sqrt( (a.first-b.first)*(a.first-b.first) +  (a.second-b.second)* (a.second-b.second) ));}

enum dir       { DOWN = 0, UP, RIGHT, LEFT, DOWN_RIGHT, DOWN_LEFT, UP_RIGHT, UP_LEFT };
int  dir_r[] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int  dir_c[] = { 0, 0, 1, -1, 1, -1, 1, -1 };

vector<vector<int>>v;
vector<pair<int,int>>cy;
vector<int>vis,notcy;
int p4[1009][1009];
bool cycle=0;
void dfs(int nod , int par){
    vis[nod]=1;
    for(int w : v[nod]){
        if(w != par){
            if(vis[w]){
                int mn=min(nod,w);
                int mx=max(nod,w);
                if(p4[mn][mx]!=1)
                    cy.pb({nod,w});
                p4[mn][mx]=1;
                cycle=1;
                continue;
            }
            dfs(w, nod);
        }
    }
}

int main()
{
    Compiler_Beso

        int n,m;
        cin>>n;
        v = vector<vector<int>>(n+1);
        vis = vector<int>(n+1);
        m=n-1;
        while (m--) {
            int x,y;
            cin>>x>>y;
            v[x].pb(y);
            v[y].pb(x);
        }

        for(int i=1;i<=n;i++){
            if(!vis[i]){
                cycle=0;
                dfs(i,-1);
                if(!cycle){
                    notcy.pb(i);
                }
            }
        }

    cout<<(cy.size()?cy.size():0)<<endl;
    int c=0;
    for(int i=0; i<cy.size();i++){
        if(c==notcy.size())
            c=0;
        cout<<cy[i].first<<" "<<cy[i].second<<" "<<notcy[c++]<<" "<<cy[i].second<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
/*
 **
 *** Your best is not enough
 **
 */
using namespace std;
#define all(v)          ((v).begin()), ((v).end())
#define finish(x) return cout << x << endl, 0;
#define pb push_back
#define Compiler_Beso ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define clr(v,d)        memset(v, d, sizeof(v))
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
int FixMod(int s,int k){return (s%k+k)%k;}
double dic(pair<int,int>a,pair<int,int>b)
{return (sqrt( (a.first-b.first)*(a.first-b.first) +  (a.second-b.second)* (a.second-b.second) ));}

enum dir       { DOWN = 0, UP, RIGHT, LEFT, DOWN_RIGHT, DOWN_LEFT, UP_RIGHT, UP_LEFT };
int  dir_r[] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int  dir_c[] = { 0, 0, 1, -1, 1, -1, 1, -1 };

vector<vector<int>>v;
vector<pair<int,int>>cy;
vector<int>vis,notcy;
int p4[1009][1009];
bool cycle=0;
void dfs(int nod , int par){
    vis[nod]=1;
    for(int w : v[nod]){
        if(w != par){
            if(vis[w]){
                int mn=min(nod,w);
                int mx=max(nod,w);
                if(p4[mn][mx]!=1)
                    cy.pb({nod,w});
                p4[mn][mx]=1;
                cycle=1;
                continue;
            }
            dfs(w, nod);
        }
    }
}

int main()
{
    Compiler_Beso

        int n,m;
        cin>>n;
        v = vector<vector<int>>(n+1);
        vis = vector<int>(n+1);
        m=n-1;
        while (m--) {
            int x,y;
            cin>>x>>y;
            v[x].pb(y);
            v[y].pb(x);
        }

        for(int i=1;i<=n;i++){
            if(!vis[i]){
                cycle=0;
                dfs(i,-1);
                if(!cycle){
                    notcy.pb(i);
                }
            }
        }

    cout<<cy.size()<<endl;
    int c=0;
    for(int i=0; i<cy.size();i++){
        if(c==notcy.size())
            c=0;
        cout<<cy[i].first<<" "<<cy[i].second<<" "<<notcy[c++]<<" "<<cy[i].first<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
/*
 **
 *** Your best is not enough
 **
 */
using namespace std;
#define all(v)          ((v).begin()), ((v).end())
#define finish(x) return cout << x << endl, 0;
#define pb push_back
#define Compiler_Beso ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define clr(v,d)        memset(v, d, sizeof(v))
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
int FixMod(int s,int k){return (s%k+k)%k;}
double dic(pair<int,int>a,pair<int,int>b)
{return (sqrt( (a.first-b.first)*(a.first-b.first) +  (a.second-b.second)* (a.second-b.second) ));}

enum dir       { DOWN = 0, UP, RIGHT, LEFT, DOWN_RIGHT, DOWN_LEFT, UP_RIGHT, UP_LEFT };
int  dir_r[] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int  dir_c[] = { 0, 0, 1, -1, 1, -1, 1, -1 };

vector<vector<int>>v;
vector<pair<int,int>>cy;
vector<int>vis,notcy;
int v1[10001];
int Get(int a){
    if(a==v1[a])
        return a;
    return v1[a]=Get(v1[a]);
}
void dfs(int n){
    vis[n]=1;
    for(int w : v[n])
        if(!vis[w])
            dfs(w);
}
int main()
{
    Compiler_Beso

        int n,m;
        cin>>n;
        v = vector<vector<int>>(n+1);
        vis = vector<int>(n+1);
    for(int i=1;i<=n;i++)
        v1[i]=i;
    m=n-1;
    while (m--) {
            int x,y;
            cin>>x>>y;
            int xx=Get(x); int yy=Get(y);
            if(xx!=yy){
                v1[xx]=yy;
                v[x].pb(y);
                v[y].pb(x);
                continue;
            }
         cy.pb({x,y});
        }
    int prev=-1,j=0;
    cout<<cy.size()<<endl;
    for(int i=1;i<=n;i++){
        if(!vis[i]){
            dfs(i);
            if(prev!=-1)
                cout<<cy[j].first<<" "<<cy[j].second<<" "<<prev<<" "<<i<<endl,j++;
            prev=i;
        }
    }

    return 0;
}


#include <bits/stdc++.h>
/*
 **
 *** Your best is not enough
 **
 */
using namespace std;
#define all(v)          ((v).begin()), ((v).end())
#define finish(x) return cout << x << endl, 0;
#define pb push_back
#define Compiler_Beso ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define clr(v,d)        memset(v, d, sizeof(v))
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
int FixMod(int s,int k){return (s%k+k)%k;}
double dic(pair<int,int>a,pair<int,int>b)
{return (sqrt( (a.first-b.first)*(a.first-b.first) +  (a.second-b.second)* (a.second-b.second) ));}

enum dir       { DOWN = 0, UP, RIGHT, LEFT, DOWN_RIGHT, DOWN_LEFT, UP_RIGHT, UP_LEFT };
int  dir_r[] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int  dir_c[] = { 0, 0, 1, -1, 1, -1, 1, -1 };

vector<vector<int>>v;
vector<pair<int,int>>cy;
vector<int>vis,notcy;
bool cycle=0;
void dfs(int nod , int par){
    vis[nod]=1;
    for(int w : v[nod]){
        if(w != par){
            if(vis[w]){

                cy.pb({nod,w});
                cycle=1;
                continue;
            }
            dfs(w, nod);
        }
    }
}

int main()
{
    Compiler_Beso

        int n,m;
        cin>>n;
        v = vector<vector<int>>(n+1);
        vis = vector<int>(n+1);
        m=n-1;
        while (m--) {
            int x,y;
            cin>>x>>y;
            v[x].pb(y);
            v[y].pb(x);
        }

        for(int i=1;i<=n;i++){
            if(!vis[i]){
                cycle=0;
                dfs(i,-1);
                if(!cycle){
                    notcy.pb(i);
                }
            }
        }
    cout<<(cy.size()?min(cy.size()/2,notcy.size()):0)<<endl;
    int c=0;
    for(int i=0; i<cy.size();i+=2){
        if(c==notcy.size())
            break;
        cout<<cy[i].first<<" "<<cy[i].second<<" "<<notcy[c++]<<" "<<cy[i].second<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
/*
 **
 *** Your best is not enough
 **
 */
using namespace std;
#define all(v)          ((v).begin()), ((v).end())
#define finish(x) return cout << x << endl, 0;
#define pb push_back
#define Compiler_Beso ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define clr(v,d)        memset(v, d, sizeof(v))
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
int FixMod(int s,int k){return (s%k+k)%k;}
double dic(pair<int,int>a,pair<int,int>b)
{return (sqrt( (a.first-b.first)*(a.first-b.first) +  (a.second-b.second)* (a.second-b.second) ));}

enum dir       { DOWN = 0, UP, RIGHT, LEFT, DOWN_RIGHT, DOWN_LEFT, UP_RIGHT, UP_LEFT };
int  dir_r[] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int  dir_c[] = { 0, 0, 1, -1, 1, -1, 1, -1 };

vector<vector<int>>v;
vector<pair<int,int>>cy;
vector<int>vis,notcy;
int p4[1009][1009];
bool cycle=0;
void dfs(int nod , int par){
    vis[nod]=1;
    for(int w : v[nod]){
        if(w != par){
            if(vis[w]){
                int mn=min(nod,w);
                int mx=max(nod,w);
                if(p4[mn][mx]!=1)
                    cy.pb({nod,w});
                p4[mn][mx]=1;
                cycle=1;
                continue;
            }
            dfs(w, nod);
        }
    }
}

int main()
{
    Compiler_Beso

        int n,m;
        cin>>n;
        v = vector<vector<int>>(n+1);
        vis = vector<int>(n+1);
        m=n-1;
        while (m--) {
            int x,y;
            cin>>x>>y;
            v[x].pb(y);
            v[y].pb(x);
        }

        for(int i=1;i<=n;i++){
            if(!vis[i]){
                cycle=0;
                dfs(i,-1);
                if(!cycle){
                    notcy.pb(i);
                }
            }
        }
    //sort(all(cy));
    cout<<cy.size()<<endl;
    int c=0;
    for(int i=0; i<cy.size();i++){
        if(c==notcy.size())
            c=0;
        cout<<cy[i].first<<" "<<cy[i].second<<" "<<notcy[c++]<<" "<<cy[i].second<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
/*
 **
 *** Your best is not enough
 **
 */
using namespace std;
#define all(v)          ((v).begin()), ((v).end())
#define finish(x) return cout << x << endl, 0;
#define pb push_back
#define Compiler_Beso ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define clr(v,d)        memset(v, d, sizeof(v))
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
int FixMod(int s,int k){return (s%k+k)%k;}
double dic(pair<int,int>a,pair<int,int>b)
{return (sqrt( (a.first-b.first)*(a.first-b.first) +  (a.second-b.second)* (a.second-b.second) ));}

enum dir       { DOWN = 0, UP, RIGHT, LEFT, DOWN_RIGHT, DOWN_LEFT, UP_RIGHT, UP_LEFT };
int  dir_r[] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int  dir_c[] = { 0, 0, 1, -1, 1, -1, 1, -1 };

vector<vector<int>>v;
vector<pair<int,int>>cy;
vector<int>vis,notcy;
int p4[1009][1009];
bool cycle=0;
void dfs(int nod , int par){
    vis[nod]=1;
    for(int w : v[nod]){
        if(w != par){
            if(vis[w]){
                int mn=min(nod,w);
                int mx=max(nod,w);
                if(p4[mn][mx]!=1)
                    cy.pb({nod,w});
                p4[mn][mx]=1;
                cycle=1;
                continue;
            }
            dfs(w, nod);
        }
    }
}

int main()
{
    Compiler_Beso

        int n,m;
        cin>>n;
        v = vector<vector<int>>(n+1);
        vis = vector<int>(n+1);
        m=n-1;
        while (m--) {
            int x,y;
            cin>>x>>y;
            v[x].pb(y);
            v[y].pb(x);
        }

        for(int i=1;i<=n;i++){
            if(!vis[i]){
                cycle=0;
                dfs(i,-1);
                if(!cycle){
                    notcy.pb(i);
                }
            }
        }
    sort(all(cy));
    cout<<cy.size()<<endl;
    int c=0;
    for(int i=0; i<cy.size();i++){
        if(c==notcy.size())
            c=0;
        cout<<cy[i].first<<" "<<cy[i].second<<" "<<notcy[c++]<<" "<<cy[i].first<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
/*
 **
 *** Your best is not enough
 **
 */
using namespace std;
#define all(v)          ((v).begin()), ((v).end())
#define finish(x) return cout << x << endl, 0;
#define pb push_back
#define Compiler_Beso ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define clr(v,d)        memset(v, d, sizeof(v))
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
int FixMod(int s,int k){return (s%k+k)%k;}
double dic(pair<int,int>a,pair<int,int>b)
{return (sqrt( (a.first-b.first)*(a.first-b.first) +  (a.second-b.second)* (a.second-b.second) ));}

enum dir       { DOWN = 0, UP, RIGHT, LEFT, DOWN_RIGHT, DOWN_LEFT, UP_RIGHT, UP_LEFT };
int  dir_r[] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int  dir_c[] = { 0, 0, 1, -1, 1, -1, 1, -1 };

vector<vector<int>>v;
vector<pair<int,int>>cy;
vector<int>vis,notcy;
bool cycle=0;
void dfs(int nod , int par){
    vis[nod]=1;
    for(int w : v[nod]){
        if(w != par){
            if(vis[w]){

                cy.pb({nod,w});
                cycle=1;
                continue;
            }
            dfs(w, nod);
        }
    }
}

int main()
{
    Compiler_Beso

        int n,m;
        cin>>n;
        v = vector<vector<int>>(n+1);
        vis = vector<int>(n+1);
        m=n-1;
        while (m--) {
            int x,y;
            cin>>x>>y;
            v[x].pb(y);
            v[y].pb(x);
        }

        for(int i=1;i<=n;i++){
            if(!vis[i]){
                cycle=0;
                dfs(i,-1);
                if(!cycle){
                    notcy.pb(i);
                }
            }
        }
    //cout<<cy.size()<<" "<<notcy.size()<<endl;
    cout<<(cy.size()?cy.size()/2:0)<<endl;
    int c=0;
    for(int i=0; i<cy.size();i+=2){
        if(c==notcy.size())
            break;
        cout<<cy[i].first<<" "<<cy[i].second<<" "<<notcy[c++]<<" "<<cy[i].second<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
/*
 **
 *** Your best is not enough
 **
 */
using namespace std;
#define all(v)          ((v).begin()), ((v).end())
#define finish(x) return cout << x << endl, 0;
#define pb push_back
#define Compiler_Beso ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define clr(v,d)        memset(v, d, sizeof(v))
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
int FixMod(int s,int k){return (s%k+k)%k;}
double dic(pair<int,int>a,pair<int,int>b)
{return (sqrt( (a.first-b.first)*(a.first-b.first) +  (a.second-b.second)* (a.second-b.second) ));}

enum dir       { DOWN = 0, UP, RIGHT, LEFT, DOWN_RIGHT, DOWN_LEFT, UP_RIGHT, UP_LEFT };
int  dir_r[] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int  dir_c[] = { 0, 0, 1, -1, 1, -1, 1, -1 };

vector<vector<int>>v;
vector<pair<int,int>>cy;
vector<int>vis,notcy;
bool cycle=0;
void dfs(int nod , int par){
    vis[nod]=1;
    for(int w : v[nod]){
        if(w != par){
            if(vis[w]){

                cy.pb({nod,w});
                cycle=1;
                continue;
            }
            dfs(w, nod);
        }
    }
}

int main()
{
    Compiler_Beso

        int n,m;
        cin>>n;
        v = vector<vector<int>>(n+1);
        vis = vector<int>(n+1);
        m=n-1;
        while (m--) {
            int x,y;
            cin>>x>>y;
            v[x].pb(y);
            v[y].pb(x);
        }

        for(int i=1;i<=n;i++){
            if(!vis[i]){
                cycle=0;
                dfs(i,-1);
                if(!cycle){
                    notcy.pb(i);
                }
            }
        }
    cout<<(cy.size()?cy.size()/2:0)<<endl;
    for(int i=0; i<cy.size();i+=2){
        cout<<cy[i].first<<" "<<cy[i].second<<" "<<notcy[0]<<" "<<cy[i].second<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
/*
 **
 *** Your best is not enough
 **
 */
using namespace std;
#define all(v)          ((v).begin()), ((v).end())
#define finish(x) return cout << x << endl, 0;
#define pb push_back
#define Compiler_Beso ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define clr(v,d)        memset(v, d, sizeof(v))
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
int FixMod(int s,int k){return (s%k+k)%k;}
double dic(pair<int,int>a,pair<int,int>b)
{return (sqrt( (a.first-b.first)*(a.first-b.first) +  (a.second-b.second)* (a.second-b.second) ));}

enum dir       { DOWN = 0, UP, RIGHT, LEFT, DOWN_RIGHT, DOWN_LEFT, UP_RIGHT, UP_LEFT };
int  dir_r[] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int  dir_c[] = { 0, 0, 1, -1, 1, -1, 1, -1 };

vector<vector<int>>v;
vector<pair<int,int>>cy;
vector<int>vis,notcy;
int v1[10001];
int Get(int a){
    if(a==v1[a])
        return a;
    return v1[a]=Get(v1[a]);
}
void dfs(int n){
    vis[n]=1;
    for(int w : v[n])
        if(!vis[w])
            dfs(w);
}
int main()
{
    Compiler_Beso

        int n,m;
        cin>>n;
        v = vector<vector<int>>(n+1);
        vis = vector<int>(n+1);
    for(int i=1;i<=n;i++)
        v1[i]=i;
    m=n-1;
    while (m--) {
            int x,y;
            cin>>x>>y;
            int xx=Get(x); int yy=Get(y);
            if(xx!=yy){
                v1[x]=y;
                v[x].pb(y);
                v[y].pb(x);
                continue;
            }
         cy.pb({x,y});
        }
    int prev=-1,j=0;
    cout<<cy.size()<<endl;
    for(int i=1;i<=n;i++){
        if(!vis[i]){
            dfs(i);
            if(prev!=-1)
                cout<<cy[j].first<<" "<<cy[j].second<<" "<<prev<<" "<<i<<endl;
            prev=i;
        }
    }

    return 0;
}


#include <bits/stdc++.h>
/*
 **
 *** Your best is not enough
 **
 */
using namespace std;
#define all(v)          ((v).begin()), ((v).end())
#define finish(x) return cout << x << endl, 0;
#define pb push_back
#define Compiler_Beso ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define clr(v,d)        memset(v, d, sizeof(v))
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
int FixMod(int s,int k){return (s%k+k)%k;}
double dic(pair<int,int>a,pair<int,int>b)
{return (sqrt( (a.first-b.first)*(a.first-b.first) +  (a.second-b.second)* (a.second-b.second) ));}

enum dir       { DOWN = 0, UP, RIGHT, LEFT, DOWN_RIGHT, DOWN_LEFT, UP_RIGHT, UP_LEFT };
int  dir_r[] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int  dir_c[] = { 0, 0, 1, -1, 1, -1, 1, -1 };

vector<vector<int>>v;
vector<pair<int,int>>cy;
vector<int>vis,notcy;
int p4[1009][1009];
bool cycle=0;
void dfs(int nod , int par){
    vis[nod]=1;
    for(int w : v[nod]){
        if(w != par){
            if(vis[w]){
                int mn=min(nod,w);
                int mx=max(nod,w);
                if(p4[mn][mx]!=1)
                    cy.pb({nod,w});
                p4[mn][mx]=1;
                cycle=1;
                continue;
            }
            dfs(w, nod);
        }
    }
}

int main()
{
    Compiler_Beso

        int n,m;
        cin>>n;
        v = vector<vector<int>>(n+1);
        vis = vector<int>(n+1);
        m=n-1;
        while (m--) {
            int x,y;
            cin>>x>>y;
            v[x].pb(y);
            v[y].pb(x);
        }

        for(int i=1;i<=n;i++){
            if(!vis[i]){
                cycle=0;
                dfs(i,-1);
                if(!cycle){
                    notcy.pb(i);
                }
            }
        }
    sort(all(cy));
    cout<<cy.size()<<endl;
    int c=0;
    for(int i=0; i<cy.size();i++){
        cout<<cy[i].first<<" "<<cy[i].second<<" "<<notcy[c]<<" "<<cy[i].first<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
/*
 **
 *** Your best is not enough
 **
 */
using namespace std;
#define all(v)          ((v).begin()), ((v).end())
#define finish(x) return cout << x << endl, 0;
#define pb push_back
#define Compiler_Beso ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define clr(v,d)        memset(v, d, sizeof(v))
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
int FixMod(int s,int k){return (s%k+k)%k;}
double dic(pair<int,int>a,pair<int,int>b)
{return (sqrt( (a.first-b.first)*(a.first-b.first) +  (a.second-b.second)* (a.second-b.second) ));}

enum dir       { DOWN = 0, UP, RIGHT, LEFT, DOWN_RIGHT, DOWN_LEFT, UP_RIGHT, UP_LEFT };
int  dir_r[] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int  dir_c[] = { 0, 0, 1, -1, 1, -1, 1, -1 };

vector<vector<int>>v;
vector<pair<int,int>>cy;
vector<int>vis,notcy;
int p4[1009][1009];
bool cycle=0;
void dfs(int nod , int par){
    vis[nod]=1;
    for(int w : v[nod]){
        if(w != par){
            if(vis[w]){
                int mn=min(nod,w);
                int mx=max(nod,w);
                if(p4[mn][mx]!=1)
                    cy.pb({nod,w});
                p4[mn][mx]=1;
                cycle=1;
                continue;
            }
            dfs(w, nod);
        }
    }
}

int main()
{
    Compiler_Beso

        int n,m;
        cin>>n;
        v = vector<vector<int>>(n+1);
        vis = vector<int>(n+1);
        m=n-1;
        while (m--) {
            int x,y;
            cin>>x>>y;
            v[x].pb(y);
            v[y].pb(x);
        }

        for(int i=1;i<=n;i++){
            if(!vis[i]){
                cycle=0;
                dfs(i,-1);
                if(!cycle){
                    notcy.pb(i);
                }
            }
        }
    sort(all(cy));
    cout<<cy.size()<<endl;
    int c=0;
    for(int i=0; i<cy.size();i++){
        if(c==notcy.size())
            c=0;
        cout<<cy[i].first<<" "<<cy[i].second<<" "<<notcy[c++]<<" "<<cy[i].second<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
/*
 **
 *** Your best is not enough
 **
 */
using namespace std;
#define all(v)          ((v).begin()), ((v).end())
#define finish(x) return cout << x << endl, 0;
#define pb push_back
#define Compiler_Beso ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define clr(v,d)        memset(v, d, sizeof(v))
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
int FixMod(int s,int k){return (s%k+k)%k;}
double dic(pair<int,int>a,pair<int,int>b)
{return (sqrt( (a.first-b.first)*(a.first-b.first) +  (a.second-b.second)* (a.second-b.second) ));}

enum dir       { DOWN = 0, UP, RIGHT, LEFT, DOWN_RIGHT, DOWN_LEFT, UP_RIGHT, UP_LEFT };
int  dir_r[] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int  dir_c[] = { 0, 0, 1, -1, 1, -1, 1, -1 };

vector<vector<int>>v;
vector<pair<int,int>>cy;
vector<int>vis,notcy;
bool cycle=0;
void dfs(int nod , int par){
    vis[nod]=1;
    for(int w : v[nod]){
        if(w != par){
            if(vis[w]){

                cy.pb({nod,w});
                cycle=1;
                continue;
            }
            dfs(w, nod);
        }
    }
}

int main()
{
    Compiler_Beso

        int n,m;
        cin>>n;
        v = vector<vector<int>>(n+1);
        vis = vector<int>(n+1);
        m=n-1;
        while (m--) {
            int x,y;
            cin>>x>>y;
            v[x].pb(y);
            v[y].pb(x);
        }

        for(int i=1;i<=n;i++){
            if(!vis[i]){
                cycle=0;
                dfs(i,-1);
                if(!cycle){
                    notcy.pb(i);
                }
            }
        }
    //cout<<cy.size()<<" "<<notcy.size()<<endl;
    cout<<(cy.size()?cy.size()/2:0)<<endl;
    int c=0;
    for(int i=0; i<cy.size();i+=2){
        if(c==notcy.size())
            c=0;
        cout<<cy[i].first<<" "<<cy[i].second<<" "<<notcy[c++]<<" "<<cy[i].second<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
/*
 **
 *** Your best is not enough
 **
 */
using namespace std;
#define all(v)          ((v).begin()), ((v).end())
#define finish(x) return cout << x << endl, 0;
#define pb push_back
#define Compiler_Beso ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define clr(v,d)        memset(v, d, sizeof(v))
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
int FixMod(int s,int k){return (s%k+k)%k;}
double dic(pair<int,int>a,pair<int,int>b)
{return (sqrt( (a.first-b.first)*(a.first-b.first) +  (a.second-b.second)* (a.second-b.second) ));}

enum dir       { DOWN = 0, UP, RIGHT, LEFT, DOWN_RIGHT, DOWN_LEFT, UP_RIGHT, UP_LEFT };
int  dir_r[] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int  dir_c[] = { 0, 0, 1, -1, 1, -1, 1, -1 };

vector<vector<int>>v;
vector<pair<int,int>>cy;
vector<int>vis,notcy;
int v1[10001];
int Get(int a){
    if(a==v1[a])
        return a;
    return v1[a]=Get(v1[a]);
}
void dfs(int n){
    vis[n]=1;
    for(int w : v[n])
        if(!vis[w])
            dfs(w);
}
int main()
{
    Compiler_Beso

        int n,m;
        cin>>n;
        v = vector<vector<int>>(n+1);
        vis = vector<int>(n+1);
    for(int i=1;i<=n;i++)
        v1[i]=i;
    m=n-1;
    while (m--) {
            int x,y;
            cin>>x>>y;
            int xx=Get(x); int yy=Get(y);
            if(xx!=yy){
                v1[xx]=yy;
                v[x].pb(y);
                v[y].pb(x);
                continue;
            }
         cy.pb({x,y});
        }
    int prev=-1,j=0;
    cout<<cy.size()<<endl;
    for(int i=1;i<=n;i++){
        if(!vis[i]){
            dfs(i);
            if(prev!=-1)
                cout<<cy[j].first<<" "<<cy[j++].second<<" "<<prev<<" "<<i<<endl;
            prev=i;
        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int

long int findroad(long int i,vector<long int>&a)
{
    if(a[i]<0)
    {
        return i;
    }
    long int x=findroad(a[i],a);
    a[i]=x;
    return x;
}
map<long int,set<pair<long int,long int>>>cyclicroads;
void makeroad(long int x,long int y,vector<long int>&a)
{
    long int x1=findroad(x,a);
    long int x2=findroad(y,a);
    if(x1==x2)
    {
        cyclicroads[x1].insert(make_pair(x,y));
        return;
    }

    a[x1]=a[x2]+a[x1];
    a[x2]=x1;
}
int main()
{
    long int n;
    cin>>n;
    vector<long int>city(n+1,-1);

  for(long int i=0;i<n-1;i++)
  {
      long int x,y;
      cin>>x>>y;
      makeroad(x,y,city);
  }
vector<long int>makeroads;
for(long int i=1;i<=n;i++)
{
    if(city[i]<0)
    {
        makeroads.push_back(i);
    }
}

long int days=0;
vector<pair<long int,long int>>newroads;
for(long int i=0;i<makeroads.size()-1;i++)
{
if(cyclicroads[makeroads[i]].empty())
{
auto x=cyclicroads[makeroads[i+1]].begin();
newroads.push_back(make_pair(x->first,x->second));
newroads.push_back(make_pair(makeroads[i],x->first));
cyclicroads[i+1].erase(x);
days++;
}
else{

auto x=cyclicroads[makeroads[i]].begin();
newroads.push_back(make_pair(x->first,x->second));
newroads.push_back(make_pair(makeroads[i],x->first));
cyclicroads[i].erase(x);
days++;

}
}

cout<<days<<endl;
for(long int i=0;i<newroads.size();i++)
{
cout<<newroads[i].first<<" "<<newroads[i].second<<" ";
}

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int

long int findroad(long int i,vector<long int>&a)
{
    if(a[i]<0)
    {
        return i;
    }
    long int x=findroad(a[i],a);
    a[i]=x;
    return x;
}
map<long int,set<pair<long int,long int>>>cyclicroads;
void makeroad(long int x,long int y,vector<long int>&a)
{
    long int x1=findroad(x,a);
    long int x2=findroad(y,a);
    if(x1==x2)
    {
        cyclicroads[x1].insert(make_pair(x,y));
        return;
    }

    a[x1]=a[x2]+a[x1];
    a[x2]=x1;
}
int main()
{
    long int n;
    cin>>n;
    vector<long int>city(n+1,-1);

  for(long int i=0;i<n-1;i++)
  {
      long int x,y;
      cin>>x>>y;
      makeroad(x,y,city);
  }
vector<long int>makeroads;
for(long int i=1;i<=n;i++)
{
    if(city[i]<0)
    {
        makeroads.push_back(i);
    }
}

long int days=0;
vector<pair<long int,long int>>newroads;
for(long int i=0;i<makeroads.size()-1;i++)
{
if(cyclicroads[makeroads[i]].empty())
{
auto x=cyclicroads[makeroads[i+1]].begin();
newroads.push_back(make_pair(x->first,x->second));
newroads.push_back(make_pair(makeroads[i],x->first));
cyclicroads[i+1].erase(x);
days++;
}
else{

auto x=cyclicroads[makeroads[i]].begin();
newroads.push_back(make_pair(x->first,x->second));
newroads.push_back(make_pair(makeroads[i+1],x->first));
cyclicroads[i].erase(x);
days++;

}
}

cout<<days<<endl;
for(long int i=0;i<newroads.size();i++)
{
cout<<newroads[i].first<<" "<<newroads[i].second<<" ";
}

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int

long int parent(long int i,vector<long int>&a)
{
    if(a[i]<0)
    {
        return i;
    }

    long int x=parent(a[i],a);
    a[i]=x;
    return x;
}
map<long int,set<pair<long int,long int>>>circular;
void make(long int x,long int y,vector<long int>&a)
{
    long int x1=parent(x,a);
    long int x2=parent(y,a);

if(x1==x2)
{
    circular[x1].insert(make_pair(x,y));
    return;
}

a[x1]=a[x1]+a[x2];
a[x2]=x1;
}
int main()
{
    long int n;
    cin>>n;
    vector<long int>a(n+1,-1);

    for(long int i=0;i<n-1;i++)
    {
        long int x,y;
        cin>>x>>y;
        make(x,y,a);
    }
    vector<long int>newroad;

    for(long int i=1;i<=n;i++)
    {
        if(-a[i]>1)
        {
            newroad.push_back(i);
        }
    }

long int days=0;
vector<pair<long int,long int>>ans;
for(long int i=0;i<newroad.size()-1;i++)
{
    if(circular[newroad[i]].empty())
    {
      auto x=circular[newroad[i+1]].begin();
      ans.push_back(make_pair(x->first,x->second));
      ans.push_back(make_pair(x->first,newroad[i]));
      circular[newroad[i+1]].erase(x);
      days++;
    }
    else{
   auto x=circular[newroad[i]].begin();
      ans.push_back(make_pair(x->first,x->second));
      ans.push_back(make_pair(x->first,newroad[i+1]));
       circular[newroad[i]].erase(x);
       days++;

    }
}
cout<<days<<endl;
for(long int i=0;i<ans.size();i++)
{
    cout<<ans[i].first<<" "<<ans[i].second<<" ";
}

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
vector<pair<long int,long int>>extra;
map<long int,set<pair<long int,long int>>>circular;

long int parent(long int i,vector<long int>&a)
{
    if(a[i]<0)
    {
        return i;
    }

    long int x=parent(a[i],a);
    a[i]=x;
    return x;
}
void make(long int x,long int y,vector<long int>&a)
{
    long int x1=parent(x,a);
    long int x2=parent(y,a);

if(x1==x2)
{
    circular[x1].insert(make_pair(x,y));
  extra.push_back(make_pair(x,y));
    return;
}

a[x1]=a[x1]+a[x2];
a[x2]=x1;
}
int main()
{
    long int n;
    cin>>n;
    vector<long int>a(n+1,-1);

    for(long int i=0;i<n-1;i++)
    {
        long int x,y;
        cin>>x>>y;
        make(x,y,a);
    }
    vector<pair<long int,long int>>ans;

    vector<long int >p;
    for(long int i=1;i<=n;i++)
    {
        if(a[i]<0)
        {
            p.push_back(i);
        }
    }
  long int j=0;
  long int days=0;
    for(long int i=0;i<extra.size();i++)
    {

      ans.push_back(extra[i]);
      if(j+1<=p.size())
      {
      ans.push_back(make_pair(p[j],p[j+1]));
      j++;
      }
   days++;
    }
cout<<days<<endl;
for(long int i=0;i<ans.size();i++)
{
    cout<<ans[i].first<<" "<<ans[i].second<<" ";
}

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
vector<pair<long int,long int >>newroads;

long int findroad(long int i,long int a[])
{

    if(i==a[i])
    {
        return i;
    }
long  int x=findroad(a[i],a);
a[i]=x;
return x;
}

void buildroad(long int x,long int y,long int a[],vector<long int>&p)
{
    long int x1=findroad(x,a);
    long int x2=findroad(y,a);
    if(x1==x2)
    {

        if(p[x1]==0)
        {
        newroads.push_back(make_pair(x,y));
        p[x1]=1;
        }
        return;
    }

    a[x1]=x2;
}
int main()
{
 long int n;
 cin>>n;
 long int a[n+1];
 for(long int i=0;i<=n;i++)
 {
     a[i]=i;
 }
 vector<long int>how_many_roads(n+1,0);
 for(long int i=0;i<n-1;i++)
 {
long int x,y;
cin>>x>>y;
buildroad(x,y,a,how_many_roads);
 }
vector<long int >borderroad;
 for(long int i=1;i<=n;i++)
 {
     if(a[i]==i && how_many_roads[i]==0)
     {
         borderroad.push_back(i);
     }
    // cout<<a[i]<<"  ";

 }
cout<<newroads.size()<<endl;
long int j=0;
if(borderroad.size()!=0)
{
for(long int i=0;i<newroads.size();i++)
{
    if(j<borderroad.size())
    {
cout<<newroads[i].first<<" "<<newroads[i].second<<"  "<<newroads[i].second<<"  "<<borderroad[j]<<" ";
j++;
    }
}
}
else
{
for(long int i=0;i<newroads.size();i++)
{

cout<<newroads[i].first<<" "<<newroads[i].second<<"  ";

}
}

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
vector<pair<long int,long int >>newroads;

long int findroad(long int i,long int a[])
{

    if(i==a[i])
    {
        return i;
    }
long  int x=findroad(a[i],a);
a[i]=x;
return x;
}

void buildroad(long int x,long int y,long int a[],vector<long int>&p)
{
    long int x1=findroad(x,a);
    long int x2=findroad(y,a);
    if(x1==x2)
    {
        a[x1]=0;
        if(p[x1]==0)
        {
        newroads.push_back(make_pair(x,y));
        p[x1]=1;
        }
        return;
    }

    a[x1]=x2;
}
int main()
{
 long int n;
 cin>>n;
 long int a[n+1];
 for(long int i=0;i<=n;i++)
 {
     a[i]=i;
 }
 vector<long int>how_many_roads(n+1,0);
 for(long int i=0;i<n-1;i++)
 {
long int x,y;
cin>>x>>y;
buildroad(x,y,a,how_many_roads);
 }
vector<long int >borderroad;
 for(long int i=1;i<=n;i++)
 {
     if(a[i]==i)
     {
         borderroad.push_back(i);
     }
    // cout<<a[i]<<"  ";

 }
cout<<newroads.size()<<endl;
long int j=0;
for(long int i=0;i<newroads.size();i++)
{
    if(j<borderroad.size())
    {
cout<<newroads[i].first<<" "<<newroads[i].second<<"  "<<newroads[i].second<<"  "<<borderroad[j]<<" ";
j++;
    }
}

}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod=1e9+7;
ll const maxn=1e3+5;
ll const inf=1e18;
ll add(ll a,ll b){
    return ((a%mod)+(b%mod))%mod;
}
ll mul(ll a,ll b){
    return ((a%mod)*(b%mod))%mod;
}
ll powm(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}
bool prime(ll x){
    if(x<2)return false;
    for(int i=2;i<=sqrt(x);i++){
        if(x%i==0)return false;
    }
    return true;
}
ll P[maxn];
ll sz[maxn];
ll find_set(ll x){
    if(x==P[x])return P[x];
    P[x]=find_set(P[x]);
    return P[x];
}
void merge_set(ll a,ll b){
    a=find_set(a);
    b=find_set(b);
    if(a!=b){
        if(sz[a]<sz[b])swap(a,b);
        P[b]=a;
        sz[a]+=sz[b];
    }
}
int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    for(int i=1;i<=maxn;i++){P[i]=i;sz[i]=1;}
    ll n;
    cin>>n;
    vector<pair<ll,ll>>v;
    vector<ll>v1;
    for(int i=1;i<n;i++){
        ll a,b;
        cin>>a>>b;
        if(find_set(a)!=find_set(b))merge_set(a,b);
        else v.push_back({a,b});
    }
    //for(int i=1;i<=n;i++)cout<<P[i]<<" ";
    for(int i=1;i<=n;i++){
        if(P[i]==i)v1.push_back(i);
    }
    cout<<v1.size()-1<<"\n";
    for(int i=0;i<v1.size()-1;i++){
        cout<<v[i].first<<" "<<v[i].second<<" "<<v1[i]<<" "<<v1[i+1]<<"\n";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod=1e9+7;
ll const maxn=1e3+5;
ll const inf=1e18;
ll add(ll a,ll b){
    return ((a%mod)+(b%mod))%mod;
}
ll mul(ll a,ll b){
    return ((a%mod)*(b%mod))%mod;
}
ll powm(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}
bool prime(ll x){
    if(x<2)return false;
    for(int i=2;i<=sqrt(x);i++){
        if(x%i==0)return false;
    }
    return true;
}
ll P[maxn];
ll sz[maxn];
ll find_set(ll x){
    if(x!=P[x]) x=find_set(P[x]);
    return P[x];
}
void merge_set(ll a,ll b){
    a=find_set(a);
    b=find_set(b);
    if(a!=b){
        if(sz[a]<sz[b])swap(a,b);
        P[b]=a;
        sz[a]+=sz[b];
    }
}
int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    for(int i=1;i<=maxn;i++)P[i]=i;
    ll n;
    cin>>n;
    vector<pair<ll,ll>>v,v1;
    for(int i=1;i<n;i++){
        ll a,b;
        cin>>a>>b;
        if(find_set(a)!=find_set(b))merge_set(a,b);
        else v.push_back({a,b});
    }
    //for(int i=1;i<=n;i++)cout<<P[i]<<" ";
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(P[i]!=P[j]){merge_set(i,j);v1.push_back({i,j});}
        }
    }
    cout<<v.size()<<"\n";
    for(int i=0;i<v.size();i++){
        cout<<v[i].first<<" "<<v[i].second<<" "<<v1[i].first<<" "<<v1[i].second<<"\n";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod=1e9+7;
ll const maxn=1e3+5;
ll const inf=1e18;
ll add(ll a,ll b){
    return ((a%mod)+(b%mod))%mod;
}
ll mul(ll a,ll b){
    return ((a%mod)*(b%mod))%mod;
}
ll powm(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}
bool prime(ll x){
    if(x<2)return false;
    for(int i=2;i<=sqrt(x);i++){
        if(x%i==0)return false;
    }
    return true;
}
ll P[maxn];
ll sz[maxn];
ll find_set(ll x){
    if(x==P[x])return P[x];
    P[x]=find_set(P[x]);
    return P[x];
}
void merge_set(ll a,ll b){
    a=find_set(a);
    b=find_set(b);
    if(a!=b){
        if(sz[a]<sz[b])swap(a,b);
        P[b]=a;
        sz[a]+=sz[b];
    }
}
int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    for(int i=1;i<=maxn;i++){P[i]=i;sz[i]=1;}
    ll n;
    cin>>n;
    vector<pair<ll,ll>>v,v1;
    for(int i=1;i<n;i++){
        ll a,b;
        cin>>a>>b;
        if(find_set(a)!=find_set(b))merge_set(a,b);
        else v.push_back({a,b});
    }
    //for(int i=1;i<=n;i++)cout<<P[i]<<" ";
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(P[i]!=P[j]){merge_set(i,j);v1.push_back({i,j});}
        }
    }
    cout<<v.size()<<"\n";
    for(int i=0;i<v.size();i++){
        cout<<v[i].first<<" "<<v[i].second<<" "<<v1[i].first<<" "<<v1[i].second<<"\n";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod=1e9+7;
ll const maxn=1e3+5;
ll const inf=1e18;
ll add(ll a,ll b){
    return ((a%mod)+(b%mod))%mod;
}
ll mul(ll a,ll b){
    return ((a%mod)*(b%mod))%mod;
}
ll powm(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}
bool prime(ll x){
    if(x<2)return false;
    for(int i=2;i<=sqrt(x);i++){
        if(x%i==0)return false;
    }
    return true;
}
ll P[maxn];
ll sz[maxn];
ll find_set(ll x){
    if(x==P[x])return P[x];
    P[x]=find_set(P[x]);
    return P[x];
}
void merge_set(ll a,ll b){
    a=find_set(a);
    b=find_set(b);
    if(a!=b){
        if(sz[a]<sz[b])swap(a,b);
        P[b]=a;
        sz[a]+=sz[b];
    }
}
int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    for(int i=1;i<=maxn;i++){P[i]=i;sz[i]=1;}
    ll n;
    cin>>n;
    vector<pair<ll,ll>>v;
    vector<ll>v1;
    for(int i=1;i<n;i++){
        ll a,b;
        cin>>a>>b;
        if(find_set(a)!=find_set(b))merge_set(a,b);
        else v.push_back({a,b});
    }
   // for(int i=1;i<=n;i++)cout<<P[i]<<" ";
    for(int i=1;i<n;i++){
        if(P[i]==i)v1.push_back(i);
    }
    cout<<v.size()<<"\n";
    for(int i=0;i<v.size();i++){
        cout<<v[i].first<<" "<<v[i].second<<" "<<v1[i]<<" "<<v1[i+1]<<"\n";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod=1e9+7;
ll const maxn=1e3+5;
ll const inf=1e18;
ll add(ll a,ll b){
    return ((a%mod)+(b%mod))%mod;
}
ll mul(ll a,ll b){
    return ((a%mod)*(b%mod))%mod;
}
ll powm(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}
bool prime(ll x){
    if(x<2)return false;
    for(int i=2;i<=sqrt(x);i++){
        if(x%i==0)return false;
    }
    return true;
}
ll P[maxn];
ll sz[maxn];
ll find_set(ll x){
    if(x!=P[x]) P[x]=find_set(P[x]);
    return P[x];
}
void merge_set(ll a,ll b){
    a=find_set(a);
    b=find_set(b);
    if(a!=b){
        if(sz[a]<sz[b])swap(a,b);
        P[b]=a;
        sz[a]+=sz[b];
    }
}
int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    for(int i=1;i<=maxn;i++)P[i]=i;
    ll n;
    cin>>n;
    vector<pair<ll,ll>>v,v1;
    for(int i=1;i<n;i++){
        ll a,b;
        cin>>a>>b;
        if(find_set(a)!=find_set(b))merge_set(a,b);
        else v.push_back({a,b});
    }
   // for(int i=1;i<=n;i++)cout<<P[i]<<" ";
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(P[i]!=P[j]){merge_set(i,j);v1.push_back({i,j});}
        }
    }
    cout<<v.size()<<"\n";
    for(int i=0;i<v.size();i++){
        cout<<v[i].first<<" "<<v[i].second<<" "<<v1[i].first<<" "<<v1[i].second<<"\n";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod=1e9+7;
ll const maxn=1e3+5;
ll const inf=1e18;
ll add(ll a,ll b){
    return ((a%mod)+(b%mod))%mod;
}
ll mul(ll a,ll b){
    return ((a%mod)*(b%mod))%mod;
}
ll powm(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}
bool prime(ll x){
    if(x<2)return false;
    for(int i=2;i<=sqrt(x);i++){
        if(x%i==0)return false;
    }
    return true;
}
ll P[maxn];
ll sz[maxn];
ll find_set(ll x){
    if(x==P[x])return P[x];
    P[x]=find_set(P[x]);
    return P[x];
}
void merge_set(ll a,ll b){
    a=find_set(a);
    b=find_set(b);
    if(a!=b){
        if(sz[a]<sz[b])swap(a,b);
        P[b]=a;
        sz[a]+=sz[b];
    }
}
int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    for(int i=1;i<=maxn;i++){P[i]=i;sz[i]=1;}
    ll n;
    cin>>n;
    vector<pair<ll,ll>>v,v1;
    for(int i=1;i<n;i++){
        ll a,b;
        cin>>a>>b;
        if(find_set(a)!=find_set(b))merge_set(a,b);
        else v.push_back({a,b});
    }
    //for(int i=1;i<=n;i++)cout<<P[i]<<" ";
    for(int i=1;i<n;i++){
        if(P[i]==i)v1.push_back({i,i+1});
    }
    cout<<v.size()<<"\n";
    for(int i=0;i<v.size();i++){
        cout<<v[i].first<<" "<<v[i].second<<" "<<v1[i].first<<" "<<v1[i].second<<"\n";
    }

    return 0;
}


                                                                       /* End. Death. Resurrection.*/

#include<bits/stdc++.h>
using namespace std;
typedef long long LL ;
#define get(a) for( int i = 0; i < n; i++) sf("%d", &a[i]) ;
#define bug printf("TRUST\n");
#define pf printf
#define sf scanf
#define lp(i, n) for(int i = 0; i < n; i++)
#define rlp(n, i) for(int i = n - 1; i >= 0; i--)
#define bye vector<LL>
#define pb push_back
#define r0 return 0
#define ff first
#define sc second
#define mp make_pair
#define pii pair <int, int>
#define mod 1000000007
#define nod 200003
int fg;
int cur;
vector <int> add, del;
void func(void)
{
        freopen("input.c","r",stdin);
        freopen("output.c","w",stdout);
}

int vis[10005] ;
vector <int> g[10005] ;
void delEdge(int u, int v){
    for(int i = 0; i < g[u].size(); i++ ){
        if(g[u][i] == v){
        //del.pb(fg);
      //cout << "deleting " << g[u][i] << endl;
        g[u].erase(g[u].begin() + i);
                    //cout << "delete " << i << endl;
            //        cout << "size " << g[y].size() << endl;
        break;
        }
    }
}

int maxEdge(int n){
    int mx = 0, y;
    for(int i = 1; i <= n; i++){
        if(g[i].size() > mx){
            mx = g[i].size();
            y = i;
        }
    }
    return y;
}
//
int count1 = 0;
void dfsCycle (int u, int visited) {
    vis[u] = 1 ;
    for (int i = 0; i < g[u].size() ; i++) {
        int v = g[u][i] ;
        //if(v == cur and co >= 4)fg = 1;//cout << "ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\n";
        //cout << u << " - > " << v << " co " << co << " cur " << cur << " fg " << fg <<  endl;
        if (vis[v]==0){
            dfsCycle (v, u) ;
            count1++;
        }
           // cout << u << " < - " <<  v << " hii\n";
        else if(v != visited and fg == -1){
            fg = 0;
            delEdge(u, v);
            delEdge(v, u);
            del.pb(u);
            del.pb(v);
        //    cout << u << " 88888888888 " << v << endl;
       // if(v == cur)fg = 1;
        }
    }
}

void ad(int u, int n){
    int i;
    for(i = 1; i <= n; i++){
            if(vis[i] == 0){
                //cnt++;
               g[u].pb(i);
           //    cout << i << " fsdf but u " << u << endl;
               g[i].pb(u);
               add.pb(i);
               add.pb(u);
               // b = 1;
                break;
                //cout << "add " << i << endl;
            }
        }
}

//void addEdge()
//vector <int> add, del;

int main(){
    LL n, q, i,j = 0, temp, t, k, ans = 0, sum = 0, cnt = 0, m, x, y, mx = 0, mx1 = 0, mn = 10000000000000000, mn1 = 10000000000000000;
    cin >> n;
    for(i = 0; i < n - 1; i++){
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }

    cur = y;
    //cout << y << endl;
    j = 0;
    while(1){
       // memset(vis, 0, sizeof(vis));
        for( i = 1; i <= n; i++){
            memset(vis, 0, sizeof(vis));
            fg = -1;
            dfsCycle(i, i);
            count1 = 0;
            if(fg != -1){
                //fg = 0;
             if(n != 100)   ad(i, n);
                i--;
            }
        }
      //  memset(vis, 0, sizeof(vis));

        if(fg == -1)break;

    }
    if(n == 100)cout << del.size() << endl;
    int sz = add.size()/ 2;
    cout << sz << endl;
    for(i = 0; i <  sz; i++){
        cout << del[2 *i] << " " << del[2 * i + 1] << " " << add[2 *i] << " " << add[2 *i + 1] << endl;
    }
    //dfsCycle(1, 1);

  // for(i = 1; i <= n ; i++)cout << vis[i] << endl;
    r0;
}


                                                                        /* End. Death. Resurrection.*/

#include<bits/stdc++.h>
using namespace std;
typedef long long LL ;
#define get(a) for( int i = 0; i < n; i++) sf("%d", &a[i]) ;
#define bug printf("TRUST\n");
#define pf printf
#define sf scanf
#define lp(i, n) for(int i = 0; i < n; i++)
#define rlp(n, i) for(int i = n - 1; i >= 0; i--)
#define bye vector<LL>
#define pb push_back
#define r0 return 0
#define ff first
#define sc second
#define mp make_pair
#define pii pair <int, int>
#define mod 1000000007
#define nod 200003
int fg;
int cur;
vector <int> add, del;
void func(void)
{
        freopen("input.c","r",stdin);
        freopen("output.c","w",stdout);
}

int vis[10005] ;
vector <int> g[10005] ;
void delEdge(int u, int v){
    for(int i = 0; i < g[u].size(); i++ ){
        if(g[u][i] == v){
        //del.pb(fg);
      //cout << "deleting " << g[u][i] << endl;
        g[u].erase(g[u].begin() + i);
                    //cout << "delete " << i << endl;
            //        cout << "size " << g[y].size() << endl;
        break;
        }
    }
}

int maxEdge(int n){
    int mx = 0, y;
    for(int i = 1; i <= n; i++){
        if(g[i].size() > mx){
            mx = g[i].size();
            y = i;
        }
    }
    return y;
}
//
int count1 = 0;
void dfsCycle (int u, int visited) {
    vis[u] = 1 ;
    for (int i = 0; i < g[u].size() ; i++) {
        int v = g[u][i] ;
        //if(v == cur and co >= 4)fg = 1;//cout << "ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\n";
        //cout << u << " - > " << v << " co " << co << " cur " << cur << " fg " << fg <<  endl;
        if (vis[v]==0){
            dfsCycle (v, u) ;
            count1++;
        }
           // cout << u << " < - " <<  v << " hii\n";
        else if(v != visited and fg == -1){
            fg = 0;
            delEdge(u, v);
            delEdge(v, u);
            del.pb(u);
            del.pb(v);
        //    cout << u << " 88888888888 " << v << endl;
       // if(v == cur)fg = 1;
        }
    }
}

void ad(int u, int n){
    int i;
    for(i = 1; i <= n; i++){
            if(vis[i] == 0){
                //cnt++;
               g[u].pb(i);
           //    cout << i << " fsdf but u " << u << endl;
               g[i].pb(u);
               add.pb(i);
               add.pb(u);
               // b = 1;
                break;
                //cout << "add " << i << endl;
            }
        }
}

int  notVisited(int n){
    for(int i = 1; i <= n; i++){
        if(!vis[i])return i;
    }
    return 0;
}

//void addEdge()
//vector <int> add, del;

int main(){
    LL n, q, i,j = 0, temp, t, k, ans = 0, sum = 0, cnt = 0, m, x, y, mx = 0, mx1 = 0, mn = 10000000000000000, mn1 = 10000000000000000;
    cin >> n;
    for(i = 0; i < n - 1; i++){
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }

    cur = y;
    //cout << y << endl;
    j = 0;
    while(1){
       // memset(vis, 0, sizeof(vis));
        for( i = 1; i <= n; i++){
            memset(vis, 0, sizeof(vis));
            fg = -1;
            dfsCycle(i, i);
            count1 = 0;
            if(fg != -1){
                //fg = 0;
             //   ad(i, n);
                i--;
            }
        }
        while(1){
            memset(vis, 0, sizeof(vis));
            dfsCycle(1, 1);
            int z = notVisited(n);
            if(z){
                g[1].pb(z);
                g[z].pb(1);
                add.pb(1);
                add.pb(z);
            }
            else break;
        }
      //  memset(vis, 0, sizeof(vis));

        if(fg == -1)break;

    }
    int sz = add.size()/ 2;
    cout << sz << endl;
    //cout << del.size() << " ssss "<< endl;
    for(i = 0; i <  sz; i++){
        cout << del[2 *i] << " " << del[2 * i + 1] << " " << add[2 *i] << " " << add[2 *i + 1] << endl;
    }
    //dfsCycle(1, 1);

  // for(i = 1; i <= n ; i++)cout << vis[i] << endl;
    r0;
}


                                                                        /* End. Death. Resurrection.*/

#include<bits/stdc++.h>
using namespace std;
typedef long long LL ;
#define get(a) for( int i = 0; i < n; i++) sf("%d", &a[i]) ;
#define bug printf("TRUST\n");
#define pf printf
#define sf scanf
#define lp(i, n) for(int i = 0; i < n; i++)
#define rlp(n, i) for(int i = n - 1; i >= 0; i--)
#define bye vector<LL>
#define pb push_back
#define r0 return 0
#define ff first
#define sc second
#define mp make_pair
#define pii pair <int, int>
#define mod 1000000007
#define nod 200003
int fg;
int cur;
vector <int> add, del;
void func(void)
{
        freopen("input.c","r",stdin);
        freopen("output.c","w",stdout);
}

int vis[10005] ;
vector <int> g[10005] ;
int tahmid = 0;
void delEdge(int u, int v){
    for(int i = 0; i < g[u].size(); i++ ){
        if(g[u][i] == v){
        //del.pb(fg);
//      cout << "deleting " << g[y][i] << endl;
        g[u].erase(g[u].begin() + i);
                    //cout << "delete " << i << endl;
            //        cout << "size " << g[y].size() << endl;
        break;
        }
    }
}
//
void dfsCycle (int u, int co, int visited) {
    vis[u] = 1 ;
    tahmid = u;
    for (int i = 0; i < g[u].size() ; i++) {
        int v = g[u][i] ;
        //if(v == cur and co >= 4)fg = 1;//cout << "ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\n";
        //cout << u << " - > " << v << " co " << co << " cur " << cur << " fg " << fg <<  endl;
        if (vis[v]==0)
            dfsCycle (v, co + 1, u) ;
           // cout << u << " < - " <<  v << " hii\n";
        else if(v != visited and co >= 3 and fg == -1 ){
            fg = 0;
            delEdge(u, v);
            delEdge(v, u);
            del.pb(u);
            del.pb(v);
            cout << u << " 88888888888 " << v << endl;
       // if(v == cur)fg = 1;
        }
    }
}

//void addEdge()
//vector <int> add, del;

int main(){
    LL n, q, i,j = 0, temp, t, k, ans = 0, sum = 0, cnt = 0, m, x, y, mx = 0, mx1 = 0, mn = 10000000000000000, mn1 = 10000000000000000;
    cin >> n;
    for(i = 0; i < n - 1; i++){
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }
    for(i = 0; i < n; i++){
        if(g[i].size() > mx){
            mx = g[i].size();
            y = i;
        }
    }
    cur = y;
    //cout << y << endl;
    j = 0;
    while(1){
        memset(vis, 0, sizeof(vis));
        fg = -1;
        dfsCycle(y, 1, 1);
        //cout << fg << endl;

       // for( i = 1; i <=n; i++)cout << vis[i] << endl;
        if(fg == -1)break;
        //if(fg != -1){

        //}

        for(i = 1; i <= n; i++){
            if(vis[i] == 0){
                cnt++;
                g[y].pb(i);
                g[i].pb(y);
                add.pb(i);
                //cout << "add " << i << endl;
                break;
            }
        }
        //cout << g[y].size() << " ll\n";
        j++;
    }
    cout << cnt << endl;
    for(i = 0; i < cnt; i++){
        cout << del[2*i] << " " << del[2*i + 1] << " " << y << " " << add[i] << endl;
    }

  //  for(i = 1; i <= n ; i++)cout << vis[i] << endl;
    r0;
}


                                                                        /* End. Death. Resurrection.*/

#include<bits/stdc++.h>
using namespace std;
typedef long long LL ;
#define get(a) for( int i = 0; i < n; i++) sf("%d", &a[i]) ;
#define bug printf("TRUST\n");
#define pf printf
#define sf scanf
#define lp(i, n) for(int i = 0; i < n; i++)
#define rlp(n, i) for(int i = n - 1; i >= 0; i--)
#define bye vector<LL>
#define pb push_back
#define r0 return 0
#define ff first
#define sc second
#define mp make_pair
#define pii pair <int, int>
#define mod 1000000007
#define nod 200003
int fg;
int cur;
void func(void)
{
        freopen("input.c","r",stdin);
        freopen("output.c","w",stdout);
}

int vis[10005] ;
vector <int> g[10005] ;

void dfs (int u) {
    vis[u] = 1 ;
    for (int i = 0; i < g[u].size() ; i++) {
        int v = g[u][i] ;
        if (vis[v]==0)
            dfs (v) ;
    }
}

void dfsCycle (int u, int co) {
    vis[u] = 1 ;
   //char ch = g[u / m][u % m];
   //int co = 0;
   // cout << ch << endl;
    for (int i = 0; i < g[u].size() ; i++) {
        int v = g[u][i] ;
        //co++; //cout << "1 " << g[v/m][v%m] << endl;;
        //if(v == cur and co >= 4)fg = 1;//cout << "ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\n";
        //cout << u << " - > " << v << " co " << co << " cur " << cur << " fg " << fg <<  endl;
        if (vis[v]==0)
            dfsCycle (v, co + 1) ;
           // cout << u << " < - " <<  v << " hii\n";
        if(v == cur and co >= 3 and fg == -1)fg = u;
       // if(v == cur)fg = 1;
    }
}
vector <int> add, del;

int main(){
    LL n, q, i,j = 0, temp, t, k, ans = 0, sum = 0, cnt = 0, m, x, y, mx = 0, mx1 = 0, mn = 10000000000000000, mn1 = 10000000000000000;
    cin >> n;
    for(i = 0; i < n - 1; i++){
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }
    for(i = 0; i < n; i++){
        if(g[i].size() > mx){
            mx = g[i].size();
            y = i;
        }
    }
    cur = y;
    //cout << y << endl;
    j = 0;
    while(j < 3){
        memset(vis, 0, sizeof(vis));
        fg = -1;
        dfsCycle(y, 1);
        //cout << fg << endl;

       // for( i = 1; i <=n; i++)cout << vis[i] << endl;
        if(fg == -1)break;
        if(fg != -1){

            for(i = 0; i < mx; i++ ){
                if(g[y][i] == fg){
                    del.pb(fg);
          //          cout << "deleting " << g[y][i] << endl;
                    g[y].erase(g[y].begin() + i);

                    //cout << "delete " << i << endl;
            //        cout << "size " << g[y].size() << endl;
                    break;
                }
            }

            for(i = 0; i < g[fg].size(); i++ ){
                if(g[fg][i] == y){
              //      cout << "deleting " << g[fg][i] << endl;
                    g[fg].erase(g[fg].begin() + i);

                    //cout << "delete " << i << endl;
                //    cout << "size " << g[fg].size() << endl;
                    break;
                }
            }
        }

        for(i = 1; i <= n; i++){
            if(vis[i] == 0){
                cnt++;
                g[y].pb(i);
                add.pb(i);
                //cout << "add " << i << endl;
                break;
            }
        }
        //cout << g[y].size() << " ll\n";
        j++;
    }
    cout << cnt << endl;
    for(i = 0; i < cnt; i++){
        cout << y << " " << del[i] << " " << y << " " << add[i] << endl;
    }
    r0;
}


                                                                        /* End. Death. Resurrection.*/

#include<bits/stdc++.h>
using namespace std;
typedef long long LL ;
#define get(a) for( int i = 0; i < n; i++) sf("%d", &a[i]) ;
#define bug printf("TRUST\n");
#define pf printf
#define sf scanf
#define lp(i, n) for(int i = 0; i < n; i++)
#define rlp(n, i) for(int i = n - 1; i >= 0; i--)
#define bye vector<LL>
#define pb push_back
#define r0 return 0
#define ff first
#define sc second
#define mp make_pair
#define pii pair <int, int>
#define mod 1000000007
#define nod 200003
int fg;
int cur;
vector <int> add, del;
void func(void)
{
        freopen("input.c","r",stdin);
        freopen("output.c","w",stdout);
}

int vis[10005] ;
vector <int> g[10005] ;
void delEdge(int u, int v){
    for(int i = 0; i < g[u].size(); i++ ){
        if(g[u][i] == v){
        //del.pb(fg);
      //cout << "deleting " << g[u][i] << endl;
        g[u].erase(g[u].begin() + i);
                    //cout << "delete " << i << endl;
            //        cout << "size " << g[y].size() << endl;
        break;
        }
    }
}

int maxEdge(int n){
    int mx = 0, y;
    for(int i = 1; i <= n; i++){
        if(g[i].size() > mx){
            mx = g[i].size();
            y = i;
        }
    }
    return y;
}
//
int count1 = 0;
void dfsCycle (int u, int visited) {
    vis[u] = 1 ;
    for (int i = 0; i < g[u].size() ; i++) {
        int v = g[u][i] ;
        //if(v == cur and co >= 4)fg = 1;//cout << "ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\n";
        //cout << u << " - > " << v << " co " << co << " cur " << cur << " fg " << fg <<  endl;
        if (vis[v]==0){
            dfsCycle (v, u) ;
            count1++;
        }
           // cout << u << " < - " <<  v << " hii\n";
        else if(v != visited and fg == -1){
            fg = 0;
            delEdge(u, v);
            delEdge(v, u);
            del.pb(u);
            del.pb(v);
        //    cout << u << " 88888888888 " << v << endl;
       // if(v == cur)fg = 1;
        }
    }
}

void ad(int u, int n){
    int i;
    for(i = 1; i <= n; i++){
            if(vis[i] == 0){
                //cnt++;
               g[u].pb(i);
           //    cout << i << " fsdf but u " << u << endl;
               g[i].pb(u);
               add.pb(i);
               add.pb(u);
               // b = 1;
                break;
                //cout << "add " << i << endl;
            }
        }
}

//void addEdge()
//vector <int> add, del;

int main(){
    LL n, q, i,j = 0, temp, t, k, ans = 0, sum = 0, cnt = 0, m, x, y, mx = 0, mx1 = 0, mn = 10000000000000000, mn1 = 10000000000000000;
    cin >> n;
    for(i = 0; i < n - 1; i++){
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }

    cur = y;
    //cout << y << endl;
    j = 0;
    while(1){
       // memset(vis, 0, sizeof(vis));
        for( i = 1; i <= n; i++){
            memset(vis, 0, sizeof(vis));
            fg = -1;
            dfsCycle(i, i);
            count1 = 0;
            if(fg != -1){
                //fg = 0;
                ad(i, n);
                i--;
            }
        }
      //  memset(vis, 0, sizeof(vis));

        if(fg == -1)break;

    }
    int sz = add.size()/ 2;
    cout << sz << endl;
    for(i = 0; i <  sz; i++){
        cout << del[2 *i] << " " << del[2 * i + 1] << " " << add[2 *i] << " " << add[2 *i + 1] << endl;
    }
    //dfsCycle(1, 1);

  // for(i = 1; i <= n ; i++)cout << vis[i] << endl;
    r0;
}


                                                                        /* End. Death. Resurrection.*/

#include<bits/stdc++.h>
using namespace std;
typedef long long LL ;
#define pb push_back
#define r0 return 0

int fg;
int cur;
vector <int> add, del;
int vis[10005] ;
vector <int> g[10005] ;
void delEdge(int u, int v){
    for(int i = 0; i < g[u].size(); i++ ){
        if(g[u][i] == v){
        g[u].erase(g[u].begin() + i);
        break;
        }
    }
}

int count1 = 0;
void dfsCycle (int u, int visited) {
    vis[u] = 1 ;
    for (int i = 0; i < g[u].size() ; i++) {
        int v = g[u][i] ;
        if (vis[v]==0){
            dfsCycle (v, u) ;
            count1++;
        }
        else if(v != visited and fg == -1){
            fg = 0;
            delEdge(u, v);
            delEdge(v, u);
            del.pb(u);
            del.pb(v);
        }
    }
}

int  notVisited(int n){
    for(int i = 1; i <= n; i++){
        if(!vis[i])return i;
    }
    return 0;
}

int main(){
    LL n, q, i,j = 0, temp, t, k, ans = 0, sum = 0, cnt = 0, m, x, y, mx = 0, mx1 = 0, mn = 10000000000000000, mn1 = 10000000000000000;
    cin >> n;
    for(i = 0; i < n - 1; i++){
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }
    while(1){
        for( i = 1; i <= n; i++){
            memset(vis, 0, sizeof(vis));
            fg = -1;
            dfsCycle(i, i);
            count1 = 0;
            if(fg != -1){
                i--;
            }
        }
        while(1){
            memset(vis, 0, sizeof(vis));
            dfsCycle(1, 1);
            int z = notVisited(n);
            if(z){
                g[1].pb(z);
                g[z].pb(1);
                add.pb(1);
                add.pb(z);
            }
            else break;
        }
        if(fg == -1)break;

    }
    int sz = add.size()/ 2;
    cout << sz << endl;
    for(i = 0; i <  sz; i++){
        cout << del[2 *i] << " " << del[2 * i + 1] << " " << add[2 *i] << " " << add[2 *i + 1] << endl;
    }
    r0;
}


                                                                        /* End. Death. Resurrection.*/

#include<bits/stdc++.h>
using namespace std;
typedef long long LL ;
#define get(a) for( int i = 0; i < n; i++) sf("%d", &a[i]) ;
#define bug printf("TRUST\n");
#define pf printf
#define sf scanf
#define lp(i, n) for(int i = 0; i < n; i++)
#define rlp(n, i) for(int i = n - 1; i >= 0; i--)
#define bye vector<LL>
#define pb push_back
#define r0 return 0
#define ff first
#define sc second
#define mp make_pair
#define pii pair <int, int>
#define mod 1000000007
#define nod 200003
int fg;
int cur;
vector <int> add, del;
void func(void)
{
        freopen("input.c","r",stdin);
        freopen("output.c","w",stdout);
}

int vis[10005] ;
vector <int> g[10005] ;
int tahmid = 0;
void delEdge(int u, int v){
    for(int i = 0; i < g[u].size(); i++ ){
        if(g[u][i] == v){
        //del.pb(fg);
//      cout << "deleting " << g[y][i] << endl;
        g[u].erase(g[u].begin() + i);
                    //cout << "delete " << i << endl;
            //        cout << "size " << g[y].size() << endl;
        break;
        }
    }
}
//
void dfsCycle (int u, int co, int visited) {
    vis[u] = 1 ;
    tahmid = u;
    for (int i = 0; i < g[u].size() ; i++) {
        int v = g[u][i] ;
        //if(v == cur and co >= 4)fg = 1;//cout << "ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\n";
        //cout << u << " - > " << v << " co " << co << " cur " << cur << " fg " << fg <<  endl;
        if (vis[v]==0)
            dfsCycle (v, co + 1, u) ;
           // cout << u << " < - " <<  v << " hii\n";
        else if(v != visited and co >= 3 and fg == -1 ){
            fg = 0;
            delEdge(u, v);
            delEdge(v, u);
            del.pb(u);
            del.pb(v);
           // cout << u << " 88888888888 " << v << endl;
       // if(v == cur)fg = 1;
        }
    }
}

//void addEdge()
//vector <int> add, del;

int main(){
    LL n, q, i,j = 0, temp, t, k, ans = 0, sum = 0, cnt = 0, m, x, y, mx = 0, mx1 = 0, mn = 10000000000000000, mn1 = 10000000000000000;
    cin >> n;
    for(i = 0; i < n - 1; i++){
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }
    for(i = 0; i < n; i++){
        if(g[i].size() > mx){
            mx = g[i].size();
            y = i;
        }
    }
    cur = y;
    //cout << y << endl;
    j = 0;
    while(1){
        memset(vis, 0, sizeof(vis));
        fg = -1;
        dfsCycle(y, 1, 1);
        //cout << fg << endl;

       // for( i = 1; i <=n; i++)cout << vis[i] << endl;
        if(fg == -1)break;
        //if(fg != -1){

        //}

        for(i = 1; i <= n; i++){
            if(vis[i] == 0){
                cnt++;
                g[y].pb(i);
                g[i].pb(y);
                add.pb(i);
                //cout << "add " << i << endl;
                break;
            }
        }
        //cout << g[y].size() << " ll\n";
        j++;
    }
    cout << cnt << endl;
    for(i = 0; i < cnt; i++){
        cout << del[2*i] << " " << del[2*i + 1] << " " << y << " " << add[i] << endl;
    }

  //  for(i = 1; i <= n ; i++)cout << vis[i] << endl;
    r0;
}


                                                                       /* End. Death. Resurrection.*/

#include<bits/stdc++.h>
using namespace std;
typedef long long LL ;
#define get(a) for( int i = 0; i < n; i++) sf("%d", &a[i]) ;
#define bug printf("TRUST\n");
#define pf printf
#define sf scanf
#define lp(i, n) for(int i = 0; i < n; i++)
#define rlp(n, i) for(int i = n - 1; i >= 0; i--)
#define bye vector<LL>
#define pb push_back
#define r0 return 0
#define ff first
#define sc second
#define mp make_pair
#define pii pair <int, int>
#define mod 1000000007
#define nod 200003
int fg;
int cur;
vector <int> add, del;
void func(void)
{
        freopen("input.c","r",stdin);
        freopen("output.c","w",stdout);
}

int vis[10005] ;
vector <int> g[10005] ;
void delEdge(int u, int v){
    for(int i = 0; i < g[u].size(); i++ ){
        if(g[u][i] == v){
        //del.pb(fg);
      //cout << "deleting " << g[u][i] << endl;
        g[u].erase(g[u].begin() + i);
                    //cout << "delete " << i << endl;
            //        cout << "size " << g[y].size() << endl;
        break;
        }
    }
}

int maxEdge(int n){
    int mx = 0, y;
    for(int i = 1; i <= n; i++){
        if(g[i].size() > mx){
            mx = g[i].size();
            y = i;
        }
    }
    return y;
}
//
int count1 = 0;
void dfsCycle (int u, int visited) {
    vis[u] = 1 ;
    for (int i = 0; i < g[u].size() ; i++) {
        int v = g[u][i] ;
        //if(v == cur and co >= 4)fg = 1;//cout << "ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\n";
        //cout << u << " - > " << v << " co " << co << " cur " << cur << " fg " << fg <<  endl;
        if (vis[v]==0){
            dfsCycle (v, u) ;
            count1++;
        }
           // cout << u << " < - " <<  v << " hii\n";
        else if(v != visited and fg == -1){
            fg = 0;
            delEdge(u, v);
            delEdge(v, u);
            del.pb(u);
            del.pb(v);
        //    cout << u << " 88888888888 " << v << endl;
       // if(v == cur)fg = 1;
        }
    }
}

void ad(int u, int n){
    int i;
    for(i = 1; i <= n; i++){
            if(vis[i] == 0){
                //cnt++;
               g[u].pb(i);
           //    cout << i << " fsdf but u " << u << endl;
               g[i].pb(u);
               add.pb(i);
               add.pb(u);
               // b = 1;
                break;
                //cout << "add " << i << endl;
            }
        }
}

//void addEdge()
//vector <int> add, del;

int main(){
    LL n, q, i,j = 0, temp, t, k, ans = 0, sum = 0, cnt = 0, m, x, y, mx = 0, mx1 = 0, mn = 10000000000000000, mn1 = 10000000000000000;
    cin >> n;
    for(i = 0; i < n - 1; i++){
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }

    cur = y;
    //cout << y << endl;
    j = 0;
    while(1){
       // memset(vis, 0, sizeof(vis));
        for( i = 1; i <= n; i++){
            memset(vis, 0, sizeof(vis));
            fg = -1;
            dfsCycle(i, i);
            count1 = 0;
            if(fg != -1){
                //fg = 0;
                ad(i, n);
                i--;
            }
        }
      //  memset(vis, 0, sizeof(vis));

        if(fg == -1)break;

    }
    int sz = add.size()/ 2;
    cout << sz << endl;
    if(n == 100)cout << del.size() << endl;
    for(i = 0; i <  sz; i++){
        cout << del[2 *i] << " " << del[2 * i + 1] << " " << add[2 *i] << " " << add[2 *i + 1] << endl;
    }
    //dfsCycle(1, 1);

  // for(i = 1; i <= n ; i++)cout << vis[i] << endl;
    r0;
}


#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> pii;

const int N = 1e5 + 10;
int n, x, m, tmp, ans, k, t;
int a[N], b[N], h[N], par[N];
vector <pii> p;
vector<int> nei[N];
bool mark[N];
vector <int> g;
vector <int> j;

int getpar(int v) {
	if (v == par[v])
		return v;
	par[v] = getpar(par[v]);
	return par[v];
}

void read_input() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		par[i] = i;
	}
	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		if (getpar(v) == getpar(u)) {
			p.pb({u, v});
		}
		else {
			par[getpar(v)] = getpar(u);
		}
	}
}

int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	read_input();
/*	for (int i = 1; i <= n; i++) {
		cout << par[i] << ' ';
	}*/
/*	cout << '\n';
	for (int i = 0; i < p.size(); i++) {
		cout << p[i].first << ' ' << p[i].second;
	}*/
	for (int i = 1; i <= n; i++) {
		g.pb(par[i]);
	}
	sort(g.begin(), g.end());
	j.pb(g[0]);
	for (int i = 1; i < g.size(); i++) {
		if (g[i] != g[i - 1])
			j.pb(g[i]);
	}
	if (p.size() == 0)
		cout << 0;
	else {
		cout << p.size() << '\n';
		for (int i = 0; i < p.size(); i++) {
			cout << p[i].first << ' ' << p[i].second << ' ' << j[0] << ' ' << j[i + 1];
		}
	}
//	cout << '\n';
/*	for (int i = 0; i < j.size(); i++)
		cout << j[i] << ' ';*/
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> pii;

const int N = 1e5 + 10;
int n, x, m, tmp, ans, k, t;
int a[N], b[N], h[N], par[N];
vector <pii> p;
vector<int> nei[N];
bool mark[N];
vector <int> g;
vector <int> j;

int getpar(int v) {
	if (v == par[v])
		return v;
	par[v] = getpar(par[v]);
	return par[v];
}

void read_input() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		par[i] = i;
	}
	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		if (getpar(v) == getpar(u)) {
			p.pb({u, v});
		}
		else {
			par[getpar(v)] = getpar(u);
		}
	}
}

int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	read_input();
/*	for (int i = 1; i <= n; i++) {
		cout << par[i] << ' ';
	}*/
/*	cout << '\n';
	for (int i = 0; i < p.size(); i++) {
		cout << p[i].first << ' ' << p[i].second;
	}*/
	for (int i = 1; i <= n; i++) {
		g.pb(par[i]);
	}
	sort(g.begin(), g.end());
	j.pb(g[0]);
	for (int i = 1; i < g.size(); i++) {
		if (g[i] != g[i - 1])
			j.pb(g[i]);
	}
	if (p.size() == 0)
		cout << 0;
	else {
		cout << p.size() << '\n';
		for (int i = 0; i < p.size(); i++) {
			cout << p[i].first << ' ' << p[i].second << ' ' << j[0] << ' ' << j[i + 1] << '\n';
		}
	}
//	cout << '\n';
/*	for (int i = 0; i < j.size(); i++)
		cout << j[i] << ' ';*/
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> pii;

const int N = 1e5 + 10;
int n, x, m, tmp, ans, k, t;
int a[N], b[N], h[N], par[N];
vector <pii> p;
vector<int> nei[N];
bool mark[N];
vector <int> g;
vector <int> j;

int getpar(int v) {
	if (v == par[v])
		return v;
	par[v] = getpar(par[v]);
	return par[v];
}

void read_input() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		par[i] = i;
	}
	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		if (getpar(v) == getpar(u)) {
			p.pb({u, v});
		}
		else {
			par[getpar(v)] = getpar(u);
		}
	}
}

int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	read_input();
/*	for (int i = 1; i <= n; i++) {
		cout << par[i] << ' ';
	}*/
/*	cout << '\n';
	for (int i = 0; i < p.size(); i++) {
		cout << p[i].first << ' ' << p[i].second;
	}*/
	for (int i = 1; i <= n; i++) {
		if (i == par[i]) {
			j.pb(i);
		}
	}
	cout << j.size() - 1 << '\n';
	for (int i = 0; i < p.size(); i++) {
		cout << p[i].fi << ' ' << p[i].se << ' ' << j.back() << ' ' << j[0] << '\n';
		j.pop_back();
	}
//	cout << '\n';
/*	for (int i = 0; i < j.size(); i++)
		cout << j[i] << ' ';*/
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> pii;

const int N = 1e5 + 10;
int n, x, m, tmp, ans, k, t;
int a[N], b[N], h[N], par[N];
vector <pii> p;
vector<int> nei[N];
bool mark[N];
vector <int> g;
vector <int> j;

int getpar(int v) {
	if (v == par[v])
		return v;
	par[v] = getpar(par[v]);
	return par[v];
}

void read_input() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		par[i] = i;
	}
	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		if (getpar(v) == getpar(u)) {
			p.pb({u, v});
		}
		else {
			par[getpar(v)] = getpar(u);
		}
	}
}

int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	read_input();
/*	for (int i = 1; i <= n; i++) {
		cout << par[i] << ' ';
	}*/
/*	cout << '\n';
	for (int i = 0; i < p.size(); i++) {
		cout << p[i].first << ' ' << p[i].second;
	}*/
	for (int i = 1; i <= n; i++) {
		g.pb(par[i]);
	}
	sort(g.begin(), g.end());
	j.pb(g[0]);
	for (int i = 1; i < g.size(); i++) {
		if (g[i] != g[i - 1])
			j.pb(g[i]);
	}
	if (p.size() == 0)
		cout << 0;
	else {
		cout << p.size() << '\n';
		for (int i = 0; i < p.size(); i++) {
			cout << p[i].first << ' ' << p[i].second << ' ' << j[0] << ' ' << j.back() << '\n';
			j.pop_back();
		}
	}
//	cout << '\n';
/*	for (int i = 0; i < j.size(); i++)
		cout << j[i] << ' ';*/
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> pii;

const int N = 1e5 + 10;
int n, x, m, tmp, ans, k, t;
int a[N], b[N], h[N], par[N];
vector <pii> p;
vector<int> nei[N];
bool mark[N];
vector <int> g;
vector <int> j;

int getpar(int v) {
	if (v == par[v])
		return v;
	par[v] = getpar(par[v]);
	return par[v];
}

void read_input() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		par[i] = i;
	}
	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		if (getpar(v) == getpar(u)) {
			p.pb({u, v});
		}
		else {
			par[getpar(v)] = getpar(u);
		}
	}
}

int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	read_input();
/*	for (int i = 1; i <= n; i++) {
		cout << par[i] << ' ';
	}*/
/*	cout << '\n';
	for (int i = 0; i < p.size(); i++) {
		cout << p[i].first << ' ' << p[i].second;
	}*/
	for (int i = 1; i <= n; i++) {
		g.pb(par[i]);
	}
	sort(g.begin(), g.end());
	j.pb(g[0]);
	for (int i = 1; i < g.size(); i++) {
		if (g[i] != g[i - 1])
			j.pb(g[i]);
	}
	if (p.size() == 0)
		cout << 0;
	else {
		for (int i = 0; i < p.size(); i++) {
			cout << p[i].first << ' ' << p[i].second << ' ' << j[0] << ' ' << j[i + 1];
		}
	}
//	cout << '\n';
/*	for (int i = 0; i < j.size(); i++)
		cout << j[i] << ' ';*/
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> pii;

const int N = 1e5 + 10;
int n, x, m, tmp, ans, k, t;
int a[N], b[N], h[N], par[N];
vector <pii> p;
vector<int> nei[N];
bool mark[N];
vector <int> g;
vector <int> j;

int getpar(int v) {
	if (v == par[v])
		return v;
	par[v] = getpar(par[v]);
	return par[v];
}

void read_input() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		par[i] = i;
	}
	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		if (getpar(v) == getpar(u)) {
			p.pb({u, v});
		}
		else {
			par[getpar(v)] = getpar(u);
		}
	}
}

int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	read_input();
/*	for (int i = 1; i <= n; i++) {
		cout << par[i] << ' ';
	}*/
/*	cout << '\n';
	for (int i = 0; i < p.size(); i++) {
		cout << p[i].first << ' ' << p[i].second;
	}*/
	for (int i = 1; i <= n; i++) {
		g.pb(getpar(i));
	}
	sort(g.begin(), g.end());
	j.pb(g[0]);
	for (int i = 1; i < g.size(); i++) {
		if (g[i] != g[i - 1])
			j.pb(g[i]);
	}
	if (p.size() == 0)
		cout << 0;
	else {
		cout << p.size() << '\n';
		for (int i = 0; i < p.size(); i++) {
			cout << p[i].first << ' ' << p[i].second << ' ' << j[0] << ' ' << j.back() << '\n';
			j.pop_back();
		}
	}
//	cout << '\n';
/*	for (int i = 0; i < j.size(); i++)
		cout << j[i] << ' ';*/
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> pii;

const int N = 1e5 + 10;
int n, x, m, tmp, ans, k, t;
int a[N], b[N], h[N], par[N];
vector <pii> p;
vector<int> nei[N];
bool mark[N];
vector <int> g;
vector <int> j;

int getpar(int v) {
	if (v == par[v])
		return v;
	par[v] = getpar(par[v]);
	return par[v];
}

void read_input() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		par[i] = i;
	}
	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		if (getpar(v) == getpar(u)) {
			p.pb({u, v});
		}
		else {
			par[getpar(v)] = getpar(u);
		}
	}
}

int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	read_input();
/*	for (int i = 1; i <= n; i++) {
		cout << par[i] << ' ';
	}*/
/*	cout << '\n';
	for (int i = 0; i < p.size(); i++) {
		cout << p[i].first << ' ' << p[i].second;
	}*/
	for (int i = 1; i <= n; i++) {
		g.pb(par[i]);
	}
	sort(g.begin(), g.end());
	j.pb(g[0]);
	for (int i = 1; i < g.size(); i++) {
		if (g[i] != g[i - 1])
			j.pb(g[i]);
	}
	for (int i = 0; i < p.size(); i++) {
		cout << p[i].first << ' ' << p[i].second << ' ' << j[0] << ' ' << j[i + 1];
	}
//	cout << '\n';
/*	for (int i = 0; i < j.size(); i++)
		cout << j[i] << ' ';*/
	return 0;
}


/***"In the name of Allah(swt), the most gracious, most merciful. Allah(swt) blesses with knowledge whom he wants."***/
/*** "ALHAMDULILLAH for Everything..." ***/
#include<bits/stdc++.h>
using namespace std;
#define  fastt       ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define  ll         long long
#define  pb         push_back
#define  mp         make_pair
#define  sz(a)      a.size()
#define  mem(a,b)   memset(a,b,sizeof(a))
#define  clr(x)     x.clear()
#define  ff         first
#define  ss         second
#define  case(x)    cout << "Case " << x <<": "

#define  md         (ll)1e9+7
#define  pi         acos(-1.0)
#define  cos(a)     cos(a*pi/180)
#define  sin(a)     sin(a*pi/180)
#define  tan(a)     tan(a*pi/180)
#define  cosi(a)    acos(a)/(pi/180)
#define  sini(a)    asin(a)/(pi/180)
#define  tani(a)    atan(a)/(pi/180)

#define  vi         vector <int>
#define  vl         vector <ll>
#define  vs         vector <string>
#define  vc         vector <char>
#define  vpii       vector < pair <int, int> >
#define  vpll       vector < pair <ll, ll> >
#define  vpsi       vector < pair <string, int> >
#define  vpis       vector < pair <int, string> >
#define  vpsl       vector < pair <string, ll> >
#define  vpls       vector < pair <ll, string> >

#define  pqi        priority_queue<int>
#define  pql        priority_queue<ll>
#define  minpqi     priority_queue<int,vector<int>,greater<int> >
#define  minpql     priority_queue<ll,vector<ll>,greater<ll> >

#define toint(a) atoll(a.c_str())
string tostr(int a) {stringstream rr;rr<<a;return rr.str();}
ll pow(ll c,ll d){return d==0?:c*pow(c,d-1);}
ll gcd(ll a,ll b) {return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b) {return ((a*b)/gcd(a,b));}

/* for unordered map: mpp.max_load_factor(0.25); mpp.reserve(1024); */
/* cout << fixed << setprecision(12);*/
int p[10005], r[10005], vis[10005];
vector<pair<int, int> >v, v1;

int findd(int x)
{
    if(x!=p[x]) p[x]=findd(p[x]);
    return p[x];
}

void uniono(int x, int y)
{
    int a, b;
    a=findd(x);
    b=findd(y);
    if(a==b){
        v.pb(mp(x, y));
    }
    if(r[a]<r[b]){
        p[a]=b;
    }
    else{
        p[b]=a;
        if(r[a]==r[b])r[a]++;
    }
}
int main()
{
    fastt;
    int n, i, j, k, l, x, y;
    cin>>n;
    for(i=1; i<=n; i++){
        p[i]=i;
        r[i]=1;
        vis[i]=0;
    }
    for(i=1; i<n; i++){
        cin>>k>>l;
        uniono(k, l);
    }
    x=p[1];
    vis[x]=1;

    for(i=2; i<=n; i++){
        x=p[i];
        if(vis[x]==0){
            v1.pb(mp(1, i));
        }
        vis[x]=1;
    }
    cout<<v1.size()<<endl;
    for(i=0; i<v1.size(); i++){
        cout<<v[i].ff<<" "<<v[i].ss<<" "<<v1[i].ff<<" "<<v1[i].ss<<endl;
    }
    return 0;
}


/***"In the name of Allah(swt), the most gracious, most merciful. Allah(swt) blesses with knowledge whom he wants."***/
/*** "ALHAMDULILLAH for Everything..." ***/
#include<bits/stdc++.h>
using namespace std;
#define  fastt       ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define  ll         long long
#define  pb         push_back
#define  mp         make_pair
#define  sz(a)      a.size()
#define  mem(a,b)   memset(a,b,sizeof(a))
#define  clr(x)     x.clear()
#define  ff         first
#define  ss         second
#define  case(x)    cout << "Case " << x <<": "

#define  md         (ll)1e9+7
#define  pi         acos(-1.0)
#define  cos(a)     cos(a*pi/180)
#define  sin(a)     sin(a*pi/180)
#define  tan(a)     tan(a*pi/180)
#define  cosi(a)    acos(a)/(pi/180)
#define  sini(a)    asin(a)/(pi/180)
#define  tani(a)    atan(a)/(pi/180)

#define  vi         vector <int>
#define  vl         vector <ll>
#define  vs         vector <string>
#define  vc         vector <char>
#define  vpii       vector < pair <int, int> >
#define  vpll       vector < pair <ll, ll> >
#define  vpsi       vector < pair <string, int> >
#define  vpis       vector < pair <int, string> >
#define  vpsl       vector < pair <string, ll> >
#define  vpls       vector < pair <ll, string> >

#define  pqi        priority_queue<int>
#define  pql        priority_queue<ll>
#define  minpqi     priority_queue<int,vector<int>,greater<int> >
#define  minpql     priority_queue<ll,vector<ll>,greater<ll> >

#define toint(a) atoll(a.c_str())
string tostr(int a) {stringstream rr;rr<<a;return rr.str();}
ll pow(ll c,ll d){return d==0?:c*pow(c,d-1);}
ll gcd(ll a,ll b) {return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b) {return ((a*b)/gcd(a,b));}

/* for unordered map: mpp.max_load_factor(0.25); mpp.reserve(1024); */
/* cout << fixed << setprecision(12);*/
int p[10005], r[10005], vis[10005];
vector<pair<int, int> >v, v1;

int findd(int x)
{
    if(x!=p[x]) p[x]=findd(p[x]);
    return p[x];
}

void uniono(int x, int y)
{
    int a, b;
    a=findd(x);
    b=findd(y);
    if(r[a]<r[b]){
        p[a]=b;
    }
    else{
        p[b]=a;
        if(r[a]==r[b])r[a]++;
    }
}
int main()
{
    fastt;
    int n, i, j, k, l, x, y;
    cin>>n;
    for(i=1; i<=n; i++){
        p[i]=i;
        r[i]=1;
        vis[i]=0;
    }
    for(i=1; i<n; i++){
        cin>>k>>l;
        x=findd(k);
        y=findd(l);
        if(x==y){
            v.pb(mp(k, l));
        }
        else{
            uniono(x, y);
        }
    }
    x=p[1];
    vis[x]=1;

    for(i=2; i<=n; i++){
        x=p[i];
        //cout<<p[i]<<" ";
        if(vis[x]==0){
            v1.pb(mp(1, i));
        }
        vis[x]=1;
    }
    int hh=min(v.size(), v1.size());
    cout<<hh<<endl;
    for(i=0; i<hh; i++){
        cout<<v[i].ff<<" "<<v[i].ss<<" "<<v1[i].ff<<" "<<v1[i].ss<<endl;
    }
    return 0;
}


/***"In the name of Allah(swt), the most gracious, most merciful. Allah(swt) blesses with knowledge whom he wants."***/
/*** "ALHAMDULILLAH for Everything..." ***/
#include<bits/stdc++.h>
using namespace std;
#define  fastt       ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define  ll         long long
#define  pb         push_back
#define  mp         make_pair
#define  sz(a)      a.size()
#define  mem(a,b)   memset(a,b,sizeof(a))
#define  clr(x)     x.clear()
#define  ff         first
#define  ss         second
#define  case(x)    cout << "Case " << x <<": "

#define  md         (ll)1e9+7
#define  pi         acos(-1.0)
#define  cos(a)     cos(a*pi/180)
#define  sin(a)     sin(a*pi/180)
#define  tan(a)     tan(a*pi/180)
#define  cosi(a)    acos(a)/(pi/180)
#define  sini(a)    asin(a)/(pi/180)
#define  tani(a)    atan(a)/(pi/180)

#define  vi         vector <int>
#define  vl         vector <ll>
#define  vs         vector <string>
#define  vc         vector <char>
#define  vpii       vector < pair <int, int> >
#define  vpll       vector < pair <ll, ll> >
#define  vpsi       vector < pair <string, int> >
#define  vpis       vector < pair <int, string> >
#define  vpsl       vector < pair <string, ll> >
#define  vpls       vector < pair <ll, string> >

#define  pqi        priority_queue<int>
#define  pql        priority_queue<ll>
#define  minpqi     priority_queue<int,vector<int>,greater<int> >
#define  minpql     priority_queue<ll,vector<ll>,greater<ll> >

#define toint(a) atoll(a.c_str())
string tostr(int a) {stringstream rr;rr<<a;return rr.str();}
ll pow(ll c,ll d){return d==0?:c*pow(c,d-1);}
ll gcd(ll a,ll b) {return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b) {return ((a*b)/gcd(a,b));}

/* for unordered map: mpp.max_load_factor(0.25); mpp.reserve(1024); */
/* cout << fixed << setprecision(12);*/

int p[10005], s[10005], vis[10005];
vector<pair<int, int> >v, v1;

int findd(int x)
{
    if(x!=p[x]) p[x]=findd(p[x]);
    return p[x];
}

void uniono(int x, int y)
{
    int a, b;
    a=findd(x);
    b=findd(y);
    if(a!=b){
        if(s[a]<s[b]){
            swap(a, b);
        }
        s[a]+=s[b];
        p[b]=a;
        //cout<<p[b]<<endl;
    }
}
int main()
{
    fastt;
    int n, i, j, k, l, x, y;
    cin>>n;
    for(i=1; i<=n; i++){
        p[i]=i;
        s[i]=1;
        vis[i]=0;
    }
    for(i=1; i<n; i++){
        cin>>k>>l;
        x=findd(k);
        y=findd(l);
        if(x==y){
            v.pb(mp(k, l));
        }
        else{
            uniono(k, l);
        }
    }
    for(i=1; i<n; i++){
        for(j=1; j<i; j++){
            x=findd(j);
            y=findd(i);
            if(x!=y){
                v1.pb(mp(j, i));
                uniono(j, i);
            }
        }
    }

    cout<<v.size()<<endl;
    for(i=0; i<v.size(); i++){
        cout<<v[i].ff<<" "<<v[i].ss<<" "<<v1[i].ff<<" "<<v1[i].ss<<endl;
    }
    return 0;
}


/***"In the name of Allah(swt), the most gracious, most merciful. Allah(swt) blesses with knowledge whom he wants."***/
/*** "ALHAMDULILLAH for Everything..." ***/
#include<bits/stdc++.h>
using namespace std;
#define  fastt       ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define  ll         long long
#define  pb         push_back
#define  mp         make_pair
#define  sz(a)      a.size()
#define  mem(a,b)   memset(a,b,sizeof(a))
#define  clr(x)     x.clear()
#define  ff         first
#define  ss         second
#define  case(x)    cout << "Case " << x <<": "

#define  md         (ll)1e9+7
#define  pi         acos(-1.0)
#define  cos(a)     cos(a*pi/180)
#define  sin(a)     sin(a*pi/180)
#define  tan(a)     tan(a*pi/180)
#define  cosi(a)    acos(a)/(pi/180)
#define  sini(a)    asin(a)/(pi/180)
#define  tani(a)    atan(a)/(pi/180)

#define  vi         vector <int>
#define  vl         vector <ll>
#define  vs         vector <string>
#define  vc         vector <char>
#define  vpii       vector < pair <int, int> >
#define  vpll       vector < pair <ll, ll> >
#define  vpsi       vector < pair <string, int> >
#define  vpis       vector < pair <int, string> >
#define  vpsl       vector < pair <string, ll> >
#define  vpls       vector < pair <ll, string> >

#define  pqi        priority_queue<int>
#define  pql        priority_queue<ll>
#define  minpqi     priority_queue<int,vector<int>,greater<int> >
#define  minpql     priority_queue<ll,vector<ll>,greater<ll> >

#define toint(a) atoll(a.c_str())
string tostr(int a) {stringstream rr;rr<<a;return rr.str();}
ll pow(ll c,ll d){return d==0?:c*pow(c,d-1);}
ll gcd(ll a,ll b) {return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b) {return ((a*b)/gcd(a,b));}

/* for unordered map: mpp.max_load_factor(0.25); mpp.reserve(1024); */
/* cout << fixed << setprecision(12);*/
int p[10005], s[10005], vis[10005];
vector<pair<int, int> >v, v1;

int findd(int x)
{
    if(x!=p[x]) p[x]=findd(p[x]);
    return p[x];
}

void uniono(int x, int y)
{
    int a, b;
    a=findd(x);
    b=findd(y);
    if(a!=b){
        if(s[a]<s[b]){
            swap(a, b);
        }
        s[a]+=s[b];
        p[b]=a;
        //cout<<p[b]<<endl;
    }
}
int main()
{
    fastt;
    int n, i, j, k, l, x, y;
    cin>>n;
    for(i=1; i<=n; i++){
        p[i]=i;
        s[i]=1;
        vis[i]=0;
    }
    for(i=1; i<n; i++){
        cin>>k>>l;
        x=findd(k);
        y=findd(l);
        if(x==y){
            v.pb(mp(k, l));
        }
        else{
            uniono(k, l);
        }
    }
    x=p[1];
    vis[x]=1;

    for(i=2; i<=n; i++){
        x=p[i];
        //cout<<p[i]<<" ";
        if(vis[x]==0){
            v1.pb(mp(1, i));
        }
        vis[x]=1;
    }
    int hh=min(v.size(), v1.size());
    cout<<hh<<endl;
    for(i=0; i<hh; i++){
        cout<<v[i].ff<<" "<<v[i].ss<<" "<<v1[i].ff<<" "<<v1[i].ss<<endl;
    }
    return 0;
}


/***"In the name of Allah(swt), the most gracious, most merciful. Allah(swt) blesses with knowledge whom he wants."***/
/*** "ALHAMDULILLAH for Everything..." ***/
#include<bits/stdc++.h>
using namespace std;
#define  fastt       ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define  ll         long long
#define  pb         push_back
#define  mp         make_pair
#define  sz(a)      a.size()
#define  mem(a,b)   memset(a,b,sizeof(a))
#define  clr(x)     x.clear()
#define  ff         first
#define  ss         second
#define  case(x)    cout << "Case " << x <<": "

#define  md         (ll)1e9+7
#define  pi         acos(-1.0)
#define  cos(a)     cos(a*pi/180)
#define  sin(a)     sin(a*pi/180)
#define  tan(a)     tan(a*pi/180)
#define  cosi(a)    acos(a)/(pi/180)
#define  sini(a)    asin(a)/(pi/180)
#define  tani(a)    atan(a)/(pi/180)

#define  vi         vector <int>
#define  vl         vector <ll>
#define  vs         vector <string>
#define  vc         vector <char>
#define  vpii       vector < pair <int, int> >
#define  vpll       vector < pair <ll, ll> >
#define  vpsi       vector < pair <string, int> >
#define  vpis       vector < pair <int, string> >
#define  vpsl       vector < pair <string, ll> >
#define  vpls       vector < pair <ll, string> >

#define  pqi        priority_queue<int>
#define  pql        priority_queue<ll>
#define  minpqi     priority_queue<int,vector<int>,greater<int> >
#define  minpql     priority_queue<ll,vector<ll>,greater<ll> >

#define toint(a) atoll(a.c_str())
string tostr(int a) {stringstream rr;rr<<a;return rr.str();}
ll pow(ll c,ll d){return d==0?:c*pow(c,d-1);}
ll gcd(ll a,ll b) {return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b) {return ((a*b)/gcd(a,b));}

/* for unordered map: mpp.max_load_factor(0.25); mpp.reserve(1024); */
/* cout << fixed << setprecision(12);*/

int p[10005], s[10005], vis[10005];
vector<pair<int, int> >v, v1;

int findd(int x)
{
    if(x!=p[x]) p[x]=findd(p[x]);
    return p[x];
}

void uniono(int x, int y)
{
    int a, b;
    a=findd(x);
    b=findd(y);
    if(a!=b){
        if(s[a]<s[b]){
            swap(a, b);
        }
        s[a]+=s[b];
        p[b]=a;
        //cout<<p[b]<<endl;
    }
}
int main()
{
    fastt;
    int n, i, j, k, l, x, y;
    cin>>n;
    for(i=1; i<=n; i++){
        p[i]=i;
        s[i]=1;
        vis[i]=0;
    }
    for(i=1; i<n; i++){
        cin>>k>>l;
        x=findd(k);
        y=findd(l);
        if(x==y){
            v.pb(mp(k, l));
        }
        else{
            uniono(k, l);
        }
    }
    for(i=2; i<=n; i++){
        for(j=1; j<i; j++){
            x=findd(j);
            y=findd(i);
            if(x!=y){
                v1.pb(mp(j, i));
                uniono(j, i);
            }
        }
    }

    cout<<v.size()<<endl;
    for(i=0; i<v.size(); i++){
        cout<<v[i].ff<<" "<<v[i].ss<<" "<<v1[i].ff<<" "<<v1[i].ss<<endl;
    }
    return 0;
}


/***"In the name of Allah(swt), the most gracious, most merciful. Allah(swt) blesses with knowledge whom he wants."***/
/*** "ALHAMDULILLAH for Everything..." ***/
#include<bits/stdc++.h>
using namespace std;
#define  fastt       ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define  ll         long long
#define  pb         push_back
#define  mp         make_pair
#define  sz(a)      a.size()
#define  mem(a,b)   memset(a,b,sizeof(a))
#define  clr(x)     x.clear()
#define  ff         first
#define  ss         second
#define  case(x)    cout << "Case " << x <<": "

#define  md         (ll)1e9+7
#define  pi         acos(-1.0)
#define  cos(a)     cos(a*pi/180)
#define  sin(a)     sin(a*pi/180)
#define  tan(a)     tan(a*pi/180)
#define  cosi(a)    acos(a)/(pi/180)
#define  sini(a)    asin(a)/(pi/180)
#define  tani(a)    atan(a)/(pi/180)

#define  vi         vector <int>
#define  vl         vector <ll>
#define  vs         vector <string>
#define  vc         vector <char>
#define  vpii       vector < pair <int, int> >
#define  vpll       vector < pair <ll, ll> >
#define  vpsi       vector < pair <string, int> >
#define  vpis       vector < pair <int, string> >
#define  vpsl       vector < pair <string, ll> >
#define  vpls       vector < pair <ll, string> >

#define  pqi        priority_queue<int>
#define  pql        priority_queue<ll>
#define  minpqi     priority_queue<int,vector<int>,greater<int> >
#define  minpql     priority_queue<ll,vector<ll>,greater<ll> >

#define toint(a) atoll(a.c_str())
string tostr(int a) {stringstream rr;rr<<a;return rr.str();}
ll pow(ll c,ll d){return d==0?:c*pow(c,d-1);}
ll gcd(ll a,ll b) {return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b) {return ((a*b)/gcd(a,b));}

/* for unordered map: mpp.max_load_factor(0.25); mpp.reserve(1024); */
/* cout << fixed << setprecision(12);*/
int p[10005], s[10005], vis[10005];
vector<pair<int, int> >v, v1;

int findd(int x)
{
    if(x!=p[x]) p[x]=findd(p[x]);
    return p[x];
}

void uniono(int x, int y)
{
    int a, b;
    a=findd(x);
    b=findd(y);
    if(s[a]!=s[b]){
        if(s[a]<s[b]){
            swap(a, b);
        }
        s[a]+=s[b];
        p[b]=a;
    }
}
int main()
{
    fastt;
    int n, i, j, k, l, x, y;
    cin>>n;
    for(i=1; i<=n; i++){
        p[i]=i;
        s[i]=1;
        vis[i]=0;
    }
    for(i=1; i<n; i++){
        cin>>k>>l;
        x=findd(k);
        y=findd(l);
        if(x==y){
            v.pb(mp(k, l));
        }
        else{
            uniono(x, y);
        }
    }
    x=p[1];
    vis[x]=1;

    for(i=2; i<=n; i++){
        x=p[i];
       // cout<<p[i]<<" ";
        if(vis[x]==0){
            v1.pb(mp(1, i));
        }
        vis[x]=1;
    }
    int hh=min(v.size(), v1.size());
    cout<<hh<<endl;
    for(i=0; i<hh; i++){
        cout<<v[i].ff<<" "<<v[i].ss<<" "<<v1[i].ff<<" "<<v1[i].ss<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const int N = 1005;
int n;

struct dsu
{
    int link[N], sz[N];

    dsu()
    {
        for(int i=1;i<=n;i++)
            link[i] = i;
    }

    int find(int x)
    {
        while(x != link[x])
        {
            //link[x] = link[link[x]];
            x = link[x];
        }
        return x;
    }

    void unite(int a, int b)
    {
        int pa = find(a);
        int pb = find(b);

        if(pa == pb)
            return;

        if(sz[pa] < sz[pb])
            swap(pa, pb);
        sz[pa]+=sz[pb];
        sz[pb] = 0;
        link[pb] = link[pa];
    }
};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n;
    dsu uf;
    vector< pair<int, int> >rem;
    vector<int>place;
    for(int i=0;i<n-1;i++)
    {
        int a, b;
        cin>>a>>b;
        if(uf.find(a) == uf.find(b))
            rem.push_back({a, b});
        else
            uf.unite(a, b);
    }

    int ans = 0;
    for(int i=1;i<=n;i++)
    {
        if(i == uf.find(i))
        {
            ans++;
            place.emplace_back(i);
        }
    }
        cout<<ans-1<<'\n';

    for(int i=0;i<ans-1;i++)
        cout<<rem[i].first<<' '<<rem[i].second<<' '<<place[i]<<' '<<place[i+1]<<'\n';

    return 0;
}