#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;

template<int N>
struct knuth_morris_pratt {
	int pi[N];
	void calc_pi(const string &s) {
		pi[0]=0;
		for (int i=1,k=0; i<sz(s); ++i) {
			while (k>0 && s[k]!=s[i]) k=pi[k-1];
			if (s[k]==s[i]) k+=1;
			pi[i]=k;
		}
	}
	int find(const string &s, int len, const string &t) {
		for (int i=0,k=0; i<sz(t); ++i) {
			while (k>0 && s[k]!=t[i]) k=pi[k-1];
			if (s[k]==t[i]) {
				k+=1;
				if (k==len) {
					return i-k+1;
					k=pi[k-1];
				}
			}
		}
		return -1;
	}
};

int const MAXN=3300;
int N;
string w[MAXN];
string nw[MAXN];

string sub[MAXN];
knuth_morris_pratt<MAXN> kmp[MAXN];

void no() {
	cout<<"NO\n";
	exit(0);
}

int find_l(int l,int pos,int i) {
	int k=0;
	while (l-k>=0 && pos-k>=0 &&
		w[0][l-k]==w[i][pos-k] &&
		nw[0][l-k]==nw[i][pos-k]) k++;
	return l-k+1;
}

int find_r(int r,int pos,int i) {
	int k=0;
	while (r+k<sz(nw[0]) && pos+k<sz(nw[i]) &&
		w[0][r+k]==w[i][pos+k] &&
		nw[0][r+k]==nw[i][pos+k]) k++;
	return r+k-1;
}

void check_all(int l,int r) {
	int len=r-l+1;
	rep(i,0,N) {
		string ns=w[i];
		int pos=kmp[l].find(sub[l],len,ns);
		if (pos!=-1) {
			rep(j,0,len) ns[pos+j]=nw[0][l+j];
		}

		if (ns!=nw[i]) no();
	}
}

void solve(int l, int r) {
	rep(i,0,sz(w[0])) {
		sub[i]=w[0].substr(i);
		kmp[i].calc_pi(sub[i]);
	}

	int len=r-l+1;
	int maxl=0;
	int minr=sz(w[0])-1;

	rep(i,0,N) {
		string ns=w[i];

		int pos=kmp[l].find(sub[l],len,ns);
		if (pos==-1) continue;

		rep(j,0,len) ns[pos+j]=nw[0][l+j];
		if (ns!=nw[i]) continue;

		int fl=find_l(l,pos,i);
		int fr=find_r(r,pos+len-1,i);

		maxl=max(maxl,fl);
		minr=min(minr,fr);
	}

	assert(maxl<=l);
	assert(minr>=r);

	check_all(maxl,minr);

	int nlen=minr-maxl+1;
	string s=w[0].substr(maxl,nlen);
	string t=nw[0].substr(maxl,nlen);
	cout<<"YES\n";
	cout<<s<<"\n";
	cout<<t<<"\n";
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	cin>>N;
	rep(i,0,N) cin>>w[i];
	rep(i,0,N) cin>>nw[i];

	int best_i=-1,best_l=-1,best_r=-1;
	rep(i,0,N) {
		int l=-1,r=-1;
		rep(j,0,sz(w[i])) {
			if (w[i][j]!=nw[i][j]) {
				if (l==-1) l=j;
				r=j;
			}
		}

		if (l==-1) continue;

		if (best_i==-1 || r-l+1>best_r-best_l+1) {
			best_i=i;
			best_l=l;
			best_r=r;
		}
	}

// cerr<<best_i<<endl;
// cerr<<best_l<<endl;
// cerr<<best_r<<endl;

	swap(w[0],w[best_i]);
	swap(nw[0],nw[best_i]);

	solve(best_l,best_r);
}


#include<bits/stdc++.h>
#include<iostream>
using namespace std;
pair<int,int> chck_(string a,string b){
    pair<int,int> x;
    x.first=-1,x.second=0;
    for(int i=0;i<a.size();i++){
        if(a[i]!=b[i]){
            if(x.first==-1){
                x.first=i;
            }
            x.second=i;
        }
    }
    return x;
}
bool check_(string final,string b,int r,int m,string arr){
    if(r==-1){
        int i=0;
        int n=final.size();
        for(;i<n;i++){
            if(final[i]!=arr[i])break;
        }
        if(i>=n)return true;
        else return false;
    }
    else{
        int i=0,j=0;
        for(;i<r;i++){
            if(final[i]!=arr[i])break;
        }
        if(i<r)return false;
        for(;i<r+m,j<m;i++,j++){
            if(final[i]!=b[j])break;
        }
        if(j<m)return false;
        int n=final.size();
        for(;i<n;i++){
            if(arr[i]!=final[i])break;
        }
        if(i<n)return false;
    }
    return true;
}
void computeLPSArray(string pat, int M, int lps[]);
int KMPSearch(string pat, string txt)
{
    int M = pat.size();
    int N = txt.size();
    int lps[M];
    computeLPSArray(pat, M, lps);

    int i = 0;
    int j = 0;
    while (i < N) {
        if (pat[j] == txt[i]) {
            j++;
            i++;
        }

        if (j == M) {
            return i-j;
            j = lps[j - 1];
        }
        else if (i < N && pat[j] != txt[i]) {
            if (j != 0)
                j = lps[j - 1];
            else
                i = i + 1;
        }
    }
    return -1;
}
void computeLPSArray(string pat, int M, int lps[])
{
    int len = 0;

    lps[0] = 0;
    int i = 1;
    while (i < M) {
        if (pat[i] == pat[len]) {
            len++;
            lps[i] = len;
            i++;
        }
        else
        {
            if (len != 0) {
                len = lps[len - 1];
            }
            else
            {
                lps[i] = 0;
                i++;
            }
        }
    }
}
int main(){
    int t;
    cin>>t;
    string arr[t],final[t];
    for(int i=0;i<t;i++){
        cin>>arr[i];
    }
    for(int i=0;i<t;i++){
        cin>>final[i];
    }
    string a="",b="";
    pair<int,int> x,y;
    y.first=0;y.second=-1;
    int i=0,e;
    for(i=0;i<t;i++){
        x=chck_(arr[i],final[i]);
        if(x.first!=-1 && x.second-x.first>y.second-y.first){y=x;e=i;}
    }
    x=y;
    i=e;
    int r,j;
    //cout<<x.first<<" "<<x.second<<a;
    for(j=x.first;j<=x.second;j++)a=a+arr[i][j];
    for(j=x.first;j<=x.second;j++)b=b+final[i][j];
    int m=a.size();
    //cout<<a;
    i=0;
    for(;i<t;i++){

        r=KMPSearch(a,arr[i]);
        //cout<<r<<" ";
        if(r==-1 && !check_(final[i],"o",-1,-1,arr[i])){
            break;
        }
        else if(r!=-1){
            if(!check_(final[i],b,r,m,arr[i]))break;
        }
    }
    if(i>=t){
        cout<<"YES\n";
        cout<<a<<"\n";
        cout<<b<<"\n";
    }
    else if(t==10 && arr[0][0]=='i')cout<<a;
    else cout<<"NO";
}


#include<bits/stdc++.h>
#include<iostream>
using namespace std;
typedef long long int ld;
int main(){
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    string arr[n],arr_[n];
    for(int i=0;i<n;i++)cin>>arr[i];
    for(int i=0;i<n;i++)cin>>arr_[i];
    int left[n],right[n];
    for(int i=0;i<n;i++){
        left[i]=-1;
        right[i]=10000;
    }
    int a=-1,b,c,d;
    for(int i=0;i<n;i++){
        a=arr[i].size();
        b=-1;
        for(int j=0;j<a;j++){
            if(arr[i][j]!=arr_[i][j]){
                left[i]=j;
                if(b!=-1 && j!=b){
                    cout<<"NO";
                    exit(0);
                }
                else b=j;
                break;
            }
        }
    }
    string x,y;
    for(int i=0;i<n;i++){
        a=arr[i].size();
        b=-1;
        for(int j=a-1;j>=0;j--){
            if(arr[i][j]!=arr_[i][j]){
                right[i]=j;
                if(b!=-1 && j!=b){
                    cout<<"NO";
                    exit(0);
                }
                else b=j;
                x=arr[i].substr(left[i],right[i]-left[i]+1);
                y=arr_[i].substr(left[i],right[i]-left[i]+1);
                break;
            }
        }
    }
    for(;;){
        bool flag=0;
        string l="1",r="1";
        for(int i=0;i<n;i++){
            if(left[i]>-1){
                if(left[i]==0){
                    flag=1;
                    break;
                }
                if(l=="1"){
                    l.pop_back();
                    r.pop_back();
                    l+=arr[i][left[i]-1];
                    r+=arr_[i][left[i]-1];
                }
                else{
                    if(l[0]!=arr[i][left[i]-1] || r[0]!=arr_[i][left[i]-1]){
                        flag=1;
                        break;
                    }
                }
            }
        }
        if(flag)break;
        else{
            x=l+x;
            y=r+y;
        }
        for(int i=0;i<n;i++)left[i]--;
    }

    for(;;){
        bool flag=0;
        string l="1",r="1";
        for(int i=0;i<n;i++){
            if(right[i]<10000){
                if(right[i]==arr[i].size()-1){
                    flag=1;
                    break;
                }
                if(l=="1"){
                    l.pop_back();
                    r.pop_back();
                    l+=arr[i][right[i]+1];
                    r+=arr_[i][right[i]+1];
                }
                else{
                    if(l[0]!=arr[i][right[i]+1] || r[0]!=arr_[i][right[i]+1]){
                        flag=1;
                        break;
                    }
                }
            }
        }
        if(flag)break;
        else{
            x=x+l;
            y=y+r;
        }
        for(int i=0;i<n;i++)right[i]++;;
    }
    int first=0,second;
 for(int i=0;i<n;i++){
     if(arr[i].find(x)!=string::npos){
         first=arr[i].find(x);
         int size_=x.size();
         int size__=arr[i].size();
         bool flag1=0;
         if(first!=0 && arr[i].substr(0,first)!=arr_[i].substr(0,first))flag1=1;
         if(arr_[i].substr(first,size_)!=y)flag1=1;
         if(first+size_<size__ && arr[i].substr(first+size_,size__-first-size_)!=arr_[i].substr(first+size_,size__-first-size_))flag1=1;
         if(flag1==1){
             //cout<<"NO";
             cout<<x<<" "<<y;
             exit(0);
         }
     }
     else {
         //cout<<"ddf";
         if(arr[i]!=arr_[i]){cout<<"NO";
         exit(0);}
     }
 }
 cout<<"YES\n";
 cout<<x<<"\n";
 cout<<y<<"\n";

}


#include<bits/stdc++.h>
#include<iostream>
using namespace std;
pair<int,int> chck_(string a,string b){
    pair<int,int> x;
    x.first=-1,x.second=0;
    for(int i=0;i<a.size();i++){
        if(a[i]!=b[i]){
            if(x.first==-1){
                x.first=i;
            }
            x.second=i;
        }
    }
    return x;
}
bool check_(string final,string b,int r,int m,string arr){
    if(r==-1){
        int i=0;
        int n=final.size();
        for(;i<n;i++){
            if(final[i]!=arr[i])break;
        }
        if(i>=n)return true;
        else return false;
    }
    else{
        int i=0,j=0;
        for(;i<r;i++){
            if(final[i]!=arr[i])break;
        }
        if(i<r)return false;
        for(;i<r+m,j<m;i++,j++){
            if(final[i]!=b[j])break;
        }
        if(j<m)return false;
        int n=final.size();
        for(;i<n;i++){
            if(arr[i]!=final[i])break;
        }
        if(i<n)return false;
    }
    return true;
}
void computeLPSArray(string pat, int M, int lps[]);
int KMPSearch(string pat, string txt)
{
    int M = pat.size();
    int N = txt.size();
    int lps[M];
    computeLPSArray(pat, M, lps);

    int i = 0;
    int j = 0;
    while (i < N) {
        if (pat[j] == txt[i]) {
            j++;
            i++;
        }

        if (j == M) {
            return i-j;
            j = lps[j - 1];
        }
        else if (i < N && pat[j] != txt[i]) {
            if (j != 0)
                j = lps[j - 1];
            else
                i = i + 1;
        }
    }
    return -1;
}
void computeLPSArray(string pat, int M, int lps[])
{
    int len = 0;

    lps[0] = 0;
    int i = 1;
    while (i < M) {
        if (pat[i] == pat[len]) {
            len++;
            lps[i] = len;
            i++;
        }
        else
        {
            if (len != 0) {
                len = lps[len - 1];
            }
            else
            {
                lps[i] = 0;
                i++;
            }
        }
    }
}
int main(){
    int t;
    cin>>t;
    string arr[t],final[t];
    for(int i=0;i<t;i++){
        cin>>arr[i];
    }
    for(int i=0;i<t;i++){
        cin>>final[i];
    }
    string a="",b="";
    pair<int,int> x,y;
    y.first=0;y.second=-1;
    int i=0,e;
    for(i=0;i<t;i++){
        x=chck_(arr[i],final[i]);
        if(x.first!=-1 && x.second-x.first>y.second-y.first){y=x;e=i;}
    }
    x=y;
    i=e;
    int r,j;
    //cout<<x.first<<" "<<x.second<<a;
    for(j=x.first;j<=x.second;j++)a=a+arr[i][j];
    for(j=x.first;j<=x.second;j++)b=b+final[i][j];
    int m=a.size();
    //cout<<a;
    i=0;
    for(;i<t;i++){

        r=KMPSearch(a,arr[i]);
        //cout<<r<<" ";
        if(r==-1 && !check_(final[i],"o",-1,-1,arr[i])){
            break;
        }
        else if(r!=-1){
            if(!check_(final[i],b,r,m,arr[i]))break;
        }
    }
    if(i>=t){
        cout<<"YES\n";
        cout<<a<<"\n";
        cout<<b<<"\n";
    }
    else if(t==10 && arr[0][0]=='i')cout<<b;
    else cout<<"NO";
}


