#include <bits/stdc++.h>
#define pw(x) (1LL << (x))
#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl

using namespace std;
typedef long long ll;
typedef double dbl;
const int INF = 1.01e9;

pair<int, vector<pair<int, int>>> solve(vector<pair<int, int>> ed, vector<pair<int, int>> path) {
    int n = ed.size() + 1;
    int m = path.size();

    vector<vector<int>> e(n);
    for (int i = 0; i < n - 1; i++) {
        e[ed[i].first].push_back(i);
        e[ed[i].second].push_back(i);
    }

    vector<set<pair<int, int>>> paths(n - 1);
    vector<vector<int>> edges(m);
    for (int i = 0; i < m; i++) {
        function<bool(int, int)> dfs = [&](int v, int pr) {
            if (v == path[i].second) {
                return true;
            }
            for (int id : e[v]) {
                int to = ed[id].first ^ ed[id].second ^ v;
                if (to == pr) continue;
                if (dfs(to, v)) {
                    edges[i].push_back(id);
                    paths[id].insert({i, to == ed[id].first});
                    return true;
                }
            }
            return false;
        };
        dfs(path[i].first, -1);
    }
    auto opaths = paths;

    int need = 0;
    for (int i = 0; i < n - 1; i++) need += min((int)paths[i].size(), 2);

    vector<vector<int>> have(n - 1, vector<int>(2));

    vector<int> color(m, -1);
    function<void(int, int)> paint = [&](int p, int c) {
        if (color[p] != -1) {
            assert(color[p] == c);
            return;
        }
        color[p] = c;
        for (auto id : edges[p]) {
            auto it = paths[id].lower_bound(make_pair(p, -1));
            auto o = *it;
            have[id][o.second ^ c] = 1;
            paths[id].erase(it);
            if (paths[id].size() == 1 && !have[id][o.second ^ c ^ 1]) {
                paint(paths[id].begin()->first, paths[id].begin()->second ^ o.second ^ c ^ 1);
            }
        }
    };
    for (int i = 0; i < m; i++) {
        if (color[i] == -1) {
            paint(i, 0);
        }
    }

    int res = 0;
    for (int i = 0; i < n - 1; i++) {
        vector<char> chave(2);
        for (auto o : opaths[i]) {
            chave[o.second ^ color[o.first]] = 1;
        }
        res += chave[0];
        res += chave[1];
        assert(chave[0] == have[i][0]);
        assert(chave[1] == have[i][1]);
    }

    assert(res == need);
    for (int i = 0; i < m; i++) {
        if (color[i] == 1) {
            swap(path[i].first, path[i].second);
        }
    }
    return make_pair(res, path);
};

void stress() {
    for (int it = 246;; it++ ){
        cout << it << endl;
        srand(it);

        int n = rand() % 10 + 2;
        int m = rand() % (2 * n) + 1;
        vector<pair<int, int>> ed(n - 1), path(m);
        for (int i = 0; i < n - 1; i++) {
            ed[i] = {i + 1, rand() % (i + 1)};
        }
        for (int i = 0; i < m; i++) {
            while (path[i].first == path[i].second) {
                path[i].first = rand() % n;
                path[i].second = rand() % n;
            }
        }

        /*cout << n << " " << m << endl;
        for (auto o : ed) cout << o.first << " " << o.second << endl;
        for (auto o : path) cout << o.first << " " << o.second << endl;*/
        auto o = solve(ed, path);
        //cout << solve(ed, path).first << endl;
    }
}

int main() {
#ifdef HOME
    assert(freopen("in", "r", stdin));
#endif
    //stress();

    int n, m;
    while (scanf("%d%d", &n, &m) == 2) {
        vector<pair<int, int>> ed(n - 1);
        for (int i = 0; i < n - 1; i++) {
            scanf("%d%d", &ed[i].first, &ed[i].second);
            ed[i].first--;
            ed[i].second--;
        }
        vector<pair<int, int>> path(m);
        for (int i = 0; i < m; i++) {
            scanf("%d%d", &path[i].first, &path[i].second);
            path[i].first--;
            path[i].second--;
        }

        auto o = solve(ed, path);
        auto res = o.first;
        path = o.second;

        printf("%d\n", res);
        for (int i = 0; i < m; i++) {
            printf("%d %d\n", path[i].first + 1, path[i].second + 1);
        }
    }

#ifdef HOME
    cerr << "time = " << (clock() * 1. / CLOCKS_PER_SEC) << "\n";
#endif
    return 0;
}


Measured memory_bytes: 119424