//Checker Задачи ДВЕ ДРОБИ.
//Киндер М., версия 03.11.2015

#include "testlib.h"
using namespace std;

int main(int argc, char *argv[])
{ setName("Two-fractions checker");
    registerTestlibCmd(argc, argv);
    
    int sp = ouf.readInt(1, 2000001, "number of operations");
    int a = inf.readInt();
    int b = inf.readInt();
    int c = inf.readInt();
    int d = inf.readInt();
    
    ouf.skipBlanks();
    for (int i = 0; i < sp; i++)
    {   if (ouf.eof()) quit(_pe, "not enough symbols");
        char pa = ouf.readChar();
        if (pa < 'A' || pa > 'C') quit(_pe, "invalid character in answer");
        if (pa == 'A') a += b;
        if (pa == 'B') a -= b;
        if (pa == 'C')
           {  if (b == 0) quitf(_wa, "operation C is can not applied to zero.");
              int t = a; a = b; b = t;
           }
    }
    ouf.skipBlanks();
    if (!ouf.eof()) quit(_pe, "too many symbols");
    if (a * d != b * c) 
       quitf(_wa, "numbers differ - expected: %d/%d, found: %d/%d", c, d, a, b);
    quitf(_ok, "");
}