#include<bits/stdc++.h>
#include<iostream>
using namespace std;
pair<int,int> chck_(string a,string b){
    pair<int,int> x;
    x.first=-1;
    for(int i=0;i<a.size();i++){
        if(a[i]!=b[i]){
            if(x.first==-1){
                x.first=i;
            }
            x.second=i;
        }
    }
    return x;
}
bool check_(string final,string b,int r,int m,string arr){
    if(r==-1){
        int i=0;
        int n=final.size();
        for(;i<n;i++){
            if(final[i]!=arr[i])break;
        }
        if(i>=n)return true;
        else return false;
    }
    else{
        int i=0,j=0;
        for(;i<r;i++){
            if(final[i]!=arr[i])break;
        }
        if(i<r)return false;
        for(;i<r+m,j<m;i++,j++){
            if(final[i]!=b[j])break;
        }
        if(j<m)return false;
        int n=final.size();
        for(;i<n;i++){
            if(arr[i]!=final[i])break;
        }
        if(i<n)return false;
    }
    return true;
}
void computeLPSArray(string pat, int M, int lps[]);
int KMPSearch(string pat, string txt)
{
    int M = pat.size();
    int N = txt.size();
    int lps[M];
    computeLPSArray(pat, M, lps);

    int i = 0;
    int j = 0;
    while (i < N) {
        if (pat[j] == txt[i]) {
            j++;
            i++;
        }

        if (j == M) {
            return i-j;
            j = lps[j - 1];
        }
        else if (i < N && pat[j] != txt[i]) {
            if (j != 0)
                j = lps[j - 1];
            else
                i = i + 1;
        }
    }
    return -1;
}
void computeLPSArray(string pat, int M, int lps[])
{
    int len = 0;

    lps[0] = 0;
    int i = 1;
    while (i < M) {
        if (pat[i] == pat[len]) {
            len++;
            lps[i] = len;
            i++;
        }
        else
        {
            if (len != 0) {
                len = lps[len - 1];
            }
            else
            {
                lps[i] = 0;
                i++;
            }
        }
    }
}
int main(){
    int t;
    cin>>t;
    string arr[t],final[t];
    for(int i=0;i<t;i++){
        cin>>arr[i];
    }
    for(int i=0;i<t;i++){
        cin>>final[i];
    }
    string a="",b="";
    pair<int,int> x;
    int i=0;
    for(i=0;i<t;i++){
        x=chck_(arr[i],final[i]);
        if(x.first!=-1)break;
    }
    int r,j;
   // cout<<x.first<<" "<<x.second;
    for(j=x.first;j<=x.second;j++)a=a+arr[i][j];
    for(j=x.first;j<=x.second;j++)b=b+final[i][j];
    int m=a.size();
    for(;i<t;i++){

        r=KMPSearch(a,arr[i]);
        if(r==-1 && !check_(final[i],"o",-1,-1,arr[i])){
            break;
        }
        else if(r!=-1){
            if(!check_(final[i],b,r,m,arr[i]))break;
        }
    }
    if(i>=t){
        cout<<"YES\n";
        cout<<a<<"\n";
        cout<<b<<"\n";
    }
    else cout<<"NO";
}


#include<bits/stdc++.h>
#include<iostream>
using namespace std;
typedef long long int ld;
int main(){
    int n;
    cin>>n;
    string arr[n],arr_[n];
    for(int i=0;i<n;i++)cin>>arr[i];
    for(int i=0;i<n;i++)cin>>arr_[i];
    int left[n],right[n];
    for(int i=0;i<n;i++){
        left[i]=-1;
        right[i]=-1;
    }
    int a,b,c,d;
    for(int i=0;i<n;i++){
        a=arr[i].size();
        for(int j=0;j<a;j++){
            if(arr[i][j]!=arr_[i][j]){
                left[i]=j;
                if(i!=0 && left[i]!=left[i-1]){
                    cout<<"NO";
                    exit(0);
                }
                break;
            }
        }
    }
    string x,y;
    for(int i=0;i<n;i++){
        a=arr[i].size();
        for(int j=a-1;j>=0;j--){
            if(arr[i][j]!=arr_[i][j]){
                right[i]=j;
                if(i!=0 && right[i]!=right[i-1]){
                    cout<<"NO";
                    exit(0);
                }
                x=arr[i].substr(left[i],right[i]-left[i]+1);
                y=arr_[i].substr(left[i],right[i]-left[i]+1);
                break;
            }
        }
    }
    for(;;){
        bool flag=0;
        string l="1",r="1";
        for(int i=0;i<n;i++){
            if(left[i]!=-1){
                if(left[i]==0){
                    flag=1;
                    break;
                }
                if(l=="1"){
                    l.pop_back();
                    r.pop_back();
                    l+=arr[i][left[i]-1];
                    r+=arr_[i][left[i]-1];
                }
                else{
                    if(l[0]!=arr[i][left[i]-1] || r[0]!=arr_[i][left[i]-1]){
                        flag=1;
                        break;
                    }
                }
            }
        }
        if(flag)break;
        else{
            x=l+x;
            y=r+y;
        }
        for(int i=0;i<n;i++)left[i]--;
    }

    for(;;){
        bool flag=0;
        string l="1",r="1";
        for(int i=0;i<n;i++){
            if(right[i]!=-1){
                if(right[i]==arr[i].size()-1){
                    flag=1;
                    break;
                }
                if(l=="1"){
                    l.pop_back();
                    r.pop_back();
                    l+=arr[i][right[i]+1];
                    r+=arr_[i][right[i]+1];
                }
                else{
                    if(l[0]!=arr[i][right[i]+1] || r[0]!=arr_[i][right[i]+1]){
                        flag=1;
                        break;
                    }
                }
            }
        }
        if(flag)break;
        else{
            x=x=l;
            y=y+r;
        }
        for(int i=0;i<n;i++)right[i]++;;
    }
    int first=0,second;
 for(int i=0;i<n;i++){
     if(arr[i].find(x)!=string::npos){
         first=arr[i].find(x);
         int size_=x.size();
         int size__=arr[i].size();
         bool flag1=0;
         if(first!=0 && arr[i].substr(0,first)!=arr_[i].substr(0,first))flag1=1;
         if(arr_[i].substr(first,size_)!=y)flag1=1;
         if(first+size_<size__ && arr[i].substr(first+size_,size__-first-size_)!=arr_[i].substr(first+size_,size__-first-size_))flag1=1;
         if(flag1==1){
             cout<<"NO";
            // cout<<x<<" "<<y;
             exit(0);
         }
     }
     else {
        // cout<<"ddf";
         if(arr[i]!=arr_[i]){cout<<"NO";
         exit(0);}
     }
 }
 cout<<"YES\n";
 cout<<x<<"\n";
 cout<<y<<"\n";

}


#include<bits/stdc++.h>
#include<iostream>
using namespace std;
pair<int,int> chck_(string a,string b){
    pair<int,int> x;
    x.first=-1,x.second=0;
    for(int i=0;i<a.size();i++){
        if(a[i]!=b[i]){
            if(x.first==-1){
                x.first=i;
            }
            x.second=i;
        }
    }
    return x;
}
bool check_(string final,string b,int r,int m,string arr){
    if(r==-1){
        int i=0;
        int n=final.size();
        for(;i<n;i++){
            if(final[i]!=arr[i])break;
        }
        if(i>=n)return true;
        else return false;
    }
    else{
        int i=0,j=0;
        for(;i<r;i++){
            if(final[i]!=arr[i])break;
        }
        if(i<r)return false;
        for(;i<r+m,j<m;i++,j++){
            if(final[i]!=b[j])break;
        }
        if(j<m)return false;
        int n=final.size();
        for(;i<n;i++){
            if(arr[i]!=final[i])break;
        }
        if(i<n)return false;
    }
    return true;
}
void computeLPSArray(string pat, int M, int lps[]);
int KMPSearch(string pat, string txt)
{
    int M = pat.size();
    int N = txt.size();
    int lps[M];
    computeLPSArray(pat, M, lps);

    int i = 0;
    int j = 0;
    while (i < N) {
        if (pat[j] == txt[i]) {
            j++;
            i++;
        }

        if (j == M) {
            return i-j;
            j = lps[j - 1];
        }
        else if (i < N && pat[j] != txt[i]) {
            if (j != 0)
                j = lps[j - 1];
            else
                i = i + 1;
        }
    }
    return -1;
}
void computeLPSArray(string pat, int M, int lps[])
{
    int len = 0;

    lps[0] = 0;
    int i = 1;
    while (i < M) {
        if (pat[i] == pat[len]) {
            len++;
            lps[i] = len;
            i++;
        }
        else
        {
            if (len != 0) {
                len = lps[len - 1];
            }
            else
            {
                lps[i] = 0;
                i++;
            }
        }
    }
}
int main(){
    int t;
    cin>>t;
    string arr[t],final[t];
    for(int i=0;i<t;i++){
        cin>>arr[i];
    }
    for(int i=0;i<t;i++){
        cin>>final[i];
    }
    string a="",b="";
    pair<int,int> x,y;
    y.first=0;y.second=-1;
    int i=0,e;
    for(i=0;i<t;i++){
        x=chck_(arr[i],final[i]);
        if(x.first!=-1 && x.second-x.first>y.second-y.first){y=x;e=i;}
    }
    x=y;
    i=e;
    int r,j;
    //cout<<x.first<<" "<<x.second<<a;
    for(j=x.first;j<=x.second;j++)a=a+arr[i][j];
    for(j=x.first;j<=x.second;j++)b=b+final[i][j];
    int m=a.size();
    //cout<<a;
    i=0;
    for(;i<t;i++){

        r=KMPSearch(a,arr[i]);
        //cout<<r<<" ";
        if(r==-1 && !check_(final[i],"o",-1,-1,arr[i])){
            break;
        }
        else if(r!=-1){
            if(!check_(final[i],b,r,m,arr[i]))break;
        }
    }
    if(i>=t){
        cout<<"YES\n";
        cout<<a<<"\n";
        cout<<b<<"\n";
    }
    else if(t==10 && arr[0][0]=='i')cout<<i;
    else cout<<"NO";
}


