#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void next_int(T &x) {
  x = 0;
  char c;
  bool neg = false;
  while (!isdigit(c = getchar()))
    if (c == '-') neg = true;
  do x = x * 10 + c - 48;
  while (isdigit(c = getchar()));
  if (neg) x = -x;
}
template <typename T>
inline void write_int(T x, char last = 0) {
  if (x < 0) putchar('-'), x = abs(x);
  char tmp[20];
  int cnt = 0;
  while (x >= 10) tmp[cnt++] = x % 10 + 48, x /= 10;
  tmp[cnt] = x + 48;
  for (int i = (cnt); i >= (0); --i) putchar(tmp[i]);
  if (last) putchar(last);
}
const int N = (int)5e5 + 5;
int n, par1[N], par2[N], f[N];
vector<int> g[N], g2[N];
inline int getf(int x) { return f[x] = f[x] == x ? x : getf(f[x]); }
inline void mergef(int x, int y) { f[getf(y)] = getf(x); }
void dfs_prep(vector<int> adj[], int u, int p, int par[]) {
  par[u] = p;
  for (auto v : adj[u])
    if (v != p) dfs_prep(adj, v, u, par);
}
void trace_ans(int u, int p) {
  for (auto v : g[u])
    if (v != p) {
      trace_ans(v, u);
      if (!(par2[v] == u || par2[u] == v))
        write_int(u, ' '), write_int(v, ' '), write_int(getf(v), ' '),
            write_int(par2[getf(v)], '\n');
    }
}
int main() {
  next_int(n);
  for (int i = (1); i < (n); ++i) {
    int u, v;
    next_int(u), next_int(v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  for (int i = (1); i < (n); ++i) {
    int u, v;
    next_int(u), next_int(v);
    g2[u].push_back(v);
    g2[v].push_back(u);
  }
  dfs_prep(g, 1, 0, par1);
  dfs_prep(g2, 1, 0, par2);
  for (int i = (1); i <= (n); ++i) f[i] = i;
  int res = 0;
  for (int u = (1); u <= (n); ++u)
    for (auto v : g[u])
      if (v == par1[u]) {
        if (v == par2[u] || u == par2[v]) {
          if (v == par2[u])
            mergef(v, u);
          else
            mergef(u, v);
        } else
          ++res;
      }
  write_int(res, '\n');
  trace_ans(1, 0);
  return 0;
}
