#include <bits/stdc++.h>
using namespace std;
const int maxn = (5e5) + 10;
int n, pa[maxn];
set<pair<int, int> > s[maxn];
vector<int> G[maxn];
vector<pair<pair<int, int>, pair<int, int> > > ans;
void mer(int a, int b) {
  if ((int)s[a].size() < (int)s[b].size()) swap(a, b);
  pa[b] = a;
  while (s[b].size()) {
    pair<int, int> x = *s[b].begin();
    s[b].erase(x);
    s[a].insert(x);
  }
}
int get_par(int x) {
  if (x == pa[x]) return x;
  pa[x] = get_par(pa[x]);
  return pa[x];
}
void OK(int v, int u) {
  int a = get_par(v), b = get_par(u);
  if (s[b].find(make_pair(min(u, v), max(u, v))) != s[b].end()) {
    mer(a, b);
    int rr = get_par(a);
    s[rr].erase(make_pair(min(u, v), max(u, v)));
    return;
  }
  pair<int, int> edg = make_pair(min(u, v), max(u, v));
  pair<int, int> x = *s[b].begin();
  int r1 = get_par(x.first), r2 = get_par(x.second);
  ans.push_back(make_pair(edg, x));
  mer(r1, r2);
  int rr = get_par(r1);
  s[rr].erase(x);
}
void DFS(int v, int p) {
  for (int i = 0; i < (int)G[v].size(); i++) {
    int u = G[v][i];
    if (u == p) continue;
    DFS(u, v);
    OK(v, u);
  }
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    G[x].push_back(y);
    G[y].push_back(x);
  }
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    s[x].insert(make_pair(min(x, y), max(x, y)));
    s[y].insert(make_pair(min(x, y), max(x, y)));
  }
  for (int i = 1; i <= n; i++) pa[i] = i;
  DFS(1, -1);
  printf("%d\n", (int)ans.size());
  for (int i = 0; i < (int)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);
  return 0;
}