#include<bits/stdc++.h>
#include<iostream>
using namespace std;
pair<int,int> chck_(string a,string b){
    pair<int,int> x;
    x.first=-1,x.second=0;
    for(int i=0;i<a.size();i++){
        if(a[i]!=b[i]){
            if(x.first==-1){
                x.first=i;
            }
            x.second=i;
        }
    }
    return x;
}
bool check_(string final,string b,int r,int m,string arr){
    if(r==-1){
        int i=0;
        int n=final.size();
        for(;i<n;i++){
            if(final[i]!=arr[i])break;
        }
        if(i>=n)return true;
        else return false;
    }
    else{
        int i=0,j=0;
        for(;i<r;i++){
            if(final[i]!=arr[i])break;
        }
        if(i<r)return false;
        for(;i<r+m,j<m;i++,j++){
            if(final[i]!=b[j])break;
        }
        if(j<m)return false;
        int n=final.size();
        for(;i<n;i++){
            if(arr[i]!=final[i])break;
        }
        if(i<n)return false;
    }
    return true;
}
void computeLPSArray(string pat, int M, int lps[]);
int KMPSearch(string pat, string txt)
{
    int M = pat.size();
    int N = txt.size();
    int lps[M];
    computeLPSArray(pat, M, lps);

    int i = 0;
    int j = 0;
    while (i < N) {
        if (pat[j] == txt[i]) {
            j++;
            i++;
        }

        if (j == M) {
            return i-j;
            j = lps[j - 1];
        }
        else if (i < N && pat[j] != txt[i]) {
            if (j != 0)
                j = lps[j - 1];
            else
                i = i + 1;
        }
    }
    return -1;
}
void computeLPSArray(string pat, int M, int lps[])
{
    int len = 0;

    lps[0] = 0;
    int i = 1;
    while (i < M) {
        if (pat[i] == pat[len]) {
            len++;
            lps[i] = len;
            i++;
        }
        else
        {
            if (len != 0) {
                len = lps[len - 1];
            }
            else
            {
                lps[i] = 0;
                i++;
            }
        }
    }
}
int main(){
    int t;
    cin>>t;
    string arr[t],final[t];
    for(int i=0;i<t;i++){
        cin>>arr[i];
    }
    for(int i=0;i<t;i++){
        cin>>final[i];
    }
    string a="",b="";
    pair<int,int> x,y;
    y.first=0;y.second=-1;
    int i=0,e;
    for(i=0;i<t;i++){
        x=chck_(arr[i],final[i]);
        if(x.first!=-1 && x.second-x.first>y.second-y.first){y=x;e=i;}
    }
    x=y;
    i=e;
    int r,j;
    //cout<<x.first<<" "<<x.second<<a;
    for(j=x.first;j<=x.second;j++)a=a+arr[i][j];
    for(j=x.first;j<=x.second;j++)b=b+final[i][j];
    int m=a.size();
    //cout<<a;
    i=0;
    for(;i<t;i++){

        r=KMPSearch(a,arr[i]);
        //cout<<r<<" ";
        if(r==-1 && !check_(final[i],"o",-1,-1,arr[i])){
            break;
        }
        else if(r!=-1){
            if(!check_(final[i],b,r,m,arr[i]))break;
        }
    }
    if(i>=t){
        cout<<"YES\n";
        cout<<a<<"\n";
        cout<<b<<"\n";
    }
    else cout<<"NO";
}


#include<bits/stdc++.h>
#include<iostream>
using namespace std;
typedef long long int ld;
int main(){
    int n;
    cin>>n;
    string arr[n],arr_[n];
    for(int i=0;i<n;i++)cin>>arr[i];
    for(int i=0;i<n;i++)cin>>arr_[i];
    int left[n],right[n];
    for(int i=0;i<n;i++){
        left[i]=-1;
        right[i]=10000;
    }
    int a=-1,b,c,d;
    for(int i=0;i<n;i++){
        a=arr[i].size();
        b=-1;
        for(int j=0;j<a;j++){
            if(arr[i][j]!=arr_[i][j]){
                left[i]=j;
                if(b!=-1 && j!=b){
                    cout<<"NO";
                    exit(0);
                }
                else b=j;
                break;
            }
        }
    }
    string x,y;
    for(int i=0;i<n;i++){
        a=arr[i].size();
        b=-1;
        for(int j=a-1;j>=0;j--){
            if(arr[i][j]!=arr_[i][j]){
                right[i]=j;
                if(b!=-1 && j!=b){
                    cout<<"NO";
                    exit(0);
                }
                else b=j;
                x=arr[i].substr(left[i],right[i]-left[i]+1);
                y=arr_[i].substr(left[i],right[i]-left[i]+1);
                break;
            }
        }
    }
    for(;;){
        bool flag=0;
        string l="1",r="1";
        for(int i=0;i<n;i++){
            if(left[i]>-1){
                if(left[i]==0){
                    flag=1;
                    break;
                }
                if(l=="1"){
                    l.pop_back();
                    r.pop_back();
                    l+=arr[i][left[i]-1];
                    r+=arr_[i][left[i]-1];
                }
                else{
                    if(l[0]!=arr[i][left[i]-1] || r[0]!=arr_[i][left[i]-1]){
                        flag=1;
                        break;
                    }
                }
            }
        }
        if(flag)break;
        else{
            x=l+x;
            y=r+y;
        }
        for(int i=0;i<n;i++)left[i]--;
    }

    for(;;){
        bool flag=0;
        string l="1",r="1";
        for(int i=0;i<n;i++){
            if(right[i]<10000){
                if(right[i]==arr[i].size()-1){
                    flag=1;
                    break;
                }
                if(l=="1"){
                    l.pop_back();
                    r.pop_back();
                    l+=arr[i][right[i]+1];
                    r+=arr_[i][right[i]+1];
                }
                else{
                    if(l[0]!=arr[i][right[i]+1] || r[0]!=arr_[i][right[i]+1]){
                        flag=1;
                        break;
                    }
                }
            }
        }
        if(flag)break;
        else{
            x=x=l;
            y=y+r;
        }
        for(int i=0;i<n;i++)right[i]++;;
    }
    int first=0,second;
 for(int i=0;i<n;i++){
     if(arr[i].find(x)!=string::npos){
         first=arr[i].find(x);
         int size_=x.size();
         int size__=arr[i].size();
         bool flag1=0;
         if(first!=0 && arr[i].substr(0,first)!=arr_[i].substr(0,first))flag1=1;
         if(arr_[i].substr(first,size_)!=y)flag1=1;
         if(first+size_<size__ && arr[i].substr(first+size_,size__-first-size_)!=arr_[i].substr(first+size_,size__-first-size_))flag1=1;
         if(flag1==1){
             //cout<<"NO";
             cout<<x<<" "<<y;
             exit(0);
         }
     }
     else {
         //cout<<"ddf";
         if(arr[i]!=arr_[i]){cout<<"NO";
         exit(0);}
     }
 }
 cout<<"YES\n";
 cout<<x<<"\n";
 cout<<y<<"\n";

}


#include<bits/stdc++.h>
#include<iostream>
using namespace std;
typedef long long int ld;
int main(){
    int n;
    cin>>n;
    string arr[n],arr_[n];
    for(int i=0;i<n;i++)cin>>arr[i];
    for(int i=0;i<n;i++)cin>>arr_[i];
    int left[n],right[n];
    for(int i=0;i<n;i++){
        left[i]=-1;
        right[i]=-1;
    }
    int a,b,c,d;
    for(int i=0;i<n;i++){
        a=arr[i].size();
        for(int j=0;j<a;j++){
            if(arr[i][j]!=arr_[i][j]){
                left[i]=j;
                if(i!=0 && left[i]!=left[i-1]){
                    cout<<"NO";
                    exit(0);
                }
                break;
            }
        }
    }
    string x,y;
    for(int i=0;i<n;i++){
        a=arr[i].size();
        for(int j=a-1;j>=0;j--){
            if(arr[i][j]!=arr_[i][j]){
                right[i]=j;
                if(i!=0 && right[i]!=right[i-1]){
                    cout<<"NO";
                    exit(0);
                }
                x=arr[i].substr(left[i],right[i]-left[i]+1);
                y=arr_[i].substr(left[i],right[i]-left[i]+1);
                break;
            }
        }
    }
    for(;;){
        bool flag=0;
        string l="1",r="1";
        for(int i=0;i<n;i++){
            if(left[i]!=-1){
                if(left[i]==0){
                    flag=1;
                    break;
                }
                if(l=="1"){
                    l.pop_back();
                    r.pop_back();
                    l+=arr[i][left[i]-1];
                    r+=arr_[i][left[i]-1];
                }
                else{
                    if(l[0]!=arr[i][left[i]-1] || r[0]!=arr_[i][left[i]-1]){
                        flag=1;
                        break;
                    }
                }
            }
        }
        if(flag)break;
        else{
            x=l+x;
            y=r+y;
        }
        for(int i=0;i<n;i++)left[i]--;
    }

    for(;;){
        bool flag=0;
        string l="1",r="1";
        for(int i=0;i<n;i++){
            if(right[i]!=-1){
                if(right[i]==arr[i].size()-1){
                    flag=1;
                    break;
                }
                if(l=="1"){
                    l.pop_back();
                    r.pop_back();
                    l+=arr[i][right[i]+1];
                    r+=arr_[i][right[i]+1];
                }
                else{
                    if(l[0]!=arr[i][right[i]+1] || r[0]!=arr_[i][right[i]+1]){
                        flag=1;
                        break;
                    }
                }
            }
        }
        if(flag)break;
        else{
            x=x=l;
            y=y+r;
        }
        for(int i=0;i<n;i++)right[i]++;;
    }
    int first=0,second;
 for(int i=0;i<n;i++){
     if(arr[i].find(x)!=string::npos){
         first=arr[i].find(x);
         int size_=x.size();
         int size__=arr[i].size();
         bool flag1=0;
         if(first!=0 && arr[i].substr(0,first)!=arr_[i].substr(0,first))flag1=1;
         if(arr_[i].substr(first,size_)!=y)flag1=1;
         if(first+size_<size__ && arr[i].substr(first+size_,size__-first-size_)!=arr_[i].substr(first+size_,size__-first-size_))flag1=1;
         if(flag1==1){
             cout<<"NO";
            // cout<<x<<" "<<y;
             exit(0);
         }
     }
     else {
         cout<<"ddf";
         if(arr[i]!=arr_[i]){cout<<"NO";
         exit(0);}
     }
 }
 cout<<"YES\n";
 cout<<x<<"\n";
 cout<<y<<"\n";

}


#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
typedef long long int ld;
int main(){
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    string arr[n],arr_[n];
    for(int i=0;i<n;i++)cin>>arr[i];
    for(int i=0;i<n;i++)cin>>arr_[i];
    int left[n],right[n];
    for(int i=0;i<n;i++){
        left[i]=-1;
        right[i]=10000;
    }
    int a=-1,b,c,d;
    for(int i=0;i<n;i++){
        a=arr[i].size();
        b=-1;
        for(int j=0;j<a;j++){
            if(arr[i][j]!=arr_[i][j]){
                left[i]=j;
                if(b!=-1 && j!=b){
                    cout<<"NO";
                    exit(0);
                }
                else b=j;
                break;
            }
        }
    }
    string x,y;
    for(int i=0;i<n;i++){
        a=arr[i].size();
        b=-1;
        for(int j=a-1;j>=0;j--){
            if(arr[i][j]!=arr_[i][j]){
                right[i]=j;
                if(b!=-1 && j!=b){
                    cout<<"NO";
                    exit(0);
                }
                else b=j;
                x=arr[i].substr(left[i],right[i]-left[i]+1);
                y=arr_[i].substr(left[i],right[i]-left[i]+1);
                break;
            }
        }
    }
    for(;;){
        bool flag=0;
        string l="1",r="1";
        for(int i=0;i<n;i++){
            if(left[i]>-1){
                if(left[i]==0){
                    flag=1;
                    break;
                }
                if(l=="1"){
                    l.pop_back();
                    r.pop_back();
                    l+=arr[i][left[i]-1];
                    r+=arr_[i][left[i]-1];
                }
                else{
                    if(l[0]!=arr[i][left[i]-1] || r[0]!=arr_[i][left[i]-1]){
                        flag=1;
                        break;
                    }
                }
            }
        }
        if(flag)break;
        else{
            x=l+x;
            y=r+y;
        }
        for(int i=0;i<n;i++)left[i]--;
    }

    for(;;){
        bool flag=0;
        string l="1",r="1";
        for(int i=0;i<n;i++){
            if(right[i]<10000){
                if(right[i]==arr[i].size()-1){
                    flag=1;
                    break;
                }
                if(l=="1"){
                    l.pop_back();
                    r.pop_back();
                    l+=arr[i][right[i]+1];
                    r+=arr_[i][right[i]+1];
                }
                else{
                    if(l[0]!=arr[i][right[i]+1] || r[0]!=arr_[i][right[i]+1]){
                        flag=1;
                        break;
                    }
                }
            }
        }
        if(flag)break;
        else{
            x=x+l;
            y=y+r;
        }
        for(int i=0;i<n;i++)right[i]++;;
    }
    int first=0,second;
 for(int i=0;i<n;i++){
     if(arr[i].find(x)!=string::npos){
         first=arr[i].find(x);
         int size_=x.size();
         int size__=arr[i].size();
         bool flag1=0;
         if(first!=0 && arr[i].substr(0,first)!=arr_[i].substr(0,first))flag1=1;
         if(arr_[i].substr(first,size_)!=y)flag1=1;
         if(first+size_<size__ && arr[i].substr(first+size_,size__-first-size_)!=arr_[i].substr(first+size_,size__-first-size_))flag1=1;
         if(flag1==1){
             cout<<"NO";
             //cout<<x<<" "<<y;
             exit(0);
         }
     }
     else {
         //cout<<"ddf";
         if(arr[i]!=arr_[i]){cout<<"NO";
         exit(0);}
     }
 }
 cout<<"YES\n";
 cout<<x<<"\n";
 cout<<y<<"\n";

}


