#include <bits/stdc++.h>
using namespace std;
int n, m;
unordered_map<string, int> sch;
vector<string> res;
int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        string t;
        cin >> t;
        sch[t] = 1;
    }
    string a, b;
    cin >> m;
    while (m--) {
        string t;
        cin >> t;
        string name = t;
        if (sch.count(t) != 0) {
            res.push_back(t);
            
            if (a.empty() || a.substr(6, 8) > name.substr(6, 8))
                a = name;
        }
        
        if (b.empty() || b.substr(6, 8) > name.substr(6, 8))
            b = name;
    }
    
    cout << res.size() << endl;
    if (res.size()) {
        cout << a << endl;
    } else {
        cout << b << endl;
    }
    return 0;
}