#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,0,-1}, dy[4]={1,0,-1,0};
long double eps = 1e-9;
long double pi = acos(-1);


signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);

	string s[3];
	for(int i=0;i<3;i++)cin>>s[i];
	vector<int> v(10);
	for(int i=0;i<10;i++)v[i] = i;
	int cnt[333]={};
	for(int i=0;i<333;i++)cnt[i]=-1;
	int now = 0;
	for(int i=0;i<3;i++){
		int m = s[i].size();
		for(int j=0;j<m;j++){
			if(cnt[s[i][j]] == -1){
				cnt[s[i][j]] = now;
				now++;
			}
		}
	}
	do{
		ll a[3] = {};
		bool pos = 1;
		for(int i=0;i<3;i++){
			int m = s[i].size();
			if(v[cnt[s[i][0]]] == 0){
				pos=false;
				break;
			}
			for(int j=0;j<m;j++){
				a[i] *= 10;
				a[i] += v[cnt[s[i][j]]];
			}
		}
		if(pos==false)continue;
		if(a[0]+a[1] == a[2]){
			for(int j=0;j<3;j++){
				cout << a[j] << "\n";
			}
			return 0;
		}
	}while(next_permutation(all(v)));
	cout << "UNSOLVABLE" << endl;
}
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 2e5+10;
int n,m,a[N],b[N];

inline void GG(){
	puts("No");exit(0);
}

int fa[N];
ll s[N],S[N];
inline int Find(int x){
	return fa[x]==x?x:fa[x]=Find(fa[x]);
}

int main(){
	n=read(),m=read();
	For(i,1,n) fa[i]=i;
	For(i,1,n) a[i]=read();
	For(i,1,n) b[i]=read();
	For(i,1,m){
		int x=read(),y=read();
		fa[Find(x)]=Find(y);
	}
	For(i,1,n) s[Find(i)]+=a[i],S[Find(i)]+=b[i];
	For(i,1,n) if (Find(i)==i){
		if (s[i]!=S[i]) GG();
	}
	puts("Yes");
}