#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
  cin.sync_with_stdio(false);
  cout << setprecision(16);
  string input, m[10], output;
  int i, idx = 0, j;
  cin >> input;
  for (i = 0; i < (int)(10); i++) cin >> m[i];
  while (idx != input.length()) {
    for (i = 0; i < (int)(10); i++) {
      bool good = true;
      for (j = 0; j < (int)(m[i].length()); j++)
        if (m[i][j] != input[idx + j]) {
          good = false;
          break;
        }
      if (good) {
        output += (char)('0' + i);
        idx += m[i].length();
      }
    }
  }
  cout << output << endl;
  cout.flush();
}
