#include <bits/stdc++.h>
using namespace std;
int p[500013];
int find(int x) { return p[x] == x ? x : p[x] = find(p[x]); }
void merge(int a, int b) { p[find(a)] = find(b); }
int n;
int a[500013], b[500013], c[500013], d[500013];
set<pair<int, int> > one, two;
vector<pair<int, int> > adj[500013];
pair<int, int> fa[500013];
void setup(int x, pair<int, int> pp = make_pair(0, 0)) {
  fa[x] = pp;
  for (auto i : adj[x]) {
    if (i.first != pp.second) setup(find(i.first), i);
  }
}
void dfs(int x, pair<int, int> pp = make_pair(0, 0)) {
  for (auto i : adj[x]) {
    if (i.first != pp.second) dfs(find(i.first), i);
  }
  if (x == find(1)) return;
  printf("%d %d %d %d\n", pp.second, pp.first, fa[x].second, fa[x].first);
}
int main() {
  scanf("%d", &n);
  iota(p, p + n + 1, 0);
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &a[i], &b[i]);
    if (a[i] > b[i]) swap(a[i], b[i]);
    one.insert(make_pair(a[i], b[i]));
  }
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &c[i], &d[i]);
    if (c[i] > d[i]) swap(c[i], d[i]);
    auto it = one.find(make_pair(c[i], d[i]));
    if (it != one.end()) {
      one.erase(it);
      merge(c[i], d[i]);
    } else
      two.insert(make_pair(c[i], d[i]));
  }
  for (auto p : two) {
    adj[find(p.first)].push_back(make_pair(p.second, p.first));
    adj[find(p.second)].push_back(make_pair(p.first, p.second));
  }
  setup(find(1));
  for (int i = 1; i <= n; i++) adj[i].clear();
  for (auto p : one) {
    adj[find(p.first)].push_back(make_pair(p.second, p.first));
    adj[find(p.second)].push_back(make_pair(p.first, p.second));
  }
  printf("%d\n", one.size());
  dfs(find(1));
  return 0;
}
