#include <bits/stdc++.h>
using namespace std;
inline long long getint() {
  long long _x = 0, _tmp = 1;
  char _tc = getchar();
  while ((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar();
  if (_tc == '-') _tc = getchar(), _tmp = -1;
  while (_tc >= '0' && _tc <= '9') _x *= 10, _x += (_tc - '0'), _tc = getchar();
  return _x * _tmp;
}
inline long long add(long long _x, long long _y,
                     long long _mod = 1000000007ll) {
  long long _ = _x + _y;
  if (_ >= _mod) _ -= _mod;
  return _;
}
inline long long sub(long long _x, long long _y,
                     long long _mod = 1000000007ll) {
  long long _ = _x - _y;
  if (_ < 0) _ += _mod;
  return _;
}
inline long long mul(long long _x, long long _y,
                     long long _mod = 1000000007ll) {
  long long _ = _x * _y;
  if (_ >= _mod) _ %= _mod;
  return _;
}
long long mypow(long long _a, long long _x, long long _mod) {
  if (_x == 0) return 1ll;
  long long _tmp = mypow(_a, _x / 2, _mod);
  _tmp = mul(_tmp, _tmp, _mod);
  if (_x & 1) _tmp = mul(_tmp, _a, _mod);
  return _tmp;
}
long long mymul(long long _a, long long _x, long long _mod) {
  if (_x == 0) return 0ll;
  long long _tmp = mymul(_a, _x / 2, _mod);
  _tmp = add(_tmp, _tmp, _mod);
  if (_x & 1) _tmp = add(_tmp, _a, _mod);
  return _tmp;
}
inline bool equal(double _x, double _y) {
  return _x > _y - 1e-9 && _x < _y + 1e-9;
}
int __ = 1, _cs;
int n, p[505050];
int find_p(int x) { return x == p[x] ? x : p[x] = find_p(p[x]); }
void Union(int x, int y) {
  x = find_p(x);
  y = find_p(y);
  if (x == y) return;
  p[x] = y;
}
set<pair<int, int> > s[2];
vector<pair<int, int> > nxt[505050];
pair<int, int> pt[505050];
void build() {}
void init() {
  n = getint();
  for (int i = 1; i <= n; i++) p[i] = i;
  for (int ii = 0; ii < 2; ii++)
    for (int i = 1; i < n; i++) {
      int ai = getint();
      int bi = getint();
      if (ai > bi) swap(ai, bi);
      if (ii == 1 && s[0].count(make_pair(ai, bi))) {
        s[0].erase(make_pair(ai, bi));
        Union(ai, bi);
      } else
        s[ii].insert(make_pair(ai, bi));
    }
}
vector<pair<pair<int, int>, pair<int, int> > > ans;
void DFS(int now, pair<int, int> prt = make_pair(0, 0)) {
  pt[now] = prt;
  for (size_t i = 0; i < nxt[now].size(); i++)
    if (nxt[now][i].first != prt.second)
      DFS(find_p(nxt[now][i].first), nxt[now][i]);
}
void DFS2(int now, pair<int, int> prt = make_pair(0, 0)) {
  for (size_t i = 0; i < nxt[now].size(); i++)
    if (nxt[now][i].first != prt.second)
      DFS2(find_p(nxt[now][i].first), nxt[now][i]);
  if (now == find_p(1)) return;
  ans.push_back(make_pair(prt, pt[now]));
}
void build_edge(int idx) {
  for (set<pair<int, int> >::iterator it = s[idx].begin(); it != s[idx].end();
       it++) {
    nxt[find_p(it->first)].push_back(make_pair(it->second, it->first));
    nxt[find_p(it->second)].push_back(make_pair(it->first, it->second));
  }
}
void solve() {
  build_edge(1);
  DFS(find_p(1));
  for (int i = 1; i <= n; i++) nxt[i].clear();
  build_edge(0);
  DFS2(find_p(1));
  printf("%d\n", (int)ans.size());
  for (size_t 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);
}
int main() {
  build();
  while (__--) {
    init();
    solve();
  }
}
