#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 10;
set<int> w[MAXN];
set<pair<int, int> > s[MAXN];
set<pair<int, int> > e[MAXN];
vector<pair<pair<int, int>, pair<int, int> > > ans;
int head[MAXN];
void update(int v) {
  if (head[head[v]] != head[head[head[v]]]) {
    update(head[v]);
  }
  head[v] = head[head[v]];
}
void unite(int v, int u) {
  update(v);
  update(u);
  v = head[v];
  u = head[u];
  int z = s[v].size(), f = s[u].size();
  if (s[v].size() < s[u].size()) {
    s[v].swap(s[u]);
  }
  if (e[v].size() < e[u].size()) {
    e[v].swap(e[u]);
  }
  while (e[u].size() > 0) {
    int c = e[u].begin()->first, d = e[u].begin()->second;
    e[u].erase(e[u].begin());
    e[v].insert(make_pair(c, d));
  }
  head[u] = v;
  w[z].erase(v);
  w[f].erase(u);
  w[s[v].size()].insert(v);
}
void remove_edge(int v, int a, int b) {
  w[s[v].size()].erase(v);
  s[v].erase(make_pair(a, b));
  w[s[v].size()].insert(v);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < (n - 1); i++) {
    int v, u;
    scanf("%d%d", &v, &u);
    if (v > u) {
      swap(v, u);
    }
    s[v].insert(make_pair(v, u));
    s[u].insert(make_pair(v, u));
  }
  for (int i = 1; i <= n; i++) {
    head[i] = i;
    w[s[i].size()].insert(i);
  }
  for (int i = 0; i < (n - 1); i++) {
    int v, u;
    scanf("%d%d", &v, &u);
    if (v > u) {
      swap(v, u);
    }
    e[v].insert(make_pair(v, u));
    e[u].insert(make_pair(v, u));
  }
  for (int i = 1; i <= n; i++) {
    int v = (*w[1].begin());
    int a = s[v].begin()->first, b = s[v].begin()->second, c, d;
    if (e[v].find(make_pair(a, b)) != e[v].end()) {
      c = e[v].find(make_pair(a, b))->first;
      d = e[v].find(make_pair(a, b))->second;
    } else {
      c = e[v].begin()->first;
      d = e[v].begin()->second;
    }
    update(a);
    update(b);
    update(c);
    update(d);
    remove_edge(head[a], a, b);
    remove_edge(head[b], a, b);
    e[head[c]].erase(make_pair(c, d));
    e[head[d]].erase(make_pair(c, d));
    unite(c, d);
    if (a != c || b != d) {
      ans.push_back(make_pair(make_pair(a, b), make_pair(c, d)));
    }
  }
  printf("%d\n", (int)(ans.size()));
  for (int i = 0; i < ans.size(); i++) {
    printf("%d %d %d %d\n", ans[i].first.first, ans[i].first.second,
           ans[i].second.first, ans[i].second.second);
  }
}