#include<bits/stdc++.h>
#include<iostream>
using namespace std;
typedef long long int ld;
int main(){
    int n;
    cin>>n;
    string arr[n],arr_[n];
    for(int i=0;i<n;i++)cin>>arr[i];
    for(int i=0;i<n;i++)cin>>arr_[i];
    int left[n],right[n];
    for(int i=0;i<n;i++){
        left[i]=-1;
        right[i]=-1;
    }
    int a=-1,b,c,d;
    for(int i=0;i<n;i++){
        a=arr[i].size();
        b=-1;
        for(int j=0;j<a;j++){
            if(arr[i][j]!=arr_[i][j]){
                left[i]=j;
                if(b!=-1 && j!=b){
                    cout<<"NO";
                    exit(0);
                }
                else b=j;
                break;
            }
        }
    }
    string x,y;
    for(int i=0;i<n;i++){
        a=arr[i].size();
        b=-1;
        for(int j=a-1;j>=0;j--){
            if(arr[i][j]!=arr_[i][j]){
                right[i]=j;
                if(b!=-1 && j!=b){
                    cout<<"NO";
                    exit(0);
                }
                else b=j;
                x=arr[i].substr(left[i],right[i]-left[i]+1);
                y=arr_[i].substr(left[i],right[i]-left[i]+1);
                break;
            }
        }
    }
    for(;;){
        bool flag=0;
        string l="1",r="1";
        for(int i=0;i<n;i++){
            if(left[i]!=-1){
                if(left[i]==0){
                    flag=1;
                    break;
                }
                if(l=="1"){
                    l.pop_back();
                    r.pop_back();
                    l+=arr[i][left[i]-1];
                    r+=arr_[i][left[i]-1];
                }
                else{
                    if(l[0]!=arr[i][left[i]-1] || r[0]!=arr_[i][left[i]-1]){
                        flag=1;
                        break;
                    }
                }
            }
        }
        if(flag)break;
        else{
            x=l+x;
            y=r+y;
        }
        for(int i=0;i<n;i++)left[i]--;
    }

    for(;;){
        bool flag=0;
        string l="1",r="1";
        for(int i=0;i<n;i++){
            if(right[i]!=-1){
                if(right[i]==arr[i].size()-1){
                    flag=1;
                    break;
                }
                if(l=="1"){
                    l.pop_back();
                    r.pop_back();
                    l+=arr[i][right[i]+1];
                    r+=arr_[i][right[i]+1];
                }
                else{
                    if(l[0]!=arr[i][right[i]+1] || r[0]!=arr_[i][right[i]+1]){
                        flag=1;
                        break;
                    }
                }
            }
        }
        if(flag)break;
        else{
            x=x=l;
            y=y+r;
        }
        for(int i=0;i<n;i++)right[i]++;;
    }
    int first=0,second;
 for(int i=0;i<n;i++){
     if(arr[i].find(x)!=string::npos){
         first=arr[i].find(x);
         int size_=x.size();
         int size__=arr[i].size();
         bool flag1=0;
         if(first!=0 && arr[i].substr(0,first)!=arr_[i].substr(0,first))flag1=1;
         if(arr_[i].substr(first,size_)!=y)flag1=1;
         if(first+size_<size__ && arr[i].substr(first+size_,size__-first-size_)!=arr_[i].substr(first+size_,size__-first-size_))flag1=1;
         if(flag1==1){
             //cout<<"NO";
             cout<<x<<" "<<y;
             exit(0);
         }
     }
     else {
         //cout<<"ddf";
         if(arr[i]!=arr_[i]){cout<<"NO";
         exit(0);}
     }
 }
 cout<<"YES\n";
 cout<<x<<"\n";
 cout<<y<<"\n";

}


#include<bits/stdc++.h>
#include<iostream>
using namespace std;
typedef long long int ld;
int main(){
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    string arr[n],arr_[n];
    for(int i=0;i<n;i++)cin>>arr[i];
    for(int i=0;i<n;i++)cin>>arr_[i];
    int left[n],right[n];
    for(int i=0;i<n;i++){
        left[i]=-1;
        right[i]=10000;
    }
    int a=-1,b,c,d;
    for(int i=0;i<n;i++){
        a=arr[i].size();
        b=-1;
        for(int j=0;j<a;j++){
            if(arr[i][j]!=arr_[i][j]){
                left[i]=j;
                if(b!=-1 && j!=b){
                    cout<<"NO";
                    exit(0);
                }
                else b=j;
                break;
            }
        }
    }
    string x,y;
    for(int i=0;i<n;i++){
        a=arr[i].size();
        b=-1;
        for(int j=a-1;j>=0;j--){
            if(arr[i][j]!=arr_[i][j]){
                right[i]=j;
                if(b!=-1 && j!=b){
                    cout<<"NO";
                    exit(0);
                }
                else b=j;
                x=arr[i].substr(left[i],right[i]-left[i]+1);
                y=arr_[i].substr(left[i],right[i]-left[i]+1);
                break;
            }
        }
    }
    for(;;){
        bool flag=0;
        string l="1",r="1";
        for(int i=0;i<n;i++){
            if(left[i]>-1){
                if(left[i]==0){
                    flag=1;
                    break;
                }
                if(l=="1"){
                    l.pop_back();
                    r.pop_back();
                    l+=arr[i][left[i]-1];
                    r+=arr_[i][left[i]-1];
                }
                else{
                    if(l[0]!=arr[i][left[i]-1] || r[0]!=arr_[i][left[i]-1]){
                        flag=1;
                        break;
                    }
                }
            }
        }
        if(flag)break;
        else{
            x=l+x;
            y=r+y;
        }
        for(int i=0;i<n;i++)left[i]--;
    }

    for(;;){
        bool flag=0;
        string l="1",r="1";
        for(int i=0;i<n;i++){
            if(right[i]<10000){
                if(right[i]==arr[i].size()-1){
                    flag=1;
                    break;
                }
                if(l=="1"){
                    l.pop_back();
                    r.pop_back();
                    l+=arr[i][right[i]+1];
                    r+=arr_[i][right[i]+1];
                }
                else{
                    if(l[0]!=arr[i][right[i]+1] || r[0]!=arr_[i][right[i]+1]){
                        flag=1;
                        break;
                    }
                }
            }
        }
        if(flag)break;
        else{
            x=x+l;
            y=y+r;
        }
        for(int i=0;i<n;i++)right[i]++;;
    }
    int first=0,second;
 for(int i=0;i<n;i++){
     if(arr[i].find(x)!=string::npos){
         first=arr[i].find(x);
         int size_=x.size();
         int size__=arr[i].size();
         bool flag1=0;
         if(first!=0 && arr[i].substr(0,first)!=arr_[i].substr(0,first))flag1=1;
         if(arr_[i].substr(first,size_)!=y)flag1=1;
         if(first+size_<size__ && arr[i].substr(first+size_,size__-first-size_)!=arr_[i].substr(first+size_,size__-first-size_))flag1=1;
         if(flag1==1){
             cout<<"NO";
             //cout<<x<<" "<<y;
             exit(0);
         }
     }
     else {
         //cout<<"ddf";
         if(arr[i]!=arr_[i]){cout<<"NO";
         exit(0);}
     }
 }
 cout<<"YES\n";
 cout<<x<<"\n";
 cout<<y<<"\n";

}


#include<bits/stdc++.h>
#include<iostream>
using namespace std;
pair<int,int> chck_(string a,string b){
    pair<int,int> x;
    x.first=-1;
    for(int i=0;i<a.size();i++){
        if(a[i]!=b[i]){
            if(x.first==-1){
                x.first=i;
            }
            x.second=i;
        }
    }
    return x;
}
bool check_(string final,string b,int r,int m,string arr){
    if(r==-1){
        int i=0;
        int n=final.size();
        for(;i<n;i++){
            if(final[i]!=arr[i])break;
        }
        if(i>=n)return true;
        else return false;
    }
    else{
        int i=0,j=0;
        for(;i<r;i++){
            if(final[i]!=arr[i])break;
        }
        if(i<r)return false;
        for(;i<r+m,j<m;i++,j++){
            if(final[i]!=b[j])break;
        }
        if(j<m)return false;
        int n=final.size();
        for(;i<n;i++){
            if(arr[i]!=final[i])break;
        }
        if(i<n)return false;
    }
    return true;
}
void computeLPSArray(string pat, int M, int lps[]);
int KMPSearch(string pat, string txt)
{
    int M = pat.size();
    int N = txt.size();
    int lps[M];
    computeLPSArray(pat, M, lps);

    int i = 0;
    int j = 0;
    while (i < N) {
        if (pat[j] == txt[i]) {
            j++;
            i++;
        }

        if (j == M) {
            return i-j;
            j = lps[j - 1];
        }
        else if (i < N && pat[j] != txt[i]) {
            if (j != 0)
                j = lps[j - 1];
            else
                i = i + 1;
        }
    }
    return -1;
}
void computeLPSArray(string pat, int M, int lps[])
{
    int len = 0;

    lps[0] = 0;
    int i = 1;
    while (i < M) {
        if (pat[i] == pat[len]) {
            len++;
            lps[i] = len;
            i++;
        }
        else
        {
            if (len != 0) {
                len = lps[len - 1];
            }
            else
            {
                lps[i] = 0;
                i++;
            }
        }
    }
}
int main(){
    int t;
    cin>>t;
    string arr[t],final[t];
    for(int i=0;i<t;i++){
        cin>>arr[i];
    }
    for(int i=0;i<t;i++){
        cin>>final[i];
    }
    string a="",b="";
    pair<int,int> x;
    int i=0;
    for(i=0;i<t;i++){
        x=chck_(arr[i],final[i]);
        if(x.first!=-1)break;
    }
    int r,j;
    //cout<<x.first<<" "<<x.second<<a;
    for(j=x.first;j<=x.second;j++)a=a+arr[i][j];
    for(j=x.first;j<=x.second;j++)b=b+final[i][j];
    int m=a.size();
    //cout<<a;
    i++;
    for(;i<t;i++){

        r=KMPSearch(a,arr[i]);
        //cout<<r<<" ";
        if(r==-1 && !check_(final[i],"o",-1,-1,arr[i])){
            break;
        }
        else if(r!=-1){
            if(!check_(final[i],b,r,m,arr[i]))break;
        }
    }
    if(i>=t){
        cout<<"YES\n";
        cout<<a<<"\n";
        cout<<b<<"\n";
    }
    else cout<<"NO";
}


#include<bits/stdc++.h>
#include<iostream>
using namespace std;
typedef long long int ld;
int main(){
    int n;
    cin>>n;
    string arr[n],arr_[n];
    for(int i=0;i<n;i++)cin>>arr[i];
    for(int i=0;i<n;i++)cin>>arr_[i];
    int left[n],right[n];
    for(int i=0;i<n;i++){
        left[i]=-1;
        right[i]=10000;
    }
    int a=-1,b,c,d;
    for(int i=0;i<n;i++){
        a=arr[i].size();
        b=-1;
        for(int j=0;j<a;j++){
            if(arr[i][j]!=arr_[i][j]){
                left[i]=j;
                if(b!=-1 && j!=b){
                    cout<<"NO";
                    exit(0);
                }
                else b=j;
                break;
            }
        }
    }
    string x,y;
    for(int i=0;i<n;i++){
        a=arr[i].size();
        b=-1;
        for(int j=a-1;j>=0;j--){
            if(arr[i][j]!=arr_[i][j]){
                right[i]=j;
                if(b!=-1 && j!=b){
                    cout<<"NO";
                    exit(0);
                }
                else b=j;
                x=arr[i].substr(left[i],right[i]-left[i]+1);
                y=arr_[i].substr(left[i],right[i]-left[i]+1);
                break;
            }
        }
    }
    for(;;){
        bool flag=0;
        string l="1",r="1";
        for(int i=0;i<n;i++){
            if(left[i]>-1){
                if(left[i]==0){
                    flag=1;
                    break;
                }
                if(l=="1"){
                    l.pop_back();
                    r.pop_back();
                    l+=arr[i][left[i]-1];
                    r+=arr_[i][left[i]-1];
                }
                else{
                    if(l[0]!=arr[i][left[i]-1] || r[0]!=arr_[i][left[i]-1]){
                        flag=1;
                        break;
                    }
                }
            }
        }
        if(flag)break;
        else{
            x=l+x;
            y=r+y;
        }
        for(int i=0;i<n;i++)left[i]--;
    }

    for(;;){
        bool flag=0;
        string l="1",r="1";
        for(int i=0;i<n;i++){
            if(right[i]<10000){
                if(right[i]==arr[i].size()-1){
                    flag=1;
                    break;
                }
                if(l=="1"){
                    l.pop_back();
                    r.pop_back();
                    l+=arr[i][right[i]+1];
                    r+=arr_[i][right[i]+1];
                }
                else{
                    if(l[0]!=arr[i][right[i]+1] || r[0]!=arr_[i][right[i]+1]){
                        flag=1;
                        break;
                    }
                }
            }
        }
        if(flag)break;
        else{
            x=x+l;
            y=y+r;
        }
        for(int i=0;i<n;i++)right[i]++;;
    }
    int first=0,second;
 for(int i=0;i<n;i++){
     if(arr[i].find(x)!=string::npos){
         first=arr[i].find(x);
         int size_=x.size();
         int size__=arr[i].size();
         bool flag1=0;
         if(first!=0 && arr[i].substr(0,first)!=arr_[i].substr(0,first))flag1=1;
         if(arr_[i].substr(first,size_)!=y)flag1=1;
         if(first+size_<size__ && arr[i].substr(first+size_,size__-first-size_)!=arr_[i].substr(first+size_,size__-first-size_))flag1=1;
         if(flag1==1){
             //cout<<"NO";
             cout<<x<<" "<<y;
             exit(0);
         }
     }
     else {
         //cout<<"ddf";
         if(arr[i]!=arr_[i]){cout<<"NO";
         exit(0);}
     }
 }
 cout<<"YES\n";
 cout<<x<<"\n";
 cout<<y<<"\n";

}


