#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!=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;
        }
    }

    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;
            }

            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
*/


#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] - '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;
}

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].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);
        }

        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;
        }
    }

    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;
                current.second = (current.second - p2[ answer1.size() - 1 ]*(a[i][ j - answer1.size() ] - 'a' + 1) + 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(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
aaaa
bb
aabb
*/


#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(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
aaaa
bb
aabb
*/


#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))
        {
            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];
//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!=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;
        }
    }

    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(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==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==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];
//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 && 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;
        }
    }

    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()) && (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<bits/stdc++.h>
#define rep(i,x,y) for(int i=(x);i<=(y);i++)
#define dep(i,x,y) for(int i=(x);i>=(y);i--)
#define add(x,y) x=(x+(y))%mo
#define pb push_back
#define ll long long
#define N 4000
#define inf 1000000000
#define Inf 1000000000000000000ll
using namespace std;
int n,x,len,l[N],f[N];
string s1[N],s2[N],p,p1;
int main(){
	scanf("%d",&n);
	rep(i,1,n){
		cin>>s1[i];l[i]=s1[i].length()-1;
	}
	rep(i,1,n)cin>>s2[i];len=-1;
	rep(i,1,n)if(s1[i]!=s2[i]){int L,R;
		rep(j,0,l[i])if(s1[i][j]!=s2[i][j]){L=j;break;}
		dep(j,l[i],0)if(s1[i][j]!=s2[i][j]){R=j;break;}
		len=R-L;rep(j,L,R)p=p+s1[i][j],p1=p1+s2[i][j];break;
	}
	if(len==-1){
		printf("YES\na\na\n");return 0;
	}f[0]=-1;
	rep(i,1,len){
		for(x=f[i-1];~x;x=f[x])
			if(p[i]==p[x+1])break;
		if(p[i]==p[x+1])f[i]=x+1;else f[i]=-1;
	}
	rep(i,1,n){x=0;
		rep(j,0,l[i]){
			while(~x&&p[x]!=s1[i][j])x=f[x];x++;
			if(x>len){
				string ss=s1[i];
				rep(k,0,len)ss[j-len+k]=p1[k];
				if(ss!=s2[i]){
					printf("NO\n");return 0;
				}break;
			}
		}
		if(x<=len&&s1[i]!=s2[i]){
			printf("NO\n");return 0;
		}
	}
	cout<<"YES\n"<<p<<'\n'<<p1<<'\n';
}


#include<bits/stdc++.h>
#define rep(i,x,y) for(int i=(x);i<=(y);i++)
#define dep(i,x,y) for(int i=(x);i>=(y);i--)
#define add(x,y) x=(x+(y))%mo
#define pb push_back
#define ll long long
#define N 4000
#define inf 1000000000
#define Inf 1000000000000000000ll
using namespace std;
int n,x,fr,x0,L,R,len,l[N],f[N];
string s1[N],s2[N],ss,p,p1;
int main(){
	ios::sync_with_stdio(false);
	scanf("%d",&n);
	rep(i,1,n){
		cin>>s1[i];l[i]=s1[i].length()-1;
	}
	rep(i,1,n)cin>>s2[i];
	rep(i,1,n)if(s1[i]!=s2[i]){
		if(fr){
			rep(j,0,l[i])if(s1[i][j]!=s2[i][j]){x=j;break;}
			rep(j,0,L)if(x-j<0||s1[i][x-j]!=s1[fr][x0-j]||s2[i][x-j]!=s2[fr][x0-j]){
				L=j-1;break;
			}
			rep(j,0,R)if(x+j>l[i]||s1[i][x+j]!=s1[fr][x0+j]||s2[i][x+j]!=s2[fr][x0+j]){
				R=j-1;break;
			}
		}else{fr=i;
			rep(j,0,l[i])if(s1[i][j]!=s2[i][j]){x0=j;break;}
			L=x0;R=l[i]-x0;
		}
	}
	if(L==-1){printf("NO\n");return 0;}
	rep(i,x0-L,x0+R)p=p+s1[fr][i],p1=p1+s2[fr][i];
	len=p.length()-1;f[0]=-1;
	rep(i,1,len){
		for(x=f[i-1];~x;x=f[x])
			if(p[i-1]==p[x])break;
		f[i]=x+1;
	}
	rep(i,1,n){x=0;
		rep(j,0,l[i]){
			while(~x&&p[x]!=s1[i][j])x=f[x];x++;
			if(x>len){ss=s1[i];
				rep(k,0,len)ss[j-len+k]=p1[k];
				if(ss!=s2[i]){
					printf("NO\n");return 0;
				}break;
			}
		}
		if(x<=len&&s1[i]!=s2[i]){
			printf("NO\n");return 0;
		}
	}
	cout<<"YES\n"<<p<<'\n'<<p1<<'\n';
}


#include<bits/stdc++.h>
#define rep(i,x,y) for(int i=(x);i<=(y);i++)
#define dep(i,x,y) for(int i=(x);i>=(y);i--)
#define add(x,y) x=(x+(y))%mo
#define pb push_back
#define ll long long
#define N 4000
#define inf 1000000000
#define Inf 1000000000000000000ll
using namespace std;
int n,x,len,l[N],f[N];
string s1[N],s2[N],p,p1;
int main(){
	scanf("%d",&n);
	rep(i,1,n){
		cin>>s1[i];l[i]=s1[i].length()-1;
	}
	rep(i,1,n)cin>>s2[i];len=-1;
	rep(i,1,n)if(s1[i]!=s2[i]){int L,R;
		rep(j,0,l[i])if(s1[i][j]!=s2[i][j]){L=j;break;}
		dep(j,l[i],0)if(s1[i][j]!=s2[i][j]){R=j;break;}
		len=R-L;rep(j,L,R)p=p+s1[i][j],p1=p1+s2[i][j];break;
	}
	if(len==-1){
		printf("YES\na\na\n");return 0;
	}f[0]=-1;
	rep(i,1,len){
		for(x=f[i-1];~x;x=f[x])
			if(p[i-1]==p[x])break;
		if(p[i-1]==p[x])f[i]=x+1;else f[i]=-1;
	}
	rep(i,1,n){x=0;
		rep(j,0,l[i]){
			while(~x&&p[x]!=s1[i][j])x=f[x];x++;
			if(x>len){
				string ss=s1[i];
				rep(k,0,len)ss[j-len+k]=p1[k];
				if(ss!=s2[i]){
					printf("NO\n");return 0;
				}break;
			}
		}
		if(x<=len&&s1[i]!=s2[i]){
			printf("NO\n");return 0;
		}
	}
	cout<<"YES\n"<<p<<'\n'<<p1<<'\n';
}


#include<bits/stdc++.h>
#define rep(i,x,y) for(int i=(x);i<=(y);i++)
#define dep(i,x,y) for(int i=(x);i>=(y);i--)
#define add(x,y) x=(x+(y))%mo
#define pb push_back
#define ll long long
#define N 4000
#define inf 1000000000
#define Inf 1000000000000000000ll
using namespace std;
int n,x,len,l[N],f[N];
string s1[N],s2[N],p,p1;
int main(){
	scanf("%d",&n);
	rep(i,1,n){
		cin>>s1[i];l[i]=s1[i].length()-1;
	}
	rep(i,1,n)cin>>s2[i];len=-1;
	rep(i,1,n)if(s1[i]!=s2[i]){int L,R;
		rep(j,0,l[i])if(s1[i][j]!=s2[i][j]){L=j;break;}
		dep(j,l[i],0)if(s1[i][j]!=s2[i][j]){R=j;break;}
		len=R-L;rep(j,L,R)p=p+s1[i][j],p1=p1+s2[i][j];break;
	}
	if(len==-1){
		printf("YES\na\na\n");return 0;
	}f[0]=-1;
	rep(i,1,len){
		for(x=f[i-1];~x;x=f[x])
			if(p[i-1]==p[x])break;
		f[i]=x+1;
	}
	rep(i,1,n){x=0;
		rep(j,0,l[i]){
			while(~x&&p[x]!=s1[i][j])x=f[x];x++;
			if(x>len){
				string ss=s1[i];
				rep(k,0,len)ss[j-len+k]=p1[k];
				if(ss!=s2[i]){
					printf("NO\n");return 0;
				}break;
			}
		}
		if(x<=len&&s1[i]!=s2[i]){
			printf("NO\n");return 0;
		}
	}
	cout<<"YES\n"<<p<<'\n'<<p1<<'\n';
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Azat Ismagilov
 */

/*-.``                                          ``                                                   .
 .``                               ```````..-:oss+/-``                                              .
 .`                        `-.-://::::/+/+osyyhhyyysss+/:-.`                                        .
 `                      .::++:/+++syyyyyyyyyyyyydmmddhdmhhho-.`                                     -
                    ``./o+/++oooooooyhmmNddmmmdddhhmmdmmNmmmhhs:-..`                                -
                   `.-/++/oshddmmmmhhdmmNmmmNMNNmmmhyddmNNNNNNmmdhhso+/-.`                          :
                  `./+soooshNNMMNMNNNNNNmMMNNNMMNNmmdhddmmNNNNmNNddmmmmdhs+-`                       :
                `.:/+osyddhhdmNMMMMNMNNMNMMMMMMMMMMNmdmmmmmNMNNNNdddNNmNNNmdy/`                     -
 ``           `-osssydmNNNNNNNNmNMMMMMNMMMMMMMMMMMMMNmmNNNmmNNMNmmydNNNNNNmNNNy:`                   `
            `-+syoyhmNNNMMMMMMMMMMMMMNNNNNNNMMMMMMMMMMNNmmmmmmmNdmhsyNNmMNmmmNdho-`                 `
 `         -oddyoohyyyhdmNMMMMMMMMNmmdmmmmmddmmmmmmNNmmmdddddmmmmNdshdmhMNNdhdmmmho-`
 `        :hmmysosoooooshdmmNMMMNmdysshhddddhysysyshyyhhyyyyhhhdmmyhmym+hmhyyydhmNmh+.
 `       .ohmyyhhhhyysssssyhdmmmhyo+++osydhssoooo++oo+/+++/++++ososhmhss+hy++sshydmmds-
 `       :shhdddddddmmddddddhhyso/--::/+oyyso+o++//::-----:---:://oyhhsoosos+osydhdddh+.
 `      `/yddmdmmmmNNmNNNNdyo+/:-.````...-:///+/+/:--............--:+syhhdshshhdddhddhy/`
 `       :ydmdmNNNNNNMNNdyo/--..````````````..---:-......````````...-:+yhmmddhmmmmddmddy-
 `      `/ydhmNNNNNMMNmy+:...`````````````````....-....``.`````````...-/ohmmmmmNNmmmmmmd+`
        `:oydNNMNNNNmho:-..`````````````````````.....`......```````....-/oyhmmmNNNNdddddy.
        `:oddNNNNNNds/-..`````````````````````````````..........```.....:/syhmmmNNNNmmhhy:
        `-ymmNNNNdho:...``````````````````````````````````..............-:+yhmmmmNmNNmmmh+`
        `:dmNNMNdhs:-...`````````````````````````````````````...........-:+shdmmmNNmmmmmmo`
        `/dNNMMNdh+-.....``````````````````````````````````````````.....--/oyhmNmmNNNNNNNh-
        .omNMNNNdy/-......```````````````````````````````````````````....--:+sdmmNNNNMNNNm+`
        .sNNNNmdds/-......`````````````````````````````````````````````...---:+hmmNNNMNMMNh:`
        `oNMMNNNdy/:-.....````````````````````````````````....--:::----.....---/ymNNNNMMMNho/.
         .dNMMMNmy+:-.....````````````````````````....--:/+osyhhhyyyssoo+:------/hNNNNNNNdso+/-`
         .oNMMMNmds/--...`````````````............-:/oyddmmmmmddhhysoooooo+/:-:/+ymmmmNNdo/++/:-`
 `        -yNMMNNdy/--..``````....--:://::---....-:oyhdmddhyyssssssssoooo+++shoddhhmmNNmy+shhyo:`
 `        `+mNNNNms/--..`..-:/osyyhhdddhyso/-....-:ohhyssyyyyysssssyyhhyssoosdo+/:/ymmNdss+ohhy/.
           -dNNNNNs:--..:/+syyhddmmmdddddhyo:--://sssyyyhhhyhddmmmhhhhhhyso+/o-..-:+hmdy++//+dh+.
           `sNNNNNo---:+syyyyssooosyyhdddhhhyo/::::sosyhhhso+sssyssssso++/:--/...--:odhoso++:yho:.
            :dNNNN+--:+oso++osssyyhdmmhddhyys:`````:sssso+++++++++++++/:--...:`...--/yyohhys++yoo+`
 ``         `:hmNNo/:///++osyhhhdmdmddssso+so:`````./ys+::::://////::--...``..`...--:oy/yhhs++ooo:`
 ``         ./syhdhs-::/+oshhhdhssso+++++/+yo-.````..:o:--............`````````...--:/s:oyys+++/.
            `.-:odNd:-::/+ooooo++//++++/-.-+:..`````...//:-.........```````````...--:/+/sss+//-`
            `:+//dmo+:-------:://///:-..``./-..`````````.://:--....```````````....--::+++///:.
            .oysoyd++/--............````..-:..``````````.:/o+:-....`````````......--::/+//:-`
            .sy+:/y+:/:..................-::-.```` ``````../o/:--...............---::://::-`
            .:s/:/oo::--........``````..-:/+-..```````.-----o/::::----------------:::::/+:.
            `://-:/o/--...`.```````....--://.--:----::/+osooo/--::///::::::::::::::::::/o:`
             -//---//:-.....````.......-:::--:oyysoosssyhhyyo/-..--://///:::::::::::::://.
              `-...-::--.............--::-...-oyhhyyhhhssooo+/-..---::///::::::::::::::-.
                  ``.-:--...........-:::-..``.-/////osso++//:---..-:::::::-::::/::::::-``
 `                  ``.----........--::-..`.``...---::::////:-----:/++/::----:::::::::.`
 `                     `..------..--::-.....``..-::////oososssssyyyyyo+/:.--::::::::::.`
 .                       `.-----------.----..-://+++++ossyyyysssso+//:::---://////::::.`
 -                        `-:::---------/+/+ssssssssssyss+/////:--....---::/++///////:.`
 .                        `-::::--...--/ossssoo+//:---::::/++/:::--------:/++++//////:-`
 .`                        .-:::------:/+/--..-::/+/////+++oo++////::::::://++++//////:.
 -`                         .-::::::--:::-.....-://+ooosssyssoooo++//::::://+++///////:`
 .`                         `.:////////::-..--:::/+oosyyyyyyssoo+/::----://+++///////:-`
 ``                          `:++++/++//:----:://++oossssoo++//::--.---:///+++///+//::-`
 -`          ````             .:+ooo+++/::-------::::::-----.--....--::////+///+++//::--
 `.`    ``    ````````        `./++oooo++/:--.........`........---::://////++++++///::::-
 :-.`   ``    ``` `            `-:/oooooo++/:--.........-----::////++++++++++++++///::::o.
 ++-``   `     ``               .:/o+osoooo++//:------::////++ooooooo+++++ooo+++////::::/+       `  `
 `/:```         `   ```         `:os/+ossoooo++++///+++oosoosssssooooo+ooooooo++////:::::+-``` `
 `...               .`.          -sh+//++osssoooooooooosssssssssooooooooooooo+++/////:::::/s--:-   `
                   `:`           `:oo/:://+osssssoosooooossssssssssooooooooooo++/////::::-::::o.    .
                   ``              `::::::://+ossssssyssyyyyyyyyyssooooooooooo++/////::::----:o/.`..+
                                    .-:::::::://++osssyyyyyyyyyyyssooooooooooo++/////::::--------+ydy
                                    .---------::://++oossssyyysssssoooooossooo+++///::::------.....:+
                                    `----------:::::://++oooossssoooooooooooo+++///::::-----.......``
                                    .--------------::::///++oooooooooooooo++++/////:::----.......````
                        ```         `-----------------::::////++++++++++++++/////::::----......``````
                     ```.-:::--`   `.----.-.....-------::::://////////////////:::::----.......```````
                  `.-:+osyyyys: ````...............------::::::::::::::::::::::::----.......`````````
    `...`````.--:/osysyyhyyyyo```````..................-------::::--::--::::------......`````````````
  ``.-:://+osssyhhyyyyyhsyyyy/` ```````.................----------------------........```````````````
 `.:+ossssssyyhhhyhhhhhhhhyyy-` ```````````.................--------...............````````````````
 osssssyyyyyhhhhhhhhhhhhhhyhy-`  ```````````````````````....................``````````````````````
 syyyyyhhhhhhhhhhhhhhdhhhhhhy.    ``````````````````````````````..``..````````````````````````     */

#include <bits/stdc++.h>

#define int long long
#define fs first
#define sc second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define len(v) ((int)v.size())
#define vc vector
#define pr pair
#define all(v) v.begin(), v.end()
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize("unroll-loops")

using namespace std;

template<typename T, typename U>
inline ostream &operator<<(ostream &_out, const pair<T, U> &_p) {
    _out << _p.first << ' ' << _p.second;
    return _out;
}

template<typename T, typename U>
inline istream &operator>>(istream &_in, pair<T, U> &_p) {
    _in >> _p.first >> _p.second;
    return _in;
}

template<typename T>
inline ostream &operator<<(ostream &_out, const vector<T> &_v) {
    if (_v.empty()) { return _out; }
    _out << _v.front();
    for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) { _out << ' ' << *_it; }
    return _out;
}

template<typename T>
inline istream &operator>>(istream &_in, vector<T> &_v) {
    for (auto &_i : _v) { _in >> _i; }
    return _in;
}

const int MAXN = 1e5;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int P = 101;

class TaskD {
public:
    void solve(std::istream &in, std::ostream &out) {
        int n;
        in >> n;
        vc<string> a(n), b(n);
        in >> a >> b;
        int x = 0;
        vc<pr<int, int>> pos(n, {INF, -INF});
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < len(a[i]); j++) {
                if (a[i][j] != b[i][j]) {
                    pos[i].fs = min(pos[i].fs, j);
                    pos[i].sc = max(pos[i].sc, j);
                    x = i;
                }
            }
        }
        for (int i = 0; i < n; i++) {
            if (pos[i] != mp(INF, -INF)) {
                if (pos[i].sc - pos[i].fs != pos[x].sc - pos[x].fs) {
                    out << "NO";
                    return;
                }
                for (int j = 0; j <= pos[i].sc - pos[i].fs; j++) {
                    if (a[i][pos[i].fs + j] != a[x][pos[x].fs + j] || b[i][pos[i].fs + j] != b[x][pos[x].fs + j]) {
                        out << "NO";
                        return;
                    }
                }
            }
        }

        pr<int, int> keks = mp(0, len(a[x]) - 1);
        for (int i = 0; i < n; i++) {
            if (pos[i] != mp(INF, -INF)) {
                pr<int, int> mems = pos[x];
                pr<int, int> lels = pos[i];
                while (mems.fs > 1 && lels.fs > 1) {
                    if (a[x][mems.fs - 1] != a[i][lels.fs - 1] || b[x][mems.fs - 1] != b[i][lels.fs - 1]) {
                        mems.fs--;
                        lels.fs--;
                    }
                    else{
                        break;
                    }
                }
                while (mems.sc < len(a[x]) - 1 && lels.sc < len(a[i]) - 1) {
                    if (a[x][mems.sc + 1] != a[i][lels.sc + 1] || b[x][mems.sc + 1] != b[i][lels.sc + 1]) {
                        mems.sc++;
                        lels.sc++;
                    }
                    else{
                        break;
                    }
                }
                keks.fs = max(keks.fs, mems.fs);
                keks.sc = min(keks.sc, mems.sc);
            }
        }

        int anss = 0;
        int kl = 1;
        for (int i = keks.fs; i <= keks.sc; i++){
            anss += kl * a[x][i];
            kl *= P;
            kl %= MOD;
            anss %= MOD;
        }
        for (int i = 0; i < n; i++){
            vc<int> ans(len(a[i]) + 1);
            int kl = 1;
            for (int j = 0; j < len(a[i]); j++){
                ans[j + 1] = (ans[j] + kl * a[i][j]) % MOD;
                kl *= P;
                kl %= MOD;
            }
            kl = 1;
            for (int j = 0; j + (keks.sc - keks.fs + 1) < min(pos[i].fs, len(a[i]) + 1); j++){
                if ((anss * kl - (ans[j + (keks.sc - keks.fs + 1)] - ans[j])) % MOD == 0){
                    out << "NO";
                    return;
                }
                kl *= P;
                kl %= MOD;
            }
        }
        out << "YES" << endl;
        for (int i = keks.fs; i <= keks.sc; i++){
            out << a[x][i];
        }
        out << endl;
        for (int i = keks.fs; i <= keks.sc; i++){
            out << b[x][i];
        }
    }
};

