#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1000000000;

int main() {FIN
    
    int t = 0;
    char e;
    vs nm = {"A", "B", "C"};
    vs ply(3);
    vi pos(3, 0);
    cin >> ply[0];
    cin >> ply[1];
    cin >> ply[2];
    
    while (true) {
		if ((int)ply[t].size() == pos[t]) break;
		e = ply[t][pos[t]];
		pos[t]++;
		t = (e - 'a');
	}
    cout << nm[t] << "\n";
    
    return 0;
}

#include <bits/stdc++.h>
#define repl(i, l, r) for (int i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;

int main()
{
    int n;
    cin >> n;
    string a, b, c;
    cin >> a;
    cin >> b;
    cin >> c;
    int count = 0;
    rep(i, n) {
        if(a[i] != b[i]) {
            if(a[i] == c[i]) count++;
            else if(b[i] == c[i]) count++;
            else count += 2;
        }
        else {
            if(a[i] != c[i]) count++;
        }
    }
    cout << count << endl;
    return 0;
}