#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 * 1000;
vector<int> g[MAXN], need[MAXN];
int pr[MAXN], rang[MAXN];
vector<pair<int, int> > ed[MAXN];
int find_pr(int v) {
  if (v == pr[v]) return pr[v];
  return pr[v] = find_pr(pr[v]);
}
void merge(int u, int v) {
  u = find_pr(u);
  v = find_pr(v);
  if (rang[u] > rang[v]) {
    swap(u, v);
  }
  rang[v] += rang[u];
  pr[u] = v;
  ed[v].insert(ed[v].end(), ed[u].begin(), ed[u].end());
}
vector<int> leaf;
bool was[MAXN];
pair<int, int> my_make(int x, int y) { return make_pair(min(x, y), max(x, y)); }
set<pair<int, int> > is;
pair<pair<int, int>, pair<int, int> > ans[MAXN];
int len_ans = 0;
int cnt_ed[MAXN];
int main() {
  for (int i = 0; i < MAXN; i++) {
    pr[i] = i;
    rang[i] = 1;
  }
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    scanf("%i %i", &x, &y);
    x--;
    y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    scanf("%i %i", &x, &y);
    x--;
    y--;
    need[x].push_back(y);
    need[y].push_back(x);
    ed[x].push_back(my_make(x, y));
    ed[y].push_back(my_make(y, x));
  }
  for (int i = 0; i < n; i++) {
    cnt_ed[i] = ((int)(g[i].size()));
    if (((int)(g[i].size())) == 1) {
      leaf.push_back(i);
    }
  }
  for (int it = 0; it < n - 1; it++) {
    int v = leaf.back();
    leaf.pop_back();
    was[v] = 1;
    int u = -1;
    for (int cur_v : g[v]) {
      cnt_ed[cur_v]--;
      if (cnt_ed[cur_v] == 1) {
        leaf.push_back(cur_v);
      }
      if (!was[cur_v]) {
        u = cur_v;
      }
    }
    pair<int, int> cur_ed = my_make(v, u);
    bool is_need = 0;
    for (int u : need[v]) {
      if (my_make(u, v) == cur_ed) {
        is_need = 1;
        break;
      }
    }
    if (is_need) {
      is.insert(my_make(v, u));
      merge(u, v);
      continue;
    }
    v = find_pr(v);
    while (is.count(ed[v].back())) {
      ed[v].pop_back();
    }
    ans[len_ans++] = make_pair(cur_ed, ed[v].back());
    is.insert(ed[v].back());
    int ne = ed[v].back().first;
    if (find_pr(ne) == v) {
      ne = ed[v].back().second;
    }
    ed[v].pop_back();
    merge(v, ne);
  }
  cout << len_ans << "\n";
  for (int i = 0; i < len_ans; i++) {
    printf("%i %i %i %i\n", 1 + ans[i].first.first, 1 + ans[i].first.second,
           1 + ans[i].second.first, 1 + ans[i].second.second);
  }
  return 0;
}
