#include<cassert>
#include<deque>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N, M;

VI G[2011];
int par[2011];
VI ord;
VI path(int s, int t) {
    par[t] = t;
    ord.clear();
    ord.push_back(t);
    REP (i_, N) {
	int v = ord[i_];
	EACH (e, G[v]) if (*e != par[v]) {
	    par[*e] = v;
	    if (*e == s) goto BREAK;
	    ord.push_back(*e);
	}
    }
BREAK:


    VI ret;
    while (1) {
	ret.push_back(s);
	if (s == t) break;
	s = par[s];
    }

    return ret;
}

struct Edge {
    deque<int> dq;
    int parent;
    bool flip;
    bool order;
    bool fix;

    Edge(int u_, int v_) {
	VI p = path(u_, v_);
	dq = deque<int>(p.begin(), p.end());
	parent = -1;
	flip = order = fix = false;
    }

    int u() const { return dq.front(); }
    int v() const { return dq.back(); }

    bool one_end(int x) const {
	return x == u() || x == v();
    }
};
vector<Edge> edges;

bool ban[2011];
int Eu[2011], Ev[2011];

void MAIN() {
    scanf("%d%d", &N, &M);
    REP (i, N-1) {
	int x, y;
	scanf("%d%d", &x, &y);
	x--; y--;
	G[x].push_back(y);
	G[y].push_back(x);
    }
    REP (i, M) {
	int u, v;
	scanf("%d%d", &u, &v);
	u--; v--;
	Eu[i] = u; Ev[i] = v;
	edges.emplace_back(u, v);
    }

    int ans = 0;
    {
	vector<pair<int, int> > g;
	REP (i, M) {
	    REP (j, edges[i].dq.size()-1u) {
		int x = edges[i].dq[j];
		int y = edges[i].dq[j+1];
		g.emplace_back(min(x, y), max(x, y));
	    }
	}
	sort(g.begin(), g.end());
	for (int i=0, j=0; i<(int)g.size(); i=j) {
	    while (j < (int)g.size() && g[i] == g[j]) {
		j++;
	    }
	    if (j-i >= 2) ans += 2;
	    else ans++;
	}
    }

    int rest = N;
    while (rest > 1) {
	int leaf = -1;
	REP (v, N) if (!ban[v]) {
	    int cnt = 0;
	    EACH (e, G[v]) if (!ban[*e]) {
		cnt++;
	    }
	    if (cnt == 1) {
		leaf = v;
		break;
	    }
	}

	VI Es;
	REP (i, edges.size()) if (!edges[i].fix && edges[i].one_end(leaf)) {
	    Es.push_back(i);
	    if (Es.size() == 2u) break;
	}

	if (Es.empty()) {
	} else if (Es.size() == 1u) {
	    int id = Es[0];
	    if (edges[id].u() == leaf) edges[id].dq.pop_front();
	    else edges[id].dq.pop_back();
	    if (edges[id].dq.size() == 1u) edges[id].fix = true;
	} else {
	    int a = Es[0], b = Es[1];
	    int ax = (edges[a].u() == leaf? edges[a].v(): edges[a].u());
	    int bx = (edges[b].u() == leaf? edges[b].v(): edges[b].u());

	    if (ax == bx) {
		if (edges[a].u() == leaf) edges[a].order = true;
		if (edges[b].v() == leaf) edges[b].order = true;
	    } else {
		edges[a].parent = edges.size();
		edges[b].parent = edges.size();
		if (edges[a].u() != ax) edges[a].flip = true;
		if (edges[b].v() != bx) edges[b].flip = true;
		edges.emplace_back(ax, bx);
	    }
	    edges[a].fix = true;
	    edges[b].fix = true;

	    REP (j, edges.size()) if (!edges[j].fix && edges[j].one_end(leaf)) {
		if (edges[j].v() == leaf) edges[j].dq.pop_back();
		else edges[j].dq.pop_front();

		if (edges[j].dq.size() == 1u) edges[j].fix = true;
	    }
	}
	rest--;
	ban[leaf] = true;
    }
    for (int i=edges.size(); i--;) {
//	if (!edges[i].fix) {
//	    printf("%d\n", i);
//	    rprintf("%d", edges[i].dq.begin(), edges[i].dq.end());
//	}
	assert(edges[i].fix);
	if (edges[i].parent != -1) {
	    edges[i].order = edges[edges[i].parent].order ^ edges[i].flip;
	}
    }

    printf("%d\n", ans);
    REP (i, M) {
	int u = Eu[i], v = Ev[i];
	if (edges[i].order) swap(u, v);
	printf("%d %d\n", u+1, v+1);
    }
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 23536