#include <iostream>
#include <vector>
#include <set>

using namespace std;

const int MAX_N = 2e3 + 5;

namespace dsu {
  int root [MAX_N];
  int rank [MAX_N];
  int sgn [MAX_N];

  pair<int, int> find (int u) {
    if (root[u] != u) {
      auto pr = find(root[u]);
      return make_pair(pr.first, sgn[u] * pr.second);
    } else {
      return make_pair(root[u], sgn[u]);
    }
  }

  void merge (int u, int v, int s) {
    //  cerr << " merge " << u << " " << v << endl;
    auto up = find(u);
    auto vp = find(v);
    u = up.first;
    v = vp.first;
    s *= up.second * vp.second;

    if (u == v) {
      return;
    }

    if (rank[u] < rank[v]) {
      swap(u, v);
    }

    root[v] = u;
    sgn[v] = s;
    if (rank[u] == rank[v]) {
      rank[u]++;
    }
  }
}

vector<int> adj [MAX_N];
int par [MAX_N];
int lvl [MAX_N];

void dfs (int u, int p) {
  par[u] = p;
  lvl[u] = lvl[p] + 1;

  for (int nxt : adj[u]) {
    if (nxt != p) {
      dfs(nxt, u);
    }
  }
}

struct PathFrag {
  int idx, sgn;

  PathFrag (int _idx = 0, int _sgn = 0) :
    idx(_idx), sgn(_sgn) {}
};

vector<PathFrag> covers [MAX_N];

bool doubly_covered (int u, int v) {
  if (lvl[u] < lvl[v]) {
    swap(u, v);
  }

  while (lvl[u] > lvl[v]) {
    if ((int) covers[u].size() < 2) return false;
    u = par[u];
  }

  while (u != v) {
    if ((int) covers[u].size() < 2) return false;
    u = par[u];

    if ((int) covers[v].size() < 2) return false;
    v = par[v];
  }
  
  return true;
}

void add_path (int u, int v, int idx) {
  int sgn = 1;
  
  if (lvl[u] < lvl[v]) {
    swap(u, v);
    sgn = -1;
  }

  while (lvl[u] > lvl[v]) {
    covers[u].push_back(PathFrag(idx, sgn));
    u = par[u];
  }

  while (u != v) {
    covers[u].push_back(PathFrag(idx, sgn));
    u = par[u];

    covers[v].push_back(PathFrag(idx, -sgn));
    v = par[v];
  }
}

int main () {
  int n, m;
  cin >> n >> m;

  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;

    adj[u].push_back(v);
    adj[v].push_back(u);
  }

  dfs(1, 0);

  vector<pair<int, int>> paths;
  for (int i = 0; i < m; i++) {
    dsu::root[i] = i;
    dsu::sgn[i] = 1;

    int u, v;
    cin >> u >> v;

    if (!doubly_covered(u, v)) {
      add_path(u, v, i);
    }
    paths.push_back(make_pair(u, v));
  }

  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += min(2, (int) covers[i].size());
    if ((int) covers[i].size() == 2) {
      dsu::merge(covers[i][0].idx, covers[i][1].idx,
                 -covers[i][0].sgn * covers[i][1].sgn);
    }
  }

  for (int i = 1; i <= n; i++) {
    if ((int) covers[i].size() >= 3) {
      // check if a path-group already has both sides covered here
      bool need = true;
      set<pair<int, int>> ps;
      for (PathFrag pf : covers[i]) {
        pair<int, int> fp = dsu::find(pf.idx);
        fp.second *= pf.sgn;

        fp.second *= -1;
        if (ps.count(fp)) {
          need = false;
        }
        fp.second *= -1;

        ps.insert(fp);
      }

      if (need) {
        pair<int, int> fp = dsu::find(covers[i][0].idx);
        fp.second *= covers[i][0].sgn;
      
        for (int j = 1; j < (int) covers[i].size(); j++) {
          pair<int, int> cp = dsu::find(covers[i][j].idx);
          cp.second *= covers[i][j].sgn;

          if (fp.first != cp.first) {
            dsu::merge(covers[i][0].idx, covers[i][j].idx,
                       -covers[i][0].sgn * covers[i][j].sgn);
            break;
          } else if (fp.second != cp.second) {
            break;
          }

          if (j == (int) covers[i].size() - 1) {
            cerr << " === URROR === " << endl;
          }
        }
      }
    }
  }

  cout << ans << '\n';
  for (int i = 0; i < m; i++) {
    if (dsu::find(i).second < 0) {
      swap(paths[i].first, paths[i].second);
    }

    cout << paths[i].first << " " << paths[i].second << '\n';
  }
}


Measured memory_bytes: 4436