#include <bits/stdc++.h>
using namespace std;
int main() {
  char code[80];
  cin >> code;
  char digitarray[10][10];
  for (int i = 0; i < 10; i++) {
    cin >> digitarray[i];
  }
  int password[8];
  char encodednum[10];
  int valid = 0;
  for (int i = 0; i < 8; i++) {
    for (int j = 0; j < 10; j++) {
      encodednum[j] = code[10 * i + j];
    }
    for (int j = 0; j < 10; j++) {
      valid = 1;
      for (int k = 0; k < 10; k++) {
        if (digitarray[j][k] != encodednum[k]) {
          valid = 0;
        }
      }
      if (valid) {
        password[i] = j;
      }
    }
  }
  cout << password[0] << password[1] << password[2] << password[3]
       << password[4] << password[5] << password[6] << password[7] << endl;
}