main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	TaskD solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Azat Ismagilov
 */

/*-.``                                          ``                                                   .
 .``                               ```````..-:oss+/-``                                              .
 .`                        `-.-://::::/+/+osyyhhyyysss+/:-.`                                        .
 `                      .::++:/+++syyyyyyyyyyyyydmmddhdmhhho-.`                                     -
                    ``./o+/++oooooooyhmmNddmmmdddhhmmdmmNmmmhhs:-..`                                -
                   `.-/++/oshddmmmmhhdmmNmmmNMNNmmmhyddmNNNNNNmmdhhso+/-.`                          :
                  `./+soooshNNMMNMNNNNNNmMMNNNMMNNmmdhddmmNNNNmNNddmmmmdhs+-`                       :
                `.:/+osyddhhdmNMMMMNMNNMNMMMMMMMMMMNmdmmmmmNMNNNNdddNNmNNNmdy/`                     -
 ``           `-osssydmNNNNNNNNmNMMMMMNMMMMMMMMMMMMMNmmNNNmmNNMNmmydNNNNNNmNNNy:`                   `
            `-+syoyhmNNNMMMMMMMMMMMMMNNNNNNNMMMMMMMMMMNNmmmmmmmNdmhsyNNmMNmmmNdho-`                 `
 `         -oddyoohyyyhdmNMMMMMMMMNmmdmmmmmddmmmmmmNNmmmdddddmmmmNdshdmhMNNdhdmmmho-`
 `        :hmmysosoooooshdmmNMMMNmdysshhddddhysysyshyyhhyyyyhhhdmmyhmym+hmhyyydhmNmh+.
 `       .ohmyyhhhhyysssssyhdmmmhyo+++osydhssoooo++oo+/+++/++++ososhmhss+hy++sshydmmds-
 `       :shhdddddddmmddddddhhyso/--::/+oyyso+o++//::-----:---:://oyhhsoosos+osydhdddh+.
 `      `/yddmdmmmmNNmNNNNdyo+/:-.````...-:///+/+/:--............--:+syhhdshshhdddhddhy/`
 `       :ydmdmNNNNNNMNNdyo/--..````````````..---:-......````````...-:+yhmmddhmmmmddmddy-
 `      `/ydhmNNNNNMMNmy+:...`````````````````....-....``.`````````...-/ohmmmmmNNmmmmmmd+`
        `:oydNNMNNNNmho:-..`````````````````````.....`......```````....-/oyhmmmNNNNdddddy.
        `:oddNNNNNNds/-..`````````````````````````````..........```.....:/syhmmmNNNNmmhhy:
        `-ymmNNNNdho:...``````````````````````````````````..............-:+yhmmmmNmNNmmmh+`
        `:dmNNMNdhs:-...`````````````````````````````````````...........-:+shdmmmNNmmmmmmo`
        `/dNNMMNdh+-.....``````````````````````````````````````````.....--/oyhmNmmNNNNNNNh-
        .omNMNNNdy/-......```````````````````````````````````````````....--:+sdmmNNNNMNNNm+`
        .sNNNNmdds/-......`````````````````````````````````````````````...---:+hmmNNNMNMMNh:`
        `oNMMNNNdy/:-.....````````````````````````````````....--:::----.....---/ymNNNNMMMNho/.
         .dNMMMNmy+:-.....````````````````````````....--:/+osyhhhyyyssoo+:------/hNNNNNNNdso+/-`
         .oNMMMNmds/--...`````````````............-:/oyddmmmmmddhhysoooooo+/:-:/+ymmmmNNdo/++/:-`
 `        -yNMMNNdy/--..``````....--:://::---....-:oyhdmddhyyssssssssoooo+++shoddhhmmNNmy+shhyo:`
 `        `+mNNNNms/--..`..-:/osyyhhdddhyso/-....-:ohhyssyyyyysssssyyhhyssoosdo+/:/ymmNdss+ohhy/.
           -dNNNNNs:--..:/+syyhddmmmdddddhyo:--://sssyyyhhhyhddmmmhhhhhhyso+/o-..-:+hmdy++//+dh+.
           `sNNNNNo---:+syyyyssooosyyhdddhhhyo/::::sosyhhhso+sssyssssso++/:--/...--:odhoso++:yho:.
            :dNNNN+--:+oso++osssyyhdmmhddhyys:`````:sssso+++++++++++++/:--...:`...--/yyohhys++yoo+`
 ``         `:hmNNo/:///++osyhhhdmdmddssso+so:`````./ys+::::://////::--...``..`...--:oy/yhhs++ooo:`
 ``         ./syhdhs-::/+oshhhdhssso+++++/+yo-.````..:o:--............`````````...--:/s:oyys+++/.
            `.-:odNd:-::/+ooooo++//++++/-.-+:..`````...//:-.........```````````...--:/+/sss+//-`
            `:+//dmo+:-------:://///:-..``./-..`````````.://:--....```````````....--::+++///:.
            .oysoyd++/--............````..-:..``````````.:/o+:-....`````````......--::/+//:-`
            .sy+:/y+:/:..................-::-.```` ``````../o/:--...............---::://::-`
            .:s/:/oo::--........``````..-:/+-..```````.-----o/::::----------------:::::/+:.
            `://-:/o/--...`.```````....--://.--:----::/+osooo/--::///::::::::::::::::::/o:`
             -//---//:-.....````.......-:::--:oyysoosssyhhyyo/-..--://///:::::::::::::://.
              `-...-::--.............--::-...-oyhhyyhhhssooo+/-..---::///::::::::::::::-.
                  ``.-:--...........-:::-..``.-/////osso++//:---..-:::::::-::::/::::::-``
 `                  ``.----........--::-..`.``...---::::////:-----:/++/::----:::::::::.`
 `                     `..------..--::-.....``..-::////oososssssyyyyyo+/:.--::::::::::.`
 .                       `.-----------.----..-://+++++ossyyyysssso+//:::---://////::::.`
 -                        `-:::---------/+/+ssssssssssyss+/////:--....---::/++///////:.`
 .                        `-::::--...--/ossssoo+//:---::::/++/:::--------:/++++//////:-`
 .`                        .-:::------:/+/--..-::/+/////+++oo++////::::::://++++//////:.
 -`                         .-::::::--:::-.....-://+ooosssyssoooo++//::::://+++///////:`
 .`                         `.:////////::-..--:::/+oosyyyyyyssoo+/::----://+++///////:-`
 ``                          `:++++/++//:----:://++oossssoo++//::--.---:///+++///+//::-`
 -`          ````             .:+ooo+++/::-------::::::-----.--....--::////+///+++//::--
 `.`    ``    ````````        `./++oooo++/:--.........`........---::://////++++++///::::-
 :-.`   ``    ``` `            `-:/oooooo++/:--.........-----::////++++++++++++++///::::o.
 ++-``   `     ``               .:/o+osoooo++//:------::////++ooooooo+++++ooo+++////::::/+       `  `
 `/:```         `   ```         `:os/+ossoooo++++///+++oosoosssssooooo+ooooooo++////:::::+-``` `
 `...               .`.          -sh+//++osssoooooooooosssssssssooooooooooooo+++/////:::::/s--:-   `
                   `:`           `:oo/:://+osssssoosooooossssssssssooooooooooo++/////::::-::::o.    .
                   ``              `::::::://+ossssssyssyyyyyyyyyssooooooooooo++/////::::----:o/.`..+
                                    .-:::::::://++osssyyyyyyyyyyyssooooooooooo++/////::::--------+ydy
                                    .---------::://++oossssyyysssssoooooossooo+++///::::------.....:+
                                    `----------:::::://++oooossssoooooooooooo+++///::::-----.......``
                                    .--------------::::///++oooooooooooooo++++/////:::----.......````
                        ```         `-----------------::::////++++++++++++++/////::::----......``````
                     ```.-:::--`   `.----.-.....-------::::://////////////////:::::----.......```````
                  `.-:+osyyyys: ````...............------::::::::::::::::::::::::----.......`````````
    `...`````.--:/osysyyhyyyyo```````..................-------::::--::--::::------......`````````````
  ``.-:://+osssyhhyyyyyhsyyyy/` ```````.................----------------------........```````````````
 `.:+ossssssyyhhhyhhhhhhhhyyy-` ```````````.................--------...............````````````````
 osssssyyyyyhhhhhhhhhhhhhhyhy-`  ```````````````````````....................``````````````````````
 syyyyyhhhhhhhhhhhhhhdhhhhhhy.    ``````````````````````````````..``..````````````````````````     */

