#include <bits/stdc++.h>
using namespace std;
int main() {
  int n0 = 0, n1 = 1, n2 = 2, n3 = 3, n4 = 4, n5 = 5, n6 = 6, n7 = 7, n8 = 8,
      n9 = 9, a = 0;
  string STR, str0, str1, str2, str3, str4, str5, str6, str7, str8, str9;
  cin >> STR >> str0 >> str1 >> str2 >> str3 >> str4 >> str5 >> str6 >> str7 >>
      str8 >> str9;
  for (int i = 0; i < STR.size(); i += 10) {
    if (STR[i] == str0[a] && STR[i + 1] == str0[a + 1] &&
        STR[i + 2] == str0[a + 2] && STR[i + 3] == str0[a + 3] &&
        STR[i + 4] == str0[a + 4] && STR[i + 5] == str0[a + 5] &&
        STR[i + 6] == str0[a + 6] && STR[i + 7] == str0[a + 7] &&
        STR[i + 8] == str0[a + 8] && STR[i + 9] == str0[a + 9])
      cout << n0;
    else if (STR[i] == str1[a] && STR[i + 1] == str1[a + 1] &&
             STR[i + 2] == str1[a + 2] && STR[i + 3] == str1[a + 3] &&
             STR[i + 4] == str1[a + 4] && STR[i + 5] == str1[a + 5] &&
             STR[i + 6] == str1[a + 6] && STR[i + 7] == str1[a + 7] &&
             STR[i + 8] == str1[a + 8] && STR[i + 9] == str1[a + 9])
      cout << n1;
    else if (STR[i] == str2[a] && STR[i + 1] == str2[a + 1] &&
             STR[i + 2] == str2[a + 2] && STR[i + 3] == str2[a + 3] &&
             STR[i + 4] == str2[a + 4] && STR[i + 5] == str2[a + 5] &&
             STR[i + 6] == str2[a + 6] && STR[i + 7] == str2[a + 7] &&
             STR[i + 8] == str2[a + 8] && STR[i + 9] == str2[a + 9])
      cout << n2;
    else if (STR[i] == str3[a] && STR[i + 1] == str3[a + 1] &&
             STR[i + 2] == str3[a + 2] && STR[i + 3] == str3[a + 3] &&
             STR[i + 4] == str3[a + 4] && STR[i + 5] == str3[a + 5] &&
             STR[i + 6] == str3[a + 6] && STR[i + 7] == str3[a + 7] &&
             STR[i + 8] == str3[a + 8] && STR[i + 9] == str3[a + 9])
      cout << n3;
    else if (STR[i] == str4[a] && STR[i + 1] == str4[a + 1] &&
             STR[i + 2] == str4[a + 2] && STR[i + 3] == str4[a + 3] &&
             STR[i + 4] == str4[a + 4] && STR[i + 5] == str4[a + 5] &&
             STR[i + 6] == str4[a + 6] && STR[i + 7] == str4[a + 7] &&
             STR[i + 8] == str4[a + 8] && STR[i + 9] == str4[a + 9])
      cout << n4;
    else if (STR[i] == str5[a] && STR[i + 1] == str5[a + 1] &&
             STR[i + 2] == str5[a + 2] && STR[i + 3] == str5[a + 3] &&
             STR[i + 4] == str5[a + 4] && STR[i + 5] == str5[a + 5] &&
             STR[i + 6] == str5[a + 6] && STR[i + 7] == str5[a + 7] &&
             STR[i + 8] == str5[a + 8] && STR[i + 9] == str5[a + 9])
      cout << n5;
    else if (STR[i] == str6[a] && STR[i + 1] == str6[a + 1] &&
             STR[i + 2] == str6[a + 2] && STR[i + 3] == str6[a + 3] &&
             STR[i + 4] == str6[a + 4] && STR[i + 5] == str6[a + 5] &&
             STR[i + 6] == str6[a + 6] && STR[i + 7] == str6[a + 7] &&
             STR[i + 8] == str6[a + 8] && STR[i + 9] == str6[a + 9])
      cout << n6;
    else if (STR[i] == str7[a] && STR[i + 1] == str7[a + 1] &&
             STR[i + 2] == str7[a + 2] && STR[i + 3] == str7[a + 3] &&
             STR[i + 4] == str7[a + 4] && STR[i + 5] == str7[a + 5] &&
             STR[i + 6] == str7[a + 6] && STR[i + 7] == str7[a + 7] &&
             STR[i + 8] == str7[a + 8] && STR[i + 9] == str7[a + 9])
      cout << n7;
    else if (STR[i] == str8[a] && STR[i + 1] == str8[a + 1] &&
             STR[i + 2] == str8[a + 2] && STR[i + 3] == str8[a + 3] &&
             STR[i + 4] == str8[a + 4] && STR[i + 5] == str8[a + 5] &&
             STR[i + 6] == str8[a + 6] && STR[i + 7] == str8[a + 7] &&
             STR[i + 8] == str8[a + 8] && STR[i + 9] == str8[a + 9])
      cout << n8;
    else if (STR[i] == str9[a] && STR[i + 1] == str9[a + 1] &&
             STR[i + 2] == str9[a + 2] && STR[i + 3] == str9[a + 3] &&
             STR[i + 4] == str9[a + 4] && STR[i + 5] == str9[a + 5] &&
             STR[i + 6] == str9[a + 6] && STR[i + 7] == str9[a + 7] &&
             STR[i + 8] == str9[a + 8] && STR[i + 9] == str9[a + 9])
      cout << n9;
  }
  return 0;
}
