#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cassert>
#include<ctime>
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
namespace io
{
	int F()
	{
		int n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=n*10+ch-'0';
		return F?n:-n;
	}
}
struct li
{
	int u,v;
}l[333333];
int pno;
struct edge
{
	int to;
	int next;
}e[333333];
int pe=111111;
int deg[111111];
void insert(int a,int to)
{
	e[pe]=(edge){to,e[a].next};
	e[a].next=pe++;
	deg[to]++;
}
int siz[111111],fa[111111],top[111111],dep[111111],son[111111];
void dfs(int o)
{
	siz[o]=1;
	int mx=0;
	for(register int p=e[o].next;p;p=e[p].next)
		if(e[p].to!=fa[o])
		{
			fa[e[p].to]=o;
			dep[e[p].to]=dep[o]+1;
			dfs(e[p].to);
			siz[o]+=siz[e[p].to];
			if(cmax(mx,siz[e[p].to]))son[o]=e[p].to;
		}
}
void dfs2(int o)
{
	for(register int p=e[o].next;p;p=e[p].next)
		if(e[p].to!=fa[o])
		{
			if(e[p].to==son[o])top[e[p].to]=top[o];
				else top[e[p].to]=e[p].to;
			dfs2(e[p].to);
		}
}
int lca(int u,int v)
{
	while(top[u]!=top[v])
		dep[top[u]]>dep[top[v]]?u=fa[top[u]]:v=fa[top[v]];
	return dep[u]>dep[v]?v:u;
}
int fir(int u,int v)
{
	if(lca(u,v)!=u)return fa[u];
	while(1)
	{
		if(top[u]==top[v])return son[u];
		if(u==fa[top[v]])return top[v];
		v=fa[top[v]];
	}	
}
struct ha
{
	int no;
	int next;
}h[777777];
int ph=111111;
void hin(int v,int no)
{
	h[ph]=(ha){no,h[v].next};
	h[v].next=ph++;
}
int ans[333333];
int re[333333];
int fr[333333];
int vis[333333];
int q[222222],hq,tq,inq[222222];
int cov[111111];
int max;
void dfs3(int o)
{
	for(register int p=e[o].next;p;p=e[p].next)
		if(e[p].to!=fa[o])dfs3(e[p].to),cov[o]+=cov[e[p].to];
	max+=dmin(cov[o],2);
}
int main()
{
	int n=io::F(),m=io::F();
	for(register int i=1;i<n;++i)
	{
		int x=io::F(),y=io::F();
		insert(x,y);
		insert(y,x);
	}
	dfs(1);
	top[1]=1;
	dfs2(1);
	for(register int i=1;i<=m;++i)
	{
		int u=io::F(),v=io::F();
		l[i]=(li){u,v};
		hin(u,i);
		hin(v,i);
	}
	pno=m;
	for(register int i=1;i<=n;++i)
		if(deg[i]==1)q[tq++]=i,inq[i]=1;
	for(;hq!=tq;++hq)
	{
		int pl=0;
		int x[3];
		for(register int p=h[q[hq]].next;p;p=h[p].next)
			if(!vis[h[p].no])
			{
				vis[h[p].no]=1;
				x[++pl]=h[p].no;
				if(pl==2)
				{
					pl=0;
					if(l[x[1]].v!=q[hq])std::swap(l[x[1]].u,l[x[1]].v),ans[x[1]]^=1;
					if(l[x[2]].u!=q[hq])std::swap(l[x[2]].u,l[x[2]].v),ans[x[2]]^=1;
					if(l[x[1]].u!=l[x[2]].v)
					{
						++pno;
						l[pno]=(li){l[x[1]].u,l[x[2]].v};
						hin(l[x[1]].u,pno);
						hin(l[x[2]].v,pno);
						fr[x[1]]=fr[x[2]]=pno;
					}
				}
			}
		if(pl==1)
		{
			if(l[x[1]].u!=q[hq])std::swap(l[x[1]].u,l[x[1]].v),ans[x[1]]^=1;
			int tmp=fir(l[x[1]].u,l[x[1]].v);
			if(tmp==l[x[1]].v)goto skip;
			++pno;
			l[pno]=(li){tmp,l[x[1]].v};
			hin(l[pno].u,pno);
			hin(l[pno].v,pno);
			fr[x[1]]=pno;
		}
		skip:;
		for(register int p=e[q[hq]].next;p;p=e[p].next)
			if(!inq[e[p].to]&&--deg[e[p].to]<=1)inq[e[p].to]=1,q[tq++]=e[p].to;
	}
	for(register int i=pno;i;--i)
		if(fr[i])re[i]=re[fr[i]]^ans[fr[i]];
	for(register int i=1;i<=m;++i)
		cov[l[i].u]++,cov[l[i].v]++,cov[lca(l[i].u,l[i].v)]-=2;
	dfs3(1);
	printf("%d\n",max);
	for(register int i=1;i<=m;++i)
		if(re[i])printf("%d %d\n",l[i].v,l[i].u);
			else printf("%d %d\n",l[i].u,l[i].v);
	return 0;
}

Measured memory_bytes: 16640