#include<iostream>
#include<string>
using namespace std;

int main()
{
    int n;
    int key[4];
    string judge;
    int number[10] = {0};

    cin >> n;

    for(int i=0; i<n; i++){
        for(int j=0; j<4; j++)cin >> key[j];
        cin >> judge;
        if(judge == "YES"){
            for(int j=0; j<10; j++){
                for(int k=0; k<4; k++){
                    if(j == key[k]) break;
                    if(k == 3) number[j] = -1;
                }
            }
        }
        if(judge == "NO"){
            for(int j=0; j<4; j++){
                number[key[j]] = -1;
            }
        }
    }

    for(int i=0; i<10; i++){
        if(number[i] == 0) cout << i << endl;
    }

    return 0;
}