// by Dan Joyce
// solves Problem 1: Cowculations 
// of 1996 Mid Atlantic programming contest

// input is descriptions of cow tablets 
// output tells if the tablets uphold the theory 

// Note:  Cow math is just base 4 math with V=0, U=1, C=2, D=3

import java.io.*;
import common.doinput;

class problem1 {

  static int convert(String s, int len) {
  /* takes a 'len' character cow string 's' and changes it to
     an integer, based on fact that cow strings are base 4
  */
  int value = 0;
  for (int i = 0; i < len; i++) {
    switch (s.charAt(i)) {
      case 'V': value = (value * 4) + 0;  break;
      case 'U': value = (value * 4) + 1;  break;
      case 'C': value = (value * 4) + 2;  break;
      case 'D': value = (value * 4) + 3;  break;
      }
    }
  return value;
  }

  public static void main (String [] args) throws IOException {

    String in_String;       // input string
    int N;                  // number of tablets
    int Num1, Num2, Num3;

    doinput myinput = new doinput();

    System.out.println ("COWCULATIONS OUTPUT");	

    N = myinput.nextint();

    for (int count = 1; count <= N; count++)
      {
      in_String = myinput.nextsubstring();
      Num1 = convert(in_String,5);
      in_String = myinput.nextsubstring();
      Num2 = convert(in_String,5);
 
      for (int cnt = 1; cnt <=3; cnt++) {
        in_String = myinput.nextsubstring();
        
        if (in_String.equals("A")) {
          Num2 = Num1 + Num2;
          }

        if (in_String.equals("R")) {
          Num2 = Num2 / 4;
          }

        if (in_String.equals("L")) {
          Num2 = Num2 * 4;
          }

        if (in_String.equals("N")) {
          // do nothing
          }
        };

      in_String = myinput.nextsubstring();
      Num3 = convert(in_String,8);

      if (Num2 == Num3) System.out.println("YES");
      else System.out.println("NO"); 

      };

  System.out.println("END OF OUTPUT");
  }
}

