#include <cstdio>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <vector>
inline int getint()
{
	int r = 0,s = 0;char c = getchar();for(;!isdigit(c);c = getchar()) s |= c == '-';
	for(;isdigit(c);c = getchar()) r = (((r << 2) + r) << 1) + (c ^ '0');return s ? -r : r;
}
const int N = 2020;
int head[N],next[N << 1],to[N << 1],tot = 1;
inline void addedge(int u,int v)
{
	next[++tot] = head[u];to[tot] = v;head[u] = tot;
	next[++tot] = head[v];to[tot] = u;head[v] = tot;
}
int S[N],T[N],cnt[N];
std::vector<int> path[N],edge[N];
int n,m;
inline int dfs(int u,int f,int de,int id)
{
	if(u == de) return 1;
	for(int i = head[u],v = to[i];~i;v = to[i = next[i]])
	{
		if(v == f) continue;
		++cnt[i >> 1];path[id].push_back(i);edge[i >> 1].push_back(id);
		if(dfs(v,u,de,id)) return 1;
		--cnt[i >> 1];path[id].pop_back();edge[i >> 1].pop_back();
	}
	return 0;
}
int vis[N << 1],used[N];
int main()
{
	memset(head,-1,sizeof(head));
	n = getint(),m = getint();
	for(int i = 1;i < n;i++) addedge(getint(),getint());
	for(int i = 1;i <= m;i++)
	{
		S[i] = getint(),T[i] = getint();
		dfs(S[i],0,T[i],i);
	}
	int ans = 0;
	for(int i = 1;i < n;i++) ans += std::min(cnt[i],2);
	printf("%d\n",ans);
	while(1)
	{
		int p = 0,q;
		for(int i = 1;i < n;i++) if(cnt[i] == 1 && vis[i << 1 | 1] ^ vis[i << 1]) {p = i;break;}
		if(!p) for(int i = 1;i < n;i++) if(cnt[i] >= 2) {p = i;break;}
		if(!p) break;
		for(int i = 0,sz = edge[p].size();i < sz;i++) if(!used[edge[p][i]]) {q = edge[p][i];break;}
		used[q] = 1;
		for(int i = 0,sz = path[q].size(),u = path[q][i];i < sz;u = path[q][++i])
		{
			if((u >> 1) != p) continue;
			if(vis[u])
			{
				std::swap(S[q],T[q]);
				for(int j = 0;j < sz;++j) path[q][j] ^= 1;
			}
			for(int j = 0,v = path[q][j];j < sz;v = path[q][++j]) --cnt[v >> 1],vis[v] = 1;
			break;
		}
	}
	for(int i = 1;i <= m;i++) printf("%d %d\n",S[i],T[i]);
	return 0;
}