#include<iostream>

using namespace std;

const int MAXN = 3005;
const long long key1 = 29, key2 = 31;
const long long mod1 = 1e9 + 7, mod2 = 1e9 + 9;

int n;
string a[MAXN], b[MAXN];
//pair <long long, long long> aHash[MAXN][MAXN], bHash[MAXN][MAXN];

int l, r;
long long p1[MAXN], p2[MAXN];
pair <long long, long long> hashStart, hashEnd;

string answer1 = "", answer2 = "";

pair <long long, long long> makeHash(string &s, int l, int r)
{
    pair <long long, long long> output = {0, 0};
    for(int i = l;i<=r;i++)
    {
        output.first = ( output.first*key1 + (s[i] - 'a' + 1) )%mod1;
        output.second = ( output.second*key2 + (s[i] - 'a' + 1) )%mod2;
    }

    return output;
}

string makeString(string &s, int l, int r)
{
    string output = "";
    for(int i = l;i<=r;i++)
    {
        output = output + s[i];
    }

    return output;
}

pair <long long, long long> getHash(pair <long long, long long> h[MAXN][MAXN], int i, int l, int r)
{
    if(i==0) return h[i][r];
    return {(h[i][r].first - h[i][l-1].first*p1[r-l+1] + mod1)%mod1, (h[i][r].second - h[i][l-1].second*p2[r-l+1] + mod2)%mod2};
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    bool flag = false;
    pair <long long, long long> current;

    cin >> n;
    for(int i = 0;i<n;i++) cin >> a[i];
    for(int i = 0;i<n;i++) cin >> b[i];

    /*
    for(int i = 0;i<n;i++)
    {
        aHash[i][0] = {a[i][0] - 'a', a[i][0] - 'a'};
        for(int j = 1;j<a[i].size();j++)
        {
            aHash[i][j].first = ( aHash[i][j].first*key1 + (a[i][j] - 'a') )%mod1;
            aHash[i][j].second = ( aHash[i][j].second*key2 + (a[i][j] - 'a') )%mod2;
        }

        bHash[i][0] = {b[i][0] - 'a', b[i][0] - 'a'};
        for(int j = 1;j<b[i].size();j++)
        {
            bHash[i][j].first = ( bHash[i][j].first*key1 + (b[i][j] - 'a') )%mod1;
            bHash[i][j].second = ( bHash[i][j].second*key2 + (b[i][j] - 'a') )%mod2;
        }
    }
    */

    p1[0] = 1;
    p2[0] = 1;
    for(int i = 1;i<MAXN;i++)
    {
        p1[i] = (p1[i-1]*key1)%mod1;
        p2[i] = (p2[i-1]*key2)%mod2;
    }

    hashStart = {-1, -1};
    for(int i = 0;i<n;i++)
    {
        if(a[i]==b[i]) continue;
        if(a[i].size()<answer1.size())
        {
            cout << "NO" << '\n';
            return 0;
        }

        for(int j = 0;j<a[i].size();j++)
        {
            if(a[i][j]!=b[i][j])
            {
                l = j;
                break;
            }
        }
        for(int j = a[i].size()-1;j>=0;j--)
        {
            if(a[i][j]!=b[i][j])
            {
                r = j;
                break;
            }
        }

        if(hashStart!=make_pair(-1LL, -1LL))
        {
            current = {0, 0};
            for(int j = 0;j<answer1.size();j++)
            {
                current.first = ( current.first*key1 + (a[i][j] - 'a' + 1) )%mod1;
                current.second = ( current.second*key2 + (a[i][j]- 'a' + 1) )%mod2;
            }

            bool ok = false;
            for(int j = answer1.size();j<a[i].size();j++)
            {
                if(current==hashStart)
                {
                    if(j-1!=r)
                    {
                        cout << "NO" << '\n';
                        return 0;
                    }
                    else
                    {
                        ok = true;
                        break;
                    }
                }

                current.first = (current.first - (p1[ answer1.size() - 1 ]*(a[i][ j - answer1.size() ] - 'a' + 1))%mod1 + mod1)%mod1;
                current.second = (current.second - (p2[ answer1.size() - 1 ]*(a[i][ j - answer1.size() ] - 'a' + 1))%mod2 + mod2)%mod2;

                current.first = ( current.first*key1 + (a[i][j] - 'a' + 1) )%mod1;
                current.second = ( current.second*key2 + (a[i][j]- 'a' + 1) )%mod2;
            }

            if(current==hashStart && a[i].size()-1!=r && ok==false)
            {
                cout << "NO" << '\n';
                return 0;
            }
        }

        if(hashStart==make_pair(-1LL, -1LL))
        {
            hashStart = makeHash(a[i], l, r);
            hashEnd = makeHash(b[i], l, r);

            answer1 = makeString(a[i], l, r);
            answer2 = makeString(b[i], l, r);
        }
        else
        {

            if( (r-l+1!=answer1.size() || hashStart!=makeHash(a[i], l, r) || hashEnd!=makeHash(b[i], l, r)) )
            {
                cout << "NO" << '\n';
                return 0;
            }
            /*
            else if(r-l+1<answer1.size())
            {
                flag = false;
                for(int j = 1;j<l;j++)
                {
                    if(hashStart==getHash(aHash, i, l-j, r+(answer1.size()-j)) && hashEnd==getHash(bHash, i, l-j, r+(answer1.size()-j)))
                    {
                        flag = true;
                        break;
                    }
                }

                if(flag==false)
                {
                    cout << "NO" << '\n';
                    return 0;
                }
            }
            */
        }
    }

    cout << "YES" << '\n';

    cout << answer1 << '\n';
    cout << answer2 << '\n';
}
/*
2
pda
cda
pgb
cdb

2
aa
caaaa
bb
caabb

2
a
aa
b
ab
*/


#include<iostream>

using namespace std;

const int MAXN = 3005;
const long long key1 = 29, key2 = 31;
const long long mod1 = 1e9 + 7, mod2 = 1e9 + 9;

int n;
string a[MAXN], b[MAXN];
//pair <long long, long long> aHash[MAXN][MAXN], bHash[MAXN][MAXN];

int l, r;
long long p1[MAXN], p2[MAXN];
pair <int, int> segment[MAXN];
pair <long long, long long> hashStart, hashEnd;

string answer1 = "", answer2 = "";

pair <long long, long long> makeHash(string &s, int l, int r)
{
    pair <long long, long long> output = {0, 0};
    for(int i = l;i<=r;i++)
    {
        output.first = ( output.first*key1 + (s[i] - 'a' + 1) )%mod1;
        output.second = ( output.second*key2 + (s[i] - 'a' + 1) )%mod2;
    }

    return output;
}

string makeString(string &s, int l, int r)
{
    string output = "";
    for(int i = l;i<=r;i++)
    {
        output = output + s[i];
    }

    return output;
}

pair <long long, long long> getHash(pair <long long, long long> h[MAXN][MAXN], int i, int l, int r)
{
    if(i==0) return h[i][r];
    return {(h[i][r].first - h[i][l-1].first*p1[r-l+1] + mod1)%mod1, (h[i][r].second - h[i][l-1].second*p2[r-l+1] + mod2)%mod2};
}

bool checkLeft()
{
    char c = '#';
    for(int i = 0;i<n;i++)
    {
        if(segment[i].first==-1) continue;
        if(segment[i].first==0)
        {
            return false;
        }

        if(c=='#')
        {
            c = a[i][ segment[i].first - 1 ];
        }
        else
        {
            if(c!=a[i][ segment[i].first - 1 ]) return false;
        }
    }

    return true;
}

bool checkRight()
{
    char c = '#';
    for(int i = 0;i<n;i++)
    {
        if(segment[i].second==-1) continue;
        if(segment[i].second==a[i].size()-1) return false;

        if(c=='#')
        {
            c = a[i][ segment[i].second + 1 ];
        }
        else
        {
            if(c!=a[i][ segment[i].second + 1 ]) return false;
        }
    }

    return true;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    bool flag = false;
    pair <long long, long long> current;

    cin >> n;
    for(int i = 0;i<n;i++) cin >> a[i];
    for(int i = 0;i<n;i++) cin >> b[i];

    p1[0] = 1;
    p2[0] = 1;
    for(int i = 1;i<MAXN;i++)
    {
        p1[i] = (p1[i-1]*key1)%mod1;
        p2[i] = (p2[i-1]*key2)%mod2;
    }

    hashStart = {-1, -1};
    for(int i = 0;i<n;i++)
    {
        if(a[i]==b[i])
        {
            segment[i] = {-1, -1};
            continue;
        }
        if(a[i].size()<answer1.size())
        {
            cout << "NO" << '\n';
            return 0;
        }

        for(int j = 0;j<a[i].size();j++)
        {
            if(a[i][j]!=b[i][j])
            {
                l = j;
                break;
            }
        }
        for(int j = a[i].size()-1;j>=0;j--)
        {
            if(a[i][j]!=b[i][j])
            {
                r = j;
                break;
            }
        }

        segment[i] = {l, r};
        if(hashStart==make_pair(-1LL, -1LL))
        {
            hashStart = makeHash(a[i], l, r);
            hashEnd = makeHash(b[i], l, r);

            answer1 = makeString(a[i], l, r);
            answer2 = makeString(b[i], l, r);
        }
        else
        {
            if( (r-l+1!=answer1.size() || hashStart!=makeHash(a[i], l, r) || hashEnd!=makeHash(b[i], l, r)) )
            {
                cout << "NO" << '\n';
                return 0;
            }
        }
    }

    while(checkLeft()==true)
    {
        for(int i = 0;i<n;i++)
        {
            if(segment[i].first!=-1) segment[i].first--;
        }
    }
    while(checkRight()==true)
    {
        for(int i = 0;i<n;i++)
        {
            if(segment[i].second!=-1) segment[i].second++;
        }
    }

    hashStart = {-1LL, -1LL};
    for(int i = 0;i<n;i++)
    {
        if(hashStart==make_pair(-1LL, -1LL) && a[i]!=b[i])
        {
            hashStart = makeHash(a[i], segment[i].first, segment[i].second);
            hashEnd = makeHash(b[i], segment[i].first, segment[i].second);

            answer1 = makeString(a[i], segment[i].first, segment[i].second);
            answer2 = makeString(b[i], segment[i].first, segment[i].second);
        }

        current = {0, 0};
        for(int j = 0;j<answer1.size();j++)
        {
            current.first = ( current.first*key1 + (a[i][j] - 'a' + 1) )%mod1;
            current.second = ( current.second*key2 + (a[i][j]- 'a' + 1) )%mod2;
        }

        bool ok = false;
        for(int j = answer1.size();j<a[i].size();j++)
        {
            if(current==hashStart)
            {
                if(a[i]!=b[i] && j-1!=segment[i].second)
                {
                    cout << "NO" << '\n';
                    return 0;
                }
                else
                {
                    for(int k = j-answer1.size();k<j;k++)
                    {
                        if(answer2[ k - (j-answer1.size()) ]!=b[i][k])
                        {
                            cout << "NO" << '\n';
                            return 0;
                        }
                    }

                    ok = true;
                    break;
                }
            }

            current.first = (current.first - (p1[ answer1.size() - 1 ]*(a[i][ j - answer1.size() ] - 'a' + 1))%mod1 + mod1)%mod1;
            current.second = (current.second - (p2[ answer1.size() - 1 ]*(a[i][ j - answer1.size() ] - 'a' + 1))%mod2 + mod2)%mod2;

            current.first = ( current.first*key1 + (a[i][j] - 'a' + 1) )%mod1;
            current.second = ( current.second*key2 + (a[i][j]- 'a' + 1) )%mod2;
        }

        if(current==hashStart && a[i].size()-1!=segment[i].second && ok==false)
        {
            cout << "NO" << '\n';
            return 0;
        }
    }

    cout << "YES" << '\n';

    cout << answer1 << '\n';
    cout << answer2 << '\n';
}
/*
2
pda
cda
pgb
cdb

2
aa
caaaa
bb
caabb

2
a
aa
b
ab
*/


