#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, password = "", temp = "";
  vector<string> vs(10);
  cin >> s;
  bool action = 0;
  for (int i = 0; i < 10; i++) cin >> vs[i];
  int cnt = 0, cnt1 = 0;
  for (int i = 0; i < 80; i++) {
    temp += s[i];
    cnt++;
    if (cnt == 10) {
      for (int j = 0; j < 10; j++) {
        for (int k = 0; k < 10; k++) {
          if (vs[j][k] == temp[k]) cnt1++;
        }
        if (cnt1 == 10) {
          stringstream ss;
          ss << j;
          password += ss.str();
          action = 1;
        }
        cnt1 = 0;
        if (action) {
          action = 0;
          break;
        }
      }
      temp = "";
      cnt = 0;
    }
  }
  cout << password << endl;
}