#include <bits/stdc++.h>

#define int long long
#define fs first
#define sc second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define len(v) ((int)v.size())
#define vc vector
#define pr pair
#define all(v) v.begin(), v.end()
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize("unroll-loops")

using namespace std;

template<typename T, typename U>
inline ostream &operator<<(ostream &_out, const pair<T, U> &_p) {
    _out << _p.first << ' ' << _p.second;
    return _out;
}

template<typename T, typename U>
inline istream &operator>>(istream &_in, pair<T, U> &_p) {
    _in >> _p.first >> _p.second;
    return _in;
}

template<typename T>
inline ostream &operator<<(ostream &_out, const vector<T> &_v) {
    if (_v.empty()) { return _out; }
    _out << _v.front();
    for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) { _out << ' ' << *_it; }
    return _out;
}

template<typename T>
inline istream &operator>>(istream &_in, vector<T> &_v) {
    for (auto &_i : _v) { _in >> _i; }
    return _in;
}

const int MAXN = 1e5;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int P = 101;

class TaskD {
public:
    void solve(std::istream &in, std::ostream &out) {
        int n;
        in >> n;
        vc<string> a(n), b(n);
        in >> a >> b;
        int x = 0;
        vc<pr<int, int>> pos(n, {INF, -INF});
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < len(a[i]); j++) {
                if (a[i][j] != b[i][j]) {
                    pos[i].fs = min(pos[i].fs, j);
                    pos[i].sc = max(pos[i].sc, j);
                    x = i;
                }
            }
        }
        for (int i = 0; i < n; i++) {
            if (pos[i] != mp(INF, -INF)) {
                if (pos[i].sc - pos[i].fs != pos[x].sc - pos[x].fs) {
                    out << "NO";
                    return;
                }
                for (int j = 0; j <= pos[i].sc - pos[i].fs; j++) {
                    if (a[i][pos[i].fs + j] != a[x][pos[x].fs + j] || b[i][pos[i].fs + j] != b[x][pos[x].fs + j]) {
                        out << "NO";
                        return;
                    }
                }
            }
        }

        pr<int, int> keks = mp(0, len(a[x]) - 1);
        for (int i = 0; i < n; i++) {
            if (pos[i] != mp(INF, -INF)) {
                pr<int, int> mems = pos[x];
                pr<int, int> lels = pos[i];
                while (mems.fs > 1 && lels.fs > 1) {
                    if (a[x][mems.fs - 1] != a[i][lels.fs - 1] || b[x][mems.fs - 1] != b[i][lels.fs - 1]) {
                        break;
                    } else {
                        lels.fs--;
                        mems.fs--;
                    }
                }
                while (mems.sc < len(a[x]) - 1 && lels.sc < len(a[i]) - 1) {
                    if (a[x][mems.sc + 1] != a[i][lels.sc + 1] || b[x][mems.sc + 1] != b[i][lels.sc + 1]) {
                        break;
                    } else {
                        mems.sc++;
                        lels.sc++;
                    }
                }
                keks.fs = max(keks.fs, mems.fs);
                keks.sc = min(keks.sc, mems.sc);
            }
        }
        int anss = 0;
        int kl = 1;
        for (int i = keks.fs; i <= keks.sc; i++) {
            anss += kl * a[x][i];
            kl *= P;
            kl %= MOD;
            anss %= MOD;
        }
        for (int i = 0; i < n; i++) {
            vc<int> ans(len(a[i]) + 1);
            int kl = 1;
            for (int j = 0; j < len(a[i]); j++) {
                ans[j + 1] = (ans[j] + kl * a[i][j]) % MOD;
                kl *= P;
                kl %= MOD;
            }
            kl = 1;
            for (int j = 0; j + (keks.sc - keks.fs + 1) <= len(a[i]) && j < pos[i].fs; j++) {
                if ((anss * kl - (ans[j + (keks.sc - keks.fs + 1)] - ans[j])) % MOD == 0) {
                    out << "NO";
                    return;
                }
                kl *= P;
                kl %= MOD;
            }
        }
        out << "YES" << endl;
        for (int i = keks.fs; i <= keks.sc; i++) {
            out << a[x][i];
        }
        out << endl;
        for (int i = keks.fs; i <= keks.sc; i++) {
            out << b[x][i];
        }
    }
};

main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	TaskD solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}