/*
David Du
 Bergen County Academies
 Senior
 */


#include 
#include 
#include 
#include 

using namespace std;



pair longest_common_substring(string a, string b){
    int maxlen = 0;
    int end = a.length();
    vector> ret;
    if(a.empty() || b.empty()){
        return make_pair(0, 0);
    }

    int lookup[a.length() + 1][b.length() + 1];

    memset(lookup, 0, sizeof(lookup));

    for (int i = 1; i <= a.length(); i++){
        for (int j = 1; j <= b.length(); j++){

            if (a[i - 1] == b[j - 1]){

                lookup[i][j] = lookup[i - 1][j - 1] + 1;

                if (lookup[i][j] > maxlen){
                    maxlen = lookup[i][j];
                    end = i;
                    ret.clear();
                    ret.push_back(make_pair(end - maxlen, maxlen));
                }
                else if(lookup[i][j] == maxlen){
                    ret.push_back(make_pair(i - maxlen, maxlen));
                }
            }
        }
    }
    if(ret.size() == 0){
        return make_pair(0, 0);
    }
    else if(ret.size() == 1){
        return ret[0];
    }
    int index = 0;
    int min = a[ret[0].first];
    for (int k = 1; k < ret.size(); ++k) {
        if(a[ret[k].first] < min){
            min = a[ret[k].first];
            index = k;
        }
        else if (a[ret[k].first] == min){
            for (int i = 0; i < ret[k].second; ++i) {
                if(a[ret[k].first + i] < a[ret[index].first + i]  && ret[k].first != ret[index].first){
                    index = k;
                }
                else if(a[ret[k].first + i] > a[ret[index].first + i]  && ret[k].first != ret[k + 1].first){
                    break;
                }
            }
        }


    }

    return ret[index];
}


int compute(string &a, string &b){
    if(a.length() == 0 || b.length() == 0){
        return 0;
    }
    pair first = longest_common_substring(a, b);
    pair second = longest_common_substring(b, a);
    string c = a.substr(0, first.first);
    string d = b.substr(0, second.first);
    string cc = a.substr(first.second + first.first, a.length());
    string dd = b.substr(second.second + second.first, b.length());

    if((c == a && d == b ) || (cc == a && dd == b)){
        return 0;
    }

    return first.second + compute(c, d) + compute(cc, dd);

}

bool custom_remove(char& c){
    return (c < 65 || c > 90);
}


int main(){
    freopen("sr-sample-input.txt", "r", stdin);

    for (int i = 0; i < 5; ++i) {
        string a;
        string b;

        getline(cin, a);
        getline(cin, b);

        a.erase(remove_if(a.begin(), a.end(), ::isspace), a.end());
        b.erase(remove_if(b.begin(), b.end(), ::isspace), b.end());

        transform(a.begin(), a.end(), a.begin(), ::toupper);
        transform(b.begin(), b.end(), b.begin(), ::toupper);

        a.erase(remove_if(a.begin(), a.end(), custom_remove), a.end());
        b.erase(remove_if(b.begin(), b.end(), custom_remove), b.end());


        cout << compute(a, b) << '\n';
    }
}