#include <bits/stdc++.h>
using namespace std;
int main() {
  unordered_map<string, char> M;
  string s, t, ans = "";
  cin >> s;
  for (int i = 0; i < 10; i++) {
    cin >> t;
    M[t] = i + '0';
  }
  for (int j = 0; j < s.size(); j += 10) ans += M[s.substr(j, 10)];
  cout << ans;
  return 0;
}
