#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
using namespace std;

int main() {
        int n, m;
        scanf("%d%d", &n, &m);
        vector<vector<pair<int, int>>> g(n);
        for (int i = 0; i < n - 1; i ++) {
                int a, b;
                scanf("%d%d", &a, &b);
                a --, b --;
                g[a].push_back({b, i});
                g[b].push_back({a, i});
        }
        vector<vector<int>> wi(n);
        //int tot = n + m + 5;
        int tot = 10000;
        vector<int> u(tot), v(tot);
        vector<int> ucut(tot), vcut(tot);
        for (int i = 0; i < m; i ++) {
                scanf("%d%d", &u[i], &v[i]);
                u[i] --, v[i] --;
                ucut[i] = u[i];
                vcut[i] = v[i];
                wi[u[i]].push_back(i);
                wi[v[i]].push_back(i);
        }
        int idx = m;
        vector<pair<int, int>> dir(tot);
        vector<bool> used(tot, false);
        function<void (int, int)> dfs = [&](int leaf, int prev) {
                for (auto e : g[leaf]) if (e.first != prev) {
                        dfs(e.first, leaf);
                }
                int pair = -1;
                for (auto i : wi[leaf]) if (!used[i]) {
                        if (ucut[i] == vcut[i]) {
                                continue;
                        }
                        if (pair == -1) {
                                pair = i;
                                continue;
                        }
                        used[pair] = used[i] = true;
                        int j = idx ++;
                        int pend = (leaf == ucut[pair] ? vcut[pair] : ucut[pair]);
                        int iend = (leaf == ucut[i   ] ? vcut[i   ] : ucut[i   ]);
                        u[j] = ucut[j] = pend;
                        v[j] = vcut[j] = iend;
                        dir[j] = {pair, i};
                        wi[pend].push_back(j);
                        wi[iend].push_back(j);
                        pair = -1;
                }
                if (pair != -1) {
                        (leaf == ucut[pair] ? ucut[pair] : vcut[pair]) = prev;
                        wi[prev].push_back(pair);
                }
        };
        dfs(0, -1);
        vector<bool> rev(tot, false);
        for (int i = idx - 1; i >= m; i --) {
                int p = dir[i].first, q = dir[i].second;
                rev[p] = rev[i] ^ (u[i] != ucut[p]);
                rev[q] = rev[i] ^ (v[i] != vcut[q]);
        }
        vector<int> cnt(n - 1);
        function<bool (int, int, int)> dfs2 = [&](int u, int v, int prev) {
                if (u == v) {
                        return true;
                }
                for (auto e : g[u]) if (e.first != prev) {
                        bool good = dfs2(e.first, v, u);
                        if (good) {
                                cnt[e.second] ++;
                                return true;
                        }
                }
                return false;
        };
        for (int i = 0; i < m; i ++) {
                if (rev[i]) {
                        swap(u[i], v[i]);
                }
                dfs2(u[i], v[i], -1);
        }
        int ans = 0;
        for (int i = 0; i < n - 1; i ++) {
                ans += min(2, cnt[i]);
        }
        printf("%d\n", ans);
        for (int i = 0; i < m; i ++) {
                printf("%d %d\n", u[i] + 1, v[i] + 1);
        }
        return 0;
}



Measured memory_bytes: 896