#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <numeric>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
#define rep(i, a, b) for (register int i = (a); i <= (b); ++i)
#define per(i, a, b) for (register int i = (a); i >= (b); --i)
#define loop(it, v) for (auto it = v.begin(); it != v.end(); it++)
#define cont(i, x) for (register int i = head[x]; i; i = edge[i].nex)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, cnt) memset(a, cnt, sizeof(a))
#define cop(a, b) memcpy(a, b, sizeof(a))
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()
#define SC(t, x) static_cast <t> (x)
#define ub upper_bound
#define lb lower_bound
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define pof pop_front
#define pob pop_back
#define fi first
#define se second
#define y1 y1_
#define Pi acos(-1.0)
#define iv inline void
#define enter putchar('\n')
#define siz(x) ((int)x.size())
#define file(x) freopen(x".in", "r", stdin),freopen(x".out", "w", stdout)
typedef double db ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair <int, int> pii ;
typedef vector <int> vi ;
typedef vector <pii> vii ;
typedef queue <int> qi ;
typedef queue <pii> qii ;
typedef set <int> si ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
const int maxn = 5e3 + 5 ;
const int inf = 0x3f3f3f3f ;
const int iinf = 1 << 30 ;
const ll linf = 2e18 ;
const ll mod = 1e9 + 7 ;
const double eps = 1e-7 ;
template <class T = int> T read()
{
	T f = 1, a = 0;
	char ch = getchar() ;
	while (!isdigit(ch)) { if (ch == '-') f = -1 ; ch = getchar() ; }
	while (isdigit(ch)) { a =  (a << 3) + (a << 1) + ch - '0' ; ch = getchar() ; }
	return a * f ;
}

int n, m, maxx;

vi edge[maxn];

int dep[maxn], fa[maxn], b[maxn][maxn], ans[maxn], g[maxn][2];

pii query[maxn];

bool vis[maxn];

vii s[maxn], lim[maxn];

void dfs(int now, int father)
{
	dep[now] = dep[father] + 1;
	fa[now] = father;
	for(int to : edge[now])
	{
		if(to == father) continue;
		dfs(to, now);
	}
}

void solve(int now)
{
	int cnt = 0;
	for(int to : edge[now])
	{
		if(to == fa[now]) continue;
		solve(to);
		rep(i, 1, m) if(b[now][i] == -1) b[now][i] = b[to][i];
	}
	for(pii i : s[now]) b[now][i.fi] = i.se;
	rep(i, 1, m) cnt += b[now][i] != -1;
	if(cnt < 2) return (void)(maxx += cnt);
	maxx += 2;
	for(int to : edge[now])
	{
		if(to == fa[now]) continue;
		if((~ b[now][g[to][0]]) && (~ b[now][g[to][1]]))
		{
			g[now][0] = g[to][0], g[now][1] = g[to][1];
			break;
		}
	}
	if(g[now][0] != -1) return ;
	int x = 0, y = 0;
	rep(i, 1, m)
	{
		if(b[now][i] == -1) continue;
		if(!x) x = i;
		else
		{
			y = i;
			break;
		}
	}
	g[now][0] = x, g[now][1] = y;
	lim[x].pb(mp(y, b[now][x] ^ b[now][y] ^ 1)), lim[y].pb(mp(x, b[now][x] ^ b[now][y] ^ 1));
}

void paint(int now)
{
	vis[now] = 1;
	for(pii to : lim[now])
	{
		if(vis[to.fi]) continue;
		ans[to.fi] = ans[now] ^ to.se;
		paint(to.fi);
	}
}


signed main()
{
	scanf("%d %d", &n, &m);
	rep(i, 1, n - 1)
	{
		int u, v;
		scanf("%d %d", &u, &v);
		edge[u].pb(v), edge[v].pb(u);
	}
	dfs(1, 0);
	rep(i, 1, m)
	{
		int u, v;
		scanf("%d %d", &u, &v);
		query[i] = mp(u, v);
		while(u != v)
		{
			if(dep[u] < dep[v]) swap(u, v);
			u = fa[u];
		}
		if(query[i].fi != u) s[query[i].fi].pb(mp(i, 0));
		if(query[i].se != u) s[query[i].se].pb(mp(i, 1));
		s[u].pb(mp(i, -1));
	}
	ass(b, -1), ass(g, -1);
	solve(1);
	rep(i, 1, m) if(!vis[i]) paint(i);
	printf("%d\n", maxx);
	rep(i, 1, m) if(ans[i]) printf("%d %d\n", query[i].se, query[i].fi); else printf("%d %d\n", query[i].fi, query[i].se);
	return 0;
}

Measured memory_bytes: 98944