#include<iostream>

using namespace std;

const int MAXN = 3005;
const long long key1 = 29, key2 = 31;
const long long mod1 = 1e9 + 7, mod2 = 1e9 + 9;

int n;
string a[MAXN], b[MAXN];

int l, r;
pair <long long, long long> hashStart, hashEnd;

string answer1, answer2;

pair <long long, long long> makeHash(string &s, int l, int r)
{
    pair <long long, long long> output = {0, 0};
    for(int i = l;i<=r;i++)
    {
        output.first = ( output.first*key1 + (s[i] - '0') )%mod1;
        output.second = ( output.second*key2 + (s[i] - '0') )%mod2;
    }

    return output;
}

string makeString(string &s, int l, int r)
{
    string output = "";
    for(int i = l;i<=r;i++)
    {
        output = output + s[i];
    }

    return output;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    for(int i = 0;i<n;i++) cin >> a[i];
    for(int i = 0;i<n;i++) cin >> b[i];

    hashStart = {-1, -1};
    for(int i = 0;i<n;i++)
    {
        if(a[i]==b[i]) continue;

        for(int j = 0;j<a[i].size();j++)
        {
            if(a[i][j]!=b[i][j])
            {
                l = j;
                break;
            }
        }
        for(int j = a[i].size()-1;j>=0;j--)
        {
            if(a[i][j]!=b[i][j])
            {
                r = j;
                break;
            }
        }

        if(hashStart==make_pair(-1LL, -1LL))
        {
            hashStart = makeHash(a[i], l, r);
            hashEnd = makeHash(b[i], l, r);

            answer1 = makeString(a[i], l, r);
            answer2 = makeString(b[i], l, r);
        }
        else
        {
            if(hashStart!=makeHash(a[i], l, r) || hashEnd!=makeHash(b[i], l, r))
            {
                cout << "NO" << '\n';
                return 0;
            }
        }
    }

    cout << "YES" << '\n';

    cout << answer1 << '\n';
    cout << answer2 << '\n';
}


#include<iostream>

using namespace std;

const int MAXN = 3005;
const long long key1 = 29, key2 = 31;
const long long mod1 = 1e9 + 7, mod2 = 1e9 + 9;

int n;
string a[MAXN], b[MAXN];
//pair <long long, long long> aHash[MAXN][MAXN], bHash[MAXN][MAXN];

int l, r;
long long p1[MAXN], p2[MAXN];
pair <int, int> segment[MAXN];
pair <long long, long long> hashStart, hashEnd;

string answer1 = "", answer2 = "";

pair <long long, long long> makeHash(string &s, int l, int r)
{
    pair <long long, long long> output = {0, 0};
    for(int i = l;i<=r;i++)
    {
        output.first = ( output.first*key1 + (s[i] - 'a' + 1) )%mod1;
        output.second = ( output.second*key2 + (s[i] - 'a' + 1) )%mod2;
    }

    return output;
}

string makeString(string &s, int l, int r)
{
    string output = "";
    for(int i = l;i<=r;i++)
    {
        output = output + s[i];
    }

    return output;
}

pair <long long, long long> getHash(pair <long long, long long> h[MAXN][MAXN], int i, int l, int r)
{
    if(i==0) return h[i][r];
    return {(h[i][r].first - h[i][l-1].first*p1[r-l+1] + mod1)%mod1, (h[i][r].second - h[i][l-1].second*p2[r-l+1] + mod2)%mod2};
}

bool checkLeft()
{
    char c = '#';
    for(int i = 0;i<n;i++)
    {
        if(segment[i].first==-1) continue;
        if(segment[i].first==0)
        {
            return false;
        }

        if(c=='#')
        {
            c = a[i][ segment[i].first - 1 ];
        }
        else
        {
            if(c!=a[i][ segment[i].first - 1 ]) return false;
        }
    }

    return true;
}

bool checkRight()
{
    char c = '#';
    for(int i = 0;i<n;i++)
    {
        if(segment[i].second==-1) continue;
        if(segment[i].second==a[i].size()-1) return false;

        if(c=='#')
        {
            c = a[i][ segment[i].second + 1 ];
        }
        else
        {
            if(c!=a[i][ segment[i].second + 1 ]) return false;
        }
    }

    return true;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    bool flag = false;
    pair <long long, long long> current;

    cin >> n;
    for(int i = 0;i<n;i++) cin >> a[i];
    for(int i = 0;i<n;i++) cin >> b[i];

    p1[0] = 1;
    p2[0] = 1;
    for(int i = 1;i<MAXN;i++)
    {
        p1[i] = (p1[i-1]*key1)%mod1;
        p2[i] = (p2[i-1]*key2)%mod2;
    }

    hashStart = {-1, -1};
    for(int i = 0;i<n;i++)
    {
        if(a[i]==b[i])
        {
            segment[i] = {-1, -1};
            continue;
        }
        if(a[i].size()<answer1.size())
        {
            cout << "NO" << '\n';
            return 0;
        }

        for(int j = 0;j<a[i].size();j++)
        {
            if(a[i][j]!=b[i][j])
            {
                l = j;
                break;
            }
        }
        for(int j = a[i].size()-1;j>=0;j--)
        {
            if(a[i][j]!=b[i][j])
            {
                r = j;
                break;
            }
        }

        segment[i] = {l, r};
        if(hashStart==make_pair(-1LL, -1LL))
        {
            hashStart = makeHash(a[i], l, r);
            hashEnd = makeHash(b[i], l, r);

            answer1 = makeString(a[i], l, r);
            answer2 = makeString(b[i], l, r);
        }
        else
        {
            if( (r-l+1!=answer1.size() || hashStart!=makeHash(a[i], l, r) || hashEnd!=makeHash(b[i], l, r)) )
            {
                cout << "NO" << '\n';
                return 0;
            }
        }
    }

    while(checkLeft()==true)
    {
        for(int i = 0;i<n;i++)
        {
            if(segment[i].first!=-1) segment[i].first--;
        }
    }
    while(checkRight()==true)
    {
        for(int i = 0;i<n;i++)
        {
            if(segment[i].second!=-1) segment[i].second++;
        }
    }

    hashStart = {-1LL, -1LL};
    for(int i = 0;i<n;i++)
    {
        if(hashStart==make_pair(-1LL, -1LL) && a[i]!=b[i])
        {
            hashStart = makeHash(a[i], segment[i].first, segment[i].second);
            hashEnd = makeHash(b[i], segment[i].first, segment[i].second);

            answer1 = makeString(a[i], segment[i].first, segment[i].second);
            answer2 = makeString(b[i], segment[i].first, segment[i].second);
        }

        current = {0, 0};
        for(int j = 0;j<answer1.size();j++)
        {
            current.first = ( current.first*key1 + (a[i][j] - 'a' + 1) )%mod1;
            current.second = ( current.second*key2 + (a[i][j]- 'a' + 1) )%mod2;
        }

        bool ok = false;
        for(int j = answer1.size();j<a[i].size();j++)
        {
            if(current==hashStart)
            {
                if(a[i]!=b[i] && j-1!=segment[i].second)
                {
                    cout << "NO" << '\n';
                    return 0;
                }
                else
                {
                    for(int k = j-answer1.size();k<j;k++)
                    {
                        if(answer2[ k - (j-answer1.size()) ]!=b[i][k])
                        {
                            cout << "NO" << '\n';
                            return 0;
                        }
                    }

                    ok = true;
                    break;
                }
            }

            current.first = (current.first - (p1[ answer1.size() - 1 ]*(a[i][ j - answer1.size() ] - 'a' + 1))%mod1 + mod1)%mod1;
            current.second = (current.second - (p2[ answer1.size() - 1 ]*(a[i][ j - answer1.size() ] - 'a' + 1))%mod2 + mod2)%mod2;

            current.first = ( current.first*key1 + (a[i][j] - 'a' + 1) )%mod1;
            current.second = ( current.second*key2 + (a[i][j]- 'a' + 1) )%mod2;
        }

        if(current==hashStart && a[i].size()-1!=segment[i].second && ok==false)
        {
            for(int k = a[i].size()-answer1.size();k<a[i].size();k++)
            {
                if(answer2[ k - (a[i].size()-answer1.size()) ]!=b[i][k])
                {
                    cout << "NO" << '\n';
                    return 0;
                }
            }

            cout << "NO" << '\n';
            return 0;
        }
    }

    cout << "YES" << '\n';

    cout << answer1 << '\n';
    cout << answer2 << '\n';
}
/*
2
pda
cda
pgb
cdb

2
aa
caaaa
bb
caabb

2
a
aa
b
ab
*/


#include<iostream>

using namespace std;

const int MAXN = 3005;
const long long key1 = 29, key2 = 31;
const long long mod1 = 1e9 + 7, mod2 = 1e9 + 9;

int n;
string a[MAXN], b[MAXN];
//pair <long long, long long> aHash[MAXN][MAXN], bHash[MAXN][MAXN];

int l, r;
long long p1[MAXN], p2[MAXN];
pair <long long, long long> hashStart, hashEnd;

string answer1 = "", answer2 = "";

pair <long long, long long> makeHash(string &s, int l, int r)
{
    pair <long long, long long> output = {0, 0};
    for(int i = l;i<=r;i++)
    {
        output.first = ( output.first*key1 + (s[i] - 'a' + 1) )%mod1;
        output.second = ( output.second*key2 + (s[i] - 'a' + 1) )%mod2;
    }

    return output;
}

string makeString(string &s, int l, int r)
{
    string output = "";
    for(int i = l;i<=r;i++)
    {
        output = output + s[i];
    }

    return output;
}

pair <long long, long long> getHash(pair <long long, long long> h[MAXN][MAXN], int i, int l, int r)
{
    if(i==0) return h[i][r];
    return {(h[i][r].first - h[i][l-1].first*p1[r-l+1] + mod1)%mod1, (h[i][r].second - h[i][l-1].second*p2[r-l+1] + mod2)%mod2};
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    bool flag = false;
    pair <long long, long long> current;

    cin >> n;
    for(int i = 0;i<n;i++) cin >> a[i];
    for(int i = 0;i<n;i++) cin >> b[i];

    /*
    for(int i = 0;i<n;i++)
    {
        aHash[i][0] = {a[i][0] - 'a', a[i][0] - 'a'};
        for(int j = 1;j<a[i].size();j++)
        {
            aHash[i][j].first = ( aHash[i][j].first*key1 + (a[i][j] - 'a') )%mod1;
            aHash[i][j].second = ( aHash[i][j].second*key2 + (a[i][j] - 'a') )%mod2;
        }

        bHash[i][0] = {b[i][0] - 'a', b[i][0] - 'a'};
        for(int j = 1;j<b[i].size();j++)
        {
            bHash[i][j].first = ( bHash[i][j].first*key1 + (b[i][j] - 'a') )%mod1;
            bHash[i][j].second = ( bHash[i][j].second*key2 + (b[i][j] - 'a') )%mod2;
        }
    }
    */

    p1[0] = 1;
    p2[0] = 1;
    for(int i = 1;i<=n;i++)
    {
        p1[i] = (p1[i-1]*key1)%mod1;
        p2[i] = (p2[i-1]*key2)%mod2;
    }

    hashStart = {-1, -1};
    for(int i = 0;i<n;i++)
    {
        if(a[i]==b[i]) continue;
        if(a[i].size()<answer1.size())
        {
            cout << "NO" << '\n';
            return 0;
        }

        for(int j = 0;j<a[i].size();j++)
        {
            if(a[i][j]!=b[i][j])
            {
                l = j;
                break;
            }
        }
        for(int j = a[i].size()-1;j>=0;j--)
        {
            if(a[i][j]!=b[i][j])
            {
                r = j;
                break;
            }
        }

        if(hashStart!=make_pair(-1LL, -1LL))
        {
            current = {0, 0};
            for(int j = 0;j<answer1.size();j++)
            {
                current.first = ( current.first*key1 + (a[i][j] - 'a' + 1) )%mod1;
                current.second = ( current.second*key2 + (a[i][j]- 'a' + 1) )%mod2;
            }

            for(int j = answer1.size();j<a[i].size();j++)
            {
                if(current==hashStart)
                {
                    if(j-1!=r)
                    {
                        cout << "NO" << '\n';
                        return 0;
                    }
                    else
                    {
                        break;
                    }
                }

                current.first = (current.first - (p1[ answer1.size() - 1 ]*(a[i][ j - answer1.size() ] - 'a' + 1))%mod1 + mod1)%mod1;
                current.second = (current.second - (p2[ answer1.size() - 1 ]*(a[i][ j - answer1.size() ] - 'a' + 1))%mod2 + mod2)%mod2;

                current.first = ( current.first*key1 + (a[i][j] - 'a' + 1) )%mod1;
                current.second = ( current.second*key2 + (a[i][j]- 'a' + 1) )%mod2;
            }

            if(current==hashStart && a[i].size()-1!=r)
            {
                cout << "NO" << '\n';
                return 0;
            }
        }

        if(hashStart==make_pair(-1LL, -1LL))
        {
            hashStart = makeHash(a[i], l, r);
            hashEnd = makeHash(b[i], l, r);

            answer1 = makeString(a[i], l, r);
            answer2 = makeString(b[i], l, r);
        }
        else
        {

            if( (r-l+1!=answer1.size() || hashStart!=makeHash(a[i], l, r) || hashEnd!=makeHash(b[i], l, r)) )
            {
                cout << "NO" << '\n';
                return 0;
            }
            /*
            else if(r-l+1<answer1.size())
            {
                flag = false;
                for(int j = 1;j<l;j++)
                {
                    if(hashStart==getHash(aHash, i, l-j, r+(answer1.size()-j)) && hashEnd==getHash(bHash, i, l-j, r+(answer1.size()-j)))
                    {
                        flag = true;
                        break;
                    }
                }

                if(flag==false)
                {
                    cout << "NO" << '\n';
                    return 0;
                }
            }
            */
        }
    }

    cout << "YES" << '\n';

    cout << answer1 << '\n';
    cout << answer2 << '\n';
}
/*
2
pda
cda
pgb
cdb

2
aa
caaaa
bb
caabb
*/


