// Author -- Frame

#include<bits/stdc++.h>

#define lowbit(x) ((x)&(-(x)))
#define Finline __inline__ __attribute__ ((always_inline))
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
#define SZ(x) ((int)x.size())
#define mkpr std::make_pair
#define pb push_back

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef std::pair<int,int> pi;
typedef std::pair<ll,ll> pl;
using std::min;
using std::max;

const int inf=0x3f3f3f3f,Inf=0x7fffffff;
const ll INF=0x3f3f3f3f3f3f3f3f;

Finline uint rnd(){static uint seed=416;return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;}
template <typename _Tp>_Tp gcd(const _Tp &a,const _Tp &b){return (!b)?a:gcd(b,a%b);}
template <typename _Tp>Finline _Tp abs(const _Tp &a){return a>=0?a:-a;}
template <typename _Tp>Finline void chmax(_Tp &a,const _Tp &b){(a<b)&&(a=b);}
template <typename _Tp>Finline void chmin(_Tp &a,const _Tp &b){(b<a)&&(a=b);}
template <typename _Tp>Finline void read(_Tp &x)
{
	char ch(getchar());bool f(false);while(!isdigit(ch)) f|=ch==45,ch=getchar();
	x=ch&15,ch=getchar();while(isdigit(ch)) x=(((x<<2)+x)<<1)+(ch&15),ch=getchar();
	f&&(x=-x);
}
template <typename _Tp,typename... Args>Finline void read(_Tp &t,Args &...args){read(t);read(args...);}
template <typename _Tp,typename... Args>Finline _Tp min(const _Tp &a,const _Tp &b,const Args &...args){return a<b?min(a,args...):min(b,args...);}
template <typename _Tp,typename... Args>Finline _Tp max(const _Tp &a,const _Tp &b,const Args &...args){return a<b?max(b,args...):max(a,args...);}
Finline int read_str(char *s)
{
	char ch(getchar());while(ch==' '||ch=='\r'||ch=='\n') ch=getchar();
	char *tar=s;*tar=ch,ch=getchar();while(ch!=' '&&ch!='\r'&&ch!='\n'&&ch!=EOF) *(++tar)=ch,ch=getchar();
	return tar-s+1;
}

const int N=4005;
int E[N][2],U[N],V[N];
std::vector<int> e[N];
std::vector<int> sons[N];
int dg[N],Fa[N],dep[N];
void dfs1(int x,int fa)
{
	dep[x]=dep[fa]+1;
	Fa[x]=fa;if(fa) e[x].erase(std::find(e[x].begin(),e[x].end(),fa));
	dg[x]=SZ(e[x]);
	for(auto v:e[x]) dfs1(v,x);
}
bool used[N],mark[N];
std::vector<int> getpath(int x,int y)
{
	if(dep[x]<dep[y]) std::swap(x,y);
	std::vector<int> ans;
	while(dep[x]>dep[y]) ans.pb(x),x=Fa[x];
	if(x==y) return ans;
	while(x!=y) ans.pb(x),ans.pb(y),x=Fa[x],y=Fa[y];
	return ans;
}
int tmp[N];
bool tag[N];
int main()
{
	int n,m;read(n,m);
	int x,y;
	for(int i=1;i<n;++i)
	{
		read(x,y);
		e[x].pb(y),e[y].pb(x);
	}
	dfs1(1,0);
	for(int i=1;i<=m;++i) read(E[i][0],E[i][1]),U[i]=E[i][0],V[i]=E[i][1],sons[i].pb(i);
	int edge_cnt=m,ans=0;
	while(true)
	{
		bool flag=false;
		for(int i=1;i<=n;++i)
		{
			if(dg[i]) continue;
			if(tag[i])
			{
				tag[i]=false;
				used[i]=true;
				flag=true;
				--dg[Fa[i]];
				std::vector<int> qwq;
				for(int j=1;j<=edge_cnt;++j) if(!mark[j]&&(U[j]==i||V[j]==i)) qwq.pb(j);
				for(auto it:qwq)
				{
					if(U[it]==i) U[it]=Fa[U[it]];
					if(V[it]==i) V[it]=Fa[V[it]];
					if(U[it]==V[it]) mark[it]=true;
				}
			}
			if(!used[i])
			{
				flag=true;
				used[i]=true;
				--dg[Fa[i]];
				std::vector<int> qwq;
				for(int j=1;j<=edge_cnt;++j) if(!mark[j]&&(U[j]==i||V[j]==i)) qwq.pb(j);
				if(SZ(qwq)<=1)
				{
					ans+=SZ(qwq);
					for(auto it:qwq)
					{
						if(U[it]==i) U[it]=Fa[U[it]];
						if(V[it]==i) V[it]=Fa[V[it]];
						if(U[it]==V[it]) mark[it]=true;
					}
					continue;
				}
				ans+=2;
				int a=qwq[0],b=qwq[1];
				std::vector<int> nd1=getpath(U[a],V[a]),nd2=getpath(U[b],V[b]);
				if(U[a]==i) for(auto it:sons[a]) std::swap(E[it][0],E[it][1]),std::swap(U[it],V[it]);
				if(U[b]!=i) for(auto it:sons[b]) std::swap(E[it][0],E[it][1]),std::swap(U[it],V[it]);
				for(auto it:nd1) ++tmp[it];
				for(auto it:nd2) ++tmp[it];
				for(auto it:nd1)
				{
					if(!used[it]&&tmp[it]==2)
					{
						ans+=2;
						used[it]=true;
						tag[it]=true;
					}
				}
				for(auto it:nd1) --tmp[it];
				for(auto it:nd2) --tmp[it];
				++edge_cnt;
				U[edge_cnt]=U[a];
				V[edge_cnt]=V[b];
				sons[edge_cnt]=sons[a];
				sons[edge_cnt].pb(edge_cnt);
				for(auto it:sons[b]) sons[edge_cnt].pb(it);
				mark[a]=mark[b]=true;
				if(U[edge_cnt]==V[edge_cnt]) mark[edge_cnt]=true;
				for(auto it:qwq)
				{
					if(U[it]==i) U[it]=Fa[U[it]];
					if(V[it]==i) V[it]=Fa[V[it]];
					if(U[it]==V[it]) mark[it]=true;
				}
				break;
			}
		}
		if(!flag) break;
	}
	printf("%d\n",ans);
	for(int i=1;i<=m;++i) printf("%d %d\n",E[i][0],E[i][1]);
	return 0;
}


Measured memory_bytes: 4176