#include <bits/stdc++.h>
using namespace std;
int main() {
  string e[10], a;
  cin >> a;
  for (int i = 0; i < 10; i++) cin >> e[i];
  for (int i = 0; i < 8; i++) {
    for (int j = 0; j < 10; j++) {
      bool x = 1;
      for (int k = 0; k < 10; k++)
        if (a[i * 10 + k] != e[j][k]) x = 0;
      if (x == 1) cout << j;
    }
  }
  cout << endl;
  cin >> a;
  return 0;
}
