#include <bits/stdc++.h>
using namespace std;
int main() {
  string second;
  cin >> second;
  map<string, string> mp1;
  for (int i = 0; i < 10; i++) {
    string s1;
    cin >> s1;
    mp1[s1] = to_string(i);
  }
  string p = "";
  string ans = "";
  for (int i = 0; i < second.length(); i++) {
    if (i % 10 == 0) {
      p = "";
    }
    p += second[i];
    if (i % 10 == 9)
      if (p.length() != 0) ans += mp1[p];
  }
  cout << ans << endl;
}
