#include #include using namespace std; int main() { char n[100007]; char *p, *q, *y; unsigned long s = 1; bool ok = false; while (s) { cin.getline(n, 100007); ok = false; p = strtok(n, " "); q = strtok(NULL, " "); y = strtok(NULL, " "); if (p[0] == '0' && strlen(p) == 1) { return 0; } for (int i = 0; i < strlen(n); i++) { if (p[i] == q[0]) { p[i] = y[0]; } } s = atol(p); if (s) { cout << s << "\n"; } } return 0; }