//Author:xht37
#include <bits/stdc++.h>

#define ui unsigned int
#define ll long long
#define ul unsigned ll
#define ld long double

#define pi pair <int, int>
#define fi first
#define se second
#define mp make_pair

#define ls (p << 1)
#define rs (ls | 1)
#define md ((t[p].l + t[p].r) >> 1)

#define vi vector <int>
#define pb push_back
#define pq priority_queue

#define dbg(x) cerr << #x" = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)

#define fl(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)

using namespace std;

namespace io {
	const int SI = 1 << 21 | 1;
	char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100];
	int f, t;
	#define gc() (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin), IS == IT ? EOF : *IS++) : *IS++)
	inline void flush() {
		fwrite(OB, 1, OS - OB, stdout), OS = OB;
	}
	inline void pc(char x) {
		*OS++ = x;
		if (OS == OT) flush();
	}

	template <class I>
	inline void rd(I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + (c & 15), c = gc());
		x *= f;
	}
	template <class I>
	inline void rd(I &x, I &y) {
		rd(x), rd(y);
	}
	template <class I>
	inline void rd(I &x, I &y, I &z) {
		rd(x), rd(y), rd(z);
	}
	template <class I>
	inline void rda(I *a, int n) {
		for (int i = 1; i <= n; i++) rd(a[i]);
	}
	inline void rdc(char &c) {
		for (c = gc(); c < 33 || c > 126; c = gc());
	}
	inline void rds(char *s, int &n) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (n = 0; c >= 33 && c <= 126; s[++n] = c, c = gc());
		s[n+1] = '\0';
	}
	inline void rds(string &s) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (s.clear(); c >= 33 && c <= 126; s.pb(c), c = gc());
	}

	template <class I>
	inline void print(I x, char k = '\n') {
		if (!x) pc('0');
		if (x < 0) pc('-'), x = -x;
		while (x) ch[++t] = x % 10 + '0', x /= 10;
		while (t) pc(ch[t--]);
		pc(k);
	}
	template <class I>
	inline void print(I x, I y) {
		print(x, ' '), print(y);
	}
	template <class I>
	inline void print(I x, I y, I z) {
		print(x, ' '), print(y, ' '), print(z);
	}
	template <class I>
	inline void printa(I *a, int n) {
		for (int i = 1; i <= n; i++) print(a[i], " \n"[i==n]);
	}
	inline void printc(char c) {
		pc(c);
	}
	inline void prints(char *s, int n) {
		for (int i = 1; i <= n; i++) pc(s[i]);
		pc('\n');
	}
	inline void prints(string s) {
		int n = s.length();
		while (t < n) pc(s[t++]);
		pc('\n'), t = 0;
	}
	struct Flush {
		~Flush() {
			flush();
		}
	} flusher;
}
using io::rd;
using io::rda;
using io::rdc;
using io::rds;
using io::print;
using io::printa;
using io::printc;
using io::prints;

const int N = 4e3 + 5;
vector <int> a[N];
int depth[N], father[N];
int n, m, tot, ans, x[N], y[N];
bool used[N], ok[N], res[N];
int nowx[N], nowy[N], f[N], g[N];
void dfs(int pos, int fa) {
	depth[pos] = depth[fa] + 1;
	father[pos] = fa;
	for (auto x : a[pos])
		if (x != fa) dfs(x, pos);
}
void mark(int a, int b, int c, int d) {
	static int cnt[N];
	memset(cnt, 0, sizeof(cnt));
	while (a != b) {
		if (depth[a] < depth[b]) swap(a, b);
		cnt[a]++, a = father[a];
	}
	while (c != d) {
		if (depth[c] < depth[d]) swap(c, d);
		cnt[c]++, c = father[c];
	}
	for (int i = 1; i <= n; i++)
		ok[i] |= cnt[i] >= 2;
}
void work(int pos, int fa) {
	for (auto x : a[pos])
		if (x != fa) work(x, pos);
	if (pos != 1) {
		int cnt = 0;
		for (int i = 1; i <= tot; i++)
			if (!used[i]) cnt += (nowx[i] == pos) ^ (nowy[i] == pos);
		ans += min(max(cnt, ok[pos] * 2), 2);
		if (cnt <= 1 || ok[pos]) {
			for (int i = 1; i <= tot; i++)
				if (!used[i]) {
					if (nowx[i] == pos) nowx[i] = fa;
					if (nowy[i] == pos) nowy[i] = fa;
				}
			return;
		}
		vector <int> points;
		for (int i = 1; i <= tot; i++)
			if (!used[i] && ((nowx[i] == pos) ^ (nowy[i] == pos))) {
				points.push_back(i);
			}
		int a = points[0], b = points[1];
		mark(nowx[a], nowy[a], nowx[b], nowy[b]);
		used[a] = used[b] = true;
		if (nowx[a] == pos && nowx[b] == pos) {
			tot++, f[tot] = -a, g[tot] = -b;
			x[tot] = y[a], nowx[tot] = nowy[a];
			y[tot] = y[b], nowy[tot] = nowy[b];
		}
		if (nowy[a] == pos && nowx[b] == pos) {
			tot++, f[tot] = a, g[tot] = -b;
			x[tot] = x[a], nowx[tot] = nowx[a];
			y[tot] = y[b], nowy[tot] = nowy[b];
		}
		if (nowx[a] == pos && nowy[b] == pos) {
			tot++, f[tot] = -a, g[tot] = b;
			x[tot] = y[a], nowx[tot] = nowy[a];
			y[tot] = x[b], nowy[tot] = nowx[b];
		}
		if (nowy[a] == pos && nowy[b] == pos) {
			tot++, f[tot] = a, g[tot] = b;
			x[tot] = x[a], nowx[tot] = nowx[a];
			y[tot] = x[b], nowy[tot] = nowx[b];
		}
		for (int i = 1; i <= tot; i++)
			if (!used[i]) {
				if (nowx[i] == pos) nowx[i] = fa;
				if (nowy[i] == pos) nowy[i] = fa;
			}
	}
}
int main() {
	rd(n, m), tot = m;
	for (int i = 1; i <= n - 1; i++) {
		int x, y; rd(x, y);
		a[x].push_back(y);
		a[y].push_back(x);
	}
	for (int i = 1; i <= m; i++) {
		rd(x[i], y[i]);
		nowx[i] = x[i];
		nowy[i] = y[i];
	}
	dfs(1, 0);
	work(1, 0);
	print(ans);
	for (int i = tot; i >= 1; i--) {
		if (!used[i]) res[i] = true;
		if (i > m) {
			int a = abs(f[i]), b = abs(g[i]);
			res[a] = res[i] ^ (x[i] != x[a]);
			res[b] = res[i] ^ (y[i] != y[b]);
		}
	}
	for (int i = 1; i <= m; i++)
		if (res[i]) print(x[i], y[i]);
		else print(y[i], x[i]);
	return 0;
}

Measured memory_bytes: 4112