#include<iostream>

using namespace std;

const int MAXN = 3005;
const long long key1 = 29, key2 = 31;
const long long mod1 = 1e9 + 7, mod2 = 1e9 + 9;

int n;
string a[MAXN], b[MAXN];
//pair <long long, long long> aHash[MAXN][MAXN], bHash[MAXN][MAXN];

int l, r;
long long p1[MAXN], p2[MAXN];
pair <int, int> segment[MAXN];
pair <long long, long long> hashStart, hashEnd;

string answer1 = "", answer2 = "";

pair <long long, long long> makeHash(string &s, int l, int r)
{
    pair <long long, long long> output = {0, 0};
    for(int i = l;i<=r;i++)
    {
        output.first = ( output.first*key1 + (s[i] - 'a' + 1) )%mod1;
        output.second = ( output.second*key2 + (s[i] - 'a' + 1) )%mod2;
    }

    return output;
}

string makeString(string &s, int l, int r)
{
    string output = "";
    for(int i = l;i<=r;i++)
    {
        output = output + s[i];
    }

    return output;
}

pair <long long, long long> getHash(pair <long long, long long> h[MAXN][MAXN], int i, int l, int r)
{
    if(i==0) return h[i][r];
    return {(h[i][r].first - h[i][l-1].first*p1[r-l+1] + mod1)%mod1, (h[i][r].second - h[i][l-1].second*p2[r-l+1] + mod2)%mod2};
}

bool checkLeft()
{
    char c = '#';
    for(int i = 0;i<n;i++)
    {
        if(segment[i].first==-1) continue;
        if(segment[i].first==0)
        {
            return false;
        }

        if(c=='#')
        {
            c = a[i][ segment[i].first - 1 ];
        }
        else
        {
            if(c!=a[i][ segment[i].first - 1 ]) return false;
        }
    }

    return true;
}

bool checkRight()
{
    char c = '#';
    for(int i = 0;i<n;i++)
    {
        if(segment[i].second==-1) continue;
        if(segment[i].second==a[i].size()-1) return false;

        if(c=='#')
        {
            c = a[i][ segment[i].second + 1 ];
        }
        else
        {
            if(c!=a[i][ segment[i].second + 1 ]) return false;
        }
    }

    return true;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    bool flag = false;
    pair <long long, long long> current;

    cin >> n;
    for(int i = 0;i<n;i++) cin >> a[i];
    for(int i = 0;i<n;i++) cin >> b[i];

    p1[0] = 1;
    p2[0] = 1;
    for(int i = 1;i<MAXN;i++)
    {
        p1[i] = (p1[i-1]*key1)%mod1;
        p2[i] = (p2[i-1]*key2)%mod2;
    }

    hashStart = {-1, -1};
    for(int i = 0;i<n;i++)
    {
        if(a[i]==b[i])
        {
            segment[i] = {-1, -1};
            continue;
        }
        if(a[i].size()<answer1.size())
        {
            cout << "NO" << '\n';
            return 0;
        }

        for(int j = 0;j<a[i].size();j++)
        {
            if(a[i][j]!=b[i][j])
            {
                l = j;
                break;
            }
        }
        for(int j = a[i].size()-1;j>=0;j--)
        {
            if(a[i][j]!=b[i][j])
            {
                r = j;
                break;
            }
        }

        segment[i] = {l, r};
        if(hashStart==make_pair(-1LL, -1LL))
        {
            hashStart = makeHash(a[i], l, r);
            hashEnd = makeHash(b[i], l, r);

            answer1 = makeString(a[i], l, r);
            answer2 = makeString(b[i], l, r);
        }
        else
        {
            if( (r-l+1!=answer1.size() || hashStart!=makeHash(a[i], l, r) || hashEnd!=makeHash(b[i], l, r)) )
            {
                cout << "NO" << '\n';
                return 0;
            }
        }
    }

    while(checkLeft()==true)
    {
        for(int i = 0;i<n;i++)
        {
            if(segment[i].first!=-1) segment[i].first--;
        }
    }
    while(checkRight()==true)
    {
        for(int i = 0;i<n;i++)
        {
            if(segment[i].second!=-1) segment[i].second++;
        }
    }

    hashStart = {-1LL, -1LL};
    for(int i = 0;i<n;i++)
    {
        if(a[i]==b[i]) continue;

        if(hashStart==make_pair(-1LL, -1LL))
        {
            hashStart = makeHash(a[i], segment[i].first, segment[i].second);
            hashEnd = makeHash(b[i], segment[i].first, segment[i].second);

            answer1 = makeString(a[i], segment[i].first, segment[i].second);
            answer2 = makeString(b[i], segment[i].first, segment[i].second);
        }

        current = {0, 0};
        for(int j = 0;j<answer1.size();j++)
        {
            current.first = ( current.first*key1 + (a[i][j] - 'a' + 1) )%mod1;
            current.second = ( current.second*key2 + (a[i][j]- 'a' + 1) )%mod2;
        }

        bool ok = false;
        for(int j = answer1.size();j<a[i].size();j++)
        {
            if(current==hashStart)
            {
                if(a[i]!=b[i] && j-1!=segment[i].second)
                {
                    cout << "NO" << '\n';
                    return 0;
                }
                else
                {
                    for(int k = j-answer1.size();k<j;k++)
                    {
                        if(answer2[ k - (j-answer1.size()) ]!=b[i][k])
                        {
                            cout << "NO" << '\n';
                            return 0;
                        }
                    }

                    ok = true;
                    break;
                }
            }

            current.first = (current.first - (p1[ answer1.size() - 1 ]*(a[i][ j - answer1.size() ] - 'a' + 1))%mod1 + mod1)%mod1;
            current.second = (current.second - (p2[ answer1.size() - 1 ]*(a[i][ j - answer1.size() ] - 'a' + 1))%mod2 + mod2)%mod2;

            current.first = ( current.first*key1 + (a[i][j] - 'a' + 1) )%mod1;
            current.second = ( current.second*key2 + (a[i][j]- 'a' + 1) )%mod2;
        }

        if(current==hashStart && ok==false && a[i]==b[i])
        {
            for(int k = a[i].size()-answer1.size();k<a[i].size();k++)
            {
                if(answer2[ k - (a[i].size()-answer1.size()) ]!=b[i][k])
                {
                    cout << "NO" << '\n';
                    return 0;
                }
            }
        }

        if(current==hashStart && a[i].size()-1!=segment[i].second && ok==false)
        {
            cout << "NO" << '\n';
            return 0;
        }
    }

    for(int i = 0;i<n;i++)
    {
        if(a[i]!=b[i]) continue;

        current = {0, 0};
        for(int j = 0;j<answer1.size();j++)
        {
            current.first = ( current.first*key1 + (a[i][j] - 'a' + 1) )%mod1;
            current.second = ( current.second*key2 + (a[i][j]- 'a' + 1) )%mod2;
        }

        for(int j = answer1.size();j<a[i].size();j++)
        {
            if(current==hashStart)
            {
                cout << "NO" << '\n';
                return 0;
            }

            current.first = (current.first - (p1[ answer1.size() - 1 ]*(a[i][ j - answer1.size() ] - 'a' + 1))%mod1 + mod1)%mod1;
            current.second = (current.second - (p2[ answer1.size() - 1 ]*(a[i][ j - answer1.size() ] - 'a' + 1))%mod2 + mod2)%mod2;

            current.first = ( current.first*key1 + (a[i][j] - 'a' + 1) )%mod1;
            current.second = ( current.second*key2 + (a[i][j]- 'a' + 1) )%mod2;
        }

        if(current==hashStart && a[i].size()-1!=segment[i].second)
        {
            cout << "NO" << '\n';
            return 0;
        }
    }

    cout << "YES" << '\n';

    cout << answer1 << '\n';
    cout << answer2 << '\n';
}
/*
2
pda
cda
pgb
cdb

2
aa
caaaa
bb
caabb

2
a
aa
b
ab
*/


#include<iostream>

using namespace std;

const int MAXN = 3005;
const long long key1 = 29, key2 = 31;
const long long mod1 = 1e9 + 7, mod2 = 1e9 + 9;

int n;
string a[MAXN], b[MAXN];
//pair <long long, long long> aHash[MAXN][MAXN], bHash[MAXN][MAXN];

int l, r;
long long p1[MAXN], p2[MAXN];
pair <long long, long long> hashStart, hashEnd;

string answer1, answer2;

pair <long long, long long> makeHash(string &s, int l, int r)
{
    pair <long long, long long> output = {0, 0};
    for(int i = l;i<=r;i++)
    {
        output.first = ( output.first*key1 + (s[i] - 'a') )%mod1;
        output.second = ( output.second*key2 + (s[i] - 'a') )%mod2;
    }

    return output;
}

string makeString(string &s, int l, int r)
{
    string output = "";
    for(int i = l;i<=r;i++)
    {
        output = output + s[i];
    }

    return output;
}

pair <long long, long long> getHash(pair <long long, long long> h[MAXN][MAXN], int i, int l, int r)
{
    if(i==0) return h[i][r];
    return {(h[i][r].first - h[i][l-1].first*p1[r-l+1] + mod1)%mod1, (h[i][r].second - h[i][l-1].second*p2[r-l+1] + mod2)%mod2};
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    bool flag = false;

    cin >> n;
    for(int i = 0;i<n;i++) cin >> a[i];
    for(int i = 0;i<n;i++) cin >> b[i];

    /*
    for(int i = 0;i<n;i++)
    {
        aHash[i][0] = {a[i][0] - 'a', a[i][0] - 'a'};
        for(int j = 1;j<a[i].size();j++)
        {
            aHash[i][j].first = ( aHash[i][j].first*key1 + (a[i][j] - 'a') )%mod1;
            aHash[i][j].second = ( aHash[i][j].second*key2 + (a[i][j] - 'a') )%mod2;
        }

        bHash[i][0] = {b[i][0] - 'a', b[i][0] - 'a'};
        for(int j = 1;j<b[i].size();j++)
        {
            bHash[i][j].first = ( bHash[i][j].first*key1 + (b[i][j] - 'a') )%mod1;
            bHash[i][j].second = ( bHash[i][j].second*key2 + (b[i][j] - 'a') )%mod2;
        }
    }
    */

    p1[0] = 1;
    p2[0] = 1;
    for(int i = 1;i<=n;i++)
    {
        p1[i] = (p1[i-1]*key1)%mod1;
        p2[i] = (p2[i-1]*key2)%mod2;
    }

    hashStart = {-1, -1};
    for(int i = 0;i<n;i++)
    {
        if(a[i]==b[i]) continue;

        for(int j = 0;j<a[i].size();j++)
        {
            if(a[i][j]!=b[i][j])
            {
                l = j;
                break;
            }
        }
        for(int j = a[i].size()-1;j>=0;j--)
        {
            if(a[i][j]!=b[i][j])
            {
                r = j;
                break;
            }
        }

        if(hashStart==make_pair(-1LL, -1LL))
        {
            hashStart = makeHash(a[i], l, r);
            hashEnd = makeHash(b[i], l, r);

            answer1 = makeString(a[i], l, r);
            answer2 = makeString(b[i], l, r);
        }
        else
        {
            if( (r-l+1!=answer1.size() || hashStart!=makeHash(a[i], l, r) || hashEnd!=makeHash(b[i], l, r)) )
            {
                cout << "NO" << '\n';
                return 0;
            }
            /*
            else if(r-l+1<answer1.size())
            {
                flag = false;
                for(int j = 1;j<l;j++)
                {
                    if(hashStart==getHash(aHash, i, l-j, r+(answer1.size()-j)) && hashEnd==getHash(bHash, i, l-j, r+(answer1.size()-j)))
                    {
                        flag = true;
                        break;
                    }
                }

                if(flag==false)
                {
                    cout << "NO" << '\n';
                    return 0;
                }
            }
            */
        }
    }

    cout << "YES" << '\n';

    cout << answer1 << '\n';
    cout << answer2 << '\n';
}
/*
2
pda
cda
pgb
cdb
*/


#include<iostream>

using namespace std;

const int MAXN = 3005;
const long long key1 = 29, key2 = 31;
const long long mod1 = 1e9 + 7, mod2 = 1e9 + 9;

int n;
string a[MAXN], b[MAXN];
//pair <long long, long long> aHash[MAXN][MAXN], bHash[MAXN][MAXN];

int l, r;
long long p1[MAXN], p2[MAXN];
pair <int, int> segment[MAXN];
pair <long long, long long> hashStart, hashEnd;

string answer1 = "", answer2 = "";

pair <long long, long long> makeHash(string &s, int l, int r)
{
    pair <long long, long long> output = {0, 0};
    for(int i = l;i<=r;i++)
    {
        output.first = ( output.first*key1 + (s[i] - 'a' + 1) )%mod1;
        output.second = ( output.second*key2 + (s[i] - 'a' + 1) )%mod2;
    }

    return output;
}

string makeString(string &s, int l, int r)
{
    string output = "";
    for(int i = l;i<=r;i++)
    {
        output = output + s[i];
    }

    return output;
}

pair <long long, long long> getHash(pair <long long, long long> h[MAXN][MAXN], int i, int l, int r)
{
    if(i==0) return h[i][r];
    return {(h[i][r].first - h[i][l-1].first*p1[r-l+1] + mod1)%mod1, (h[i][r].second - h[i][l-1].second*p2[r-l+1] + mod2)%mod2};
}

bool checkLeft()
{
    char c = '#';
    for(int i = 0;i<n;i++)
    {
        if(segment[i].first==-1) continue;
        if(segment[i].first==0)
        {
            return false;
        }

        if(c=='#')
        {
            c = a[i][ segment[i].first - 1 ];
        }
        else
        {
            if(c!=a[i][ segment[i].first - 1 ]) return false;
        }
    }

    return true;
}

bool checkRight()
{
    char c = '#';
    for(int i = 0;i<n;i++)
    {
        if(segment[i].second==-1) continue;
        if(segment[i].second==a[i].size()-1) return false;

        if(c=='#')
        {
            c = a[i][ segment[i].first + 1 ];
        }
        else
        {
            if(c!=a[i][ segment[i].first + 1 ]) return false;
        }
    }

    return true;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    bool flag = false;
    pair <long long, long long> current;

    cin >> n;
    for(int i = 0;i<n;i++) cin >> a[i];
    for(int i = 0;i<n;i++) cin >> b[i];

    p1[0] = 1;
    p2[0] = 1;
    for(int i = 1;i<MAXN;i++)
    {
        p1[i] = (p1[i-1]*key1)%mod1;
        p2[i] = (p2[i-1]*key2)%mod2;
    }

    hashStart = {-1, -1};
    for(int i = 0;i<n;i++)
    {
        if(a[i]==b[i])
        {
            segment[i] = {-1, -1};
            continue;
        }
        if(a[i].size()<answer1.size())
        {
            cout << "NO" << '\n';
            return 0;
        }

        for(int j = 0;j<a[i].size();j++)
        {
            if(a[i][j]!=b[i][j])
            {
                l = j;
                break;
            }
        }
        for(int j = a[i].size()-1;j>=0;j--)
        {
            if(a[i][j]!=b[i][j])
            {
                r = j;
                break;
            }
        }

        segment[i] = {l, r};
        if(hashStart==make_pair(-1LL, -1LL))
        {
            hashStart = makeHash(a[i], l, r);
            hashEnd = makeHash(b[i], l, r);

            answer1 = makeString(a[i], l, r);
            answer2 = makeString(b[i], l, r);
        }
        else
        {
            if( (r-l+1!=answer1.size() || hashStart!=makeHash(a[i], l, r) || hashEnd!=makeHash(b[i], l, r)) )
            {
                cout << "NO" << '\n';
                return 0;
            }
        }
    }

    while(checkLeft()==true)
    {
        for(int i = 0;i<n;i++)
        {
            if(segment[i].first!=-1) segment[i].first--;
        }
    }
    while(checkRight()==true)
    {
        for(int i = 0;i<n;i++)
        {
            if(segment[i].second!=-1) segment[i].second++;
        }
    }

    hashStart = {-1LL, -1LL};
    for(int i = 0;i<n;i++)
    {
        if(a[i]==b[i]) continue;

        if(hashStart==make_pair(-1LL, -1LL))
        {
            hashStart = makeHash(a[i], segment[i].first, segment[i].second);
            hashEnd = makeHash(b[i], segment[i].first, segment[i].second);

            answer1 = makeString(a[i], segment[i].first, segment[i].second);
            answer2 = makeString(b[i], segment[i].first, segment[i].second);
        }

        current = {0, 0};
        for(int j = 0;j<answer1.size();j++)
        {
            current.first = ( current.first*key1 + (a[i][j] - 'a' + 1) )%mod1;
            current.second = ( current.second*key2 + (a[i][j]- 'a' + 1) )%mod2;
        }

        bool ok = false;
        for(int j = answer1.size();j<a[i].size();j++)
        {
            if(current==hashStart)
            {
                if(j-1!=segment[i].second)
                {
                    cout << "NO" << '\n';
                    return 0;
                }
                else
                {
                    ok = true;
                    break;
                }
            }

            current.first = (current.first - (p1[ answer1.size() - 1 ]*(a[i][ j - answer1.size() ] - 'a' + 1))%mod1 + mod1)%mod1;
            current.second = (current.second - (p2[ answer1.size() - 1 ]*(a[i][ j - answer1.size() ] - 'a' + 1))%mod2 + mod2)%mod2;

            current.first = ( current.first*key1 + (a[i][j] - 'a' + 1) )%mod1;
            current.second = ( current.second*key2 + (a[i][j]- 'a' + 1) )%mod2;
        }

        if(current==hashStart && a[i].size()-1!=segment[i].second && ok==false)
        {
            cout << "NO" << '\n';
            return 0;
        }
    }

    cout << "YES" << '\n';

    cout << answer1 << '\n';
    cout << answer2 << '\n';
}
/*
2
pda
cda
pgb
cdb

2
aa
caaaa
bb
caabb

2
a
aa
b
ab
*/


#include<iostream>

using namespace std;

const int MAXN = 3005;
const long long key1 = 29, key2 = 31;
const long long mod1 = 1e9 + 7, mod2 = 1e9 + 9;

int n;
string a[MAXN], b[MAXN];
//pair <long long, long long> aHash[MAXN][MAXN], bHash[MAXN][MAXN];

int l, r;
long long p1[MAXN], p2[MAXN];
pair <int, int> segment[MAXN];
pair <long long, long long> hashStart, hashEnd;

string answer1 = "", answer2 = "";

pair <long long, long long> makeHash(string &s, int l, int r)
{
    pair <long long, long long> output = {0, 0};
    for(int i = l;i<=r;i++)
    {
        output.first = ( output.first*key1 + (s[i] - 'a' + 1) )%mod1;
        output.second = ( output.second*key2 + (s[i] - 'a' + 1) )%mod2;
    }

    return output;
}

string makeString(string &s, int l, int r)
{
    string output = "";
    for(int i = l;i<=r;i++)
    {
        output = output + s[i];
    }

    return output;
}

pair <long long, long long> getHash(pair <long long, long long> h[MAXN][MAXN], int i, int l, int r)
{
    if(i==0) return h[i][r];
    return {(h[i][r].first - h[i][l-1].first*p1[r-l+1] + mod1)%mod1, (h[i][r].second - h[i][l-1].second*p2[r-l+1] + mod2)%mod2};
}

bool checkLeft()
{
    char c = '#';
    for(int i = 0;i<n;i++)
    {
        if(segment[i].first==-1) continue;
        if(segment[i].first==0)
        {
            return false;
        }

        if(c=='#')
        {
            c = a[i][ segment[i].first - 1 ];
        }
        else
        {
            if(c!=a[i][ segment[i].first - 1 ]) return false;
        }
    }

    return true;
}

bool checkRight()
{
    char c = '#';
    for(int i = 0;i<n;i++)
    {
        if(segment[i].second==-1) continue;
        if(segment[i].second==a[i].size()-1) return false;

        if(c=='#')
        {
            c = a[i][ segment[i].first + 1 ];
        }
        else
        {
            if(c!=a[i][ segment[i].first + 1 ]) return false;
        }
    }

    return true;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    bool flag = false;
    pair <long long, long long> current;

    cin >> n;
    for(int i = 0;i<n;i++) cin >> a[i];
    for(int i = 0;i<n;i++) cin >> b[i];

    p1[0] = 1;
    p2[0] = 1;
    for(int i = 1;i<MAXN;i++)
    {
        p1[i] = (p1[i-1]*key1)%mod1;
        p2[i] = (p2[i-1]*key2)%mod2;
    }

    hashStart = {-1, -1};
    for(int i = 0;i<n;i++)
    {
        if(a[i]==b[i])
        {
            segment[i] = {-1, -1};
            continue;
        }
        if(a[i].size()<answer1.size())
        {
            cout << "NO" << '\n';
            return 0;
        }

        for(int j = 0;j<a[i].size();j++)
        {
            if(a[i][j]!=b[i][j])
            {
                l = j;
                break;
            }
        }
        for(int j = a[i].size()-1;j>=0;j--)
        {
            if(a[i][j]!=b[i][j])
            {
                r = j;
                break;
            }
        }

        segment[i] = {l, r};
        if(hashStart==make_pair(-1LL, -1LL))
        {
            hashStart = makeHash(a[i], l, r);
            hashEnd = makeHash(b[i], l, r);

            answer1 = makeString(a[i], l, r);
            answer2 = makeString(b[i], l, r);
        }
        else
        {
            if( (r-l+1!=answer1.size() || hashStart!=makeHash(a[i], l, r) || hashEnd!=makeHash(b[i], l, r)) )
            {
                cout << "NO" << '\n';
                return 0;
            }
        }
    }

    while(checkLeft()==true)
    {
        for(int i = 0;i<n;i++)
        {
            if(segment[i].first!=-1) segment[i].first--;
        }
    }
    while(checkRight()==true)
    {
        for(int i = 0;i<n;i++)
        {
            if(segment[i].second!=-1) segment[i].second++;
        }
    }

    hashStart = {-1LL, -1LL};
    for(int i = 0;i<n;i++)
    {
        if(hashStart==make_pair(-1LL, -1LL) && a[i]!=b[i])
        {
            hashStart = makeHash(a[i], segment[i].first, segment[i].second);
            hashEnd = makeHash(b[i], segment[i].first, segment[i].second);

            answer1 = makeString(a[i], segment[i].first, segment[i].second);
            answer2 = makeString(b[i], segment[i].first, segment[i].second);
        }

        current = {0, 0};
        for(int j = 0;j<answer1.size();j++)
        {
            current.first = ( current.first*key1 + (a[i][j] - 'a' + 1) )%mod1;
            current.second = ( current.second*key2 + (a[i][j]- 'a' + 1) )%mod2;
        }

        bool ok = false;
        for(int j = answer1.size();j<a[i].size();j++)
        {
            if(current==hashStart)
            {
                if(a[i]!=b[i] && j-1!=segment[i].second)
                {
                    cout << "NO" << '\n';
                    return 0;
                }
                else
                {
                    for(int k = j-answer1.size();k<j;k++)
                    {
                        if(answer2[ k - (j-answer1.size()) ]!=b[i][k])
                        {
                            cout << "NO" << '\n';
                            return 0;
                        }
                    }

                    ok = true;
                    break;
                }
            }

            current.first = (current.first - (p1[ answer1.size() - 1 ]*(a[i][ j - answer1.size() ] - 'a' + 1))%mod1 + mod1)%mod1;
            current.second = (current.second - (p2[ answer1.size() - 1 ]*(a[i][ j - answer1.size() ] - 'a' + 1))%mod2 + mod2)%mod2;

            current.first = ( current.first*key1 + (a[i][j] - 'a' + 1) )%mod1;
            current.second = ( current.second*key2 + (a[i][j]- 'a' + 1) )%mod2;
        }

        if(current==hashStart && a[i].size()-1!=segment[i].second && ok==false)
        {
            cout << "NO" << '\n';
            return 0;
        }
    }

    cout << "YES" << '\n';

    cout << answer1 << '\n';
    cout << answer2 << '\n';
}
/*
2
pda
cda
pgb
cdb

2
aa
caaaa
bb
caabb

2
a
aa
b
ab
*/