#include #include using i64 = long long; void solve() { using T = std::tuple; T a[2]; for (int i = 0; i < 2; i++) { auto &[x, y, ch] = a[i]; std::cin >> x >> y >> ch; } auto check = [&](T a, T b) { auto &[x1, y1, c1] = a; auto &[x2, y2, c2] = b; if (c1 == 'R' && c2 == 'L') { if (y1 == y2 && x1 < x2) { return true; } } if (c1 == 'R' && (c2 == 'U' || c2 == 'D')) { if (x1 < x2 && std::abs(x1 - x2) == std::abs(y1 - y2)) { return true; } } if (c1 == 'L' && c2 == 'R') { if (y1 == y2 && x1 > x2) { return true; } } if (c1 == 'L' && (c2 == 'D' || c2 == 'U')) { if (x2 < x1 && std::abs(x1 - x2) == std::abs(y1 - y2)) { return true; } } if (c1 == 'D' && c2 == 'U') { if (x1 == x2 && y1 > y2) { return true; } } if (c1 == 'D' && (c2 == 'L' || c2 == 'R')) { if (y1 > y2 && std::abs(x1 - x2) == std::abs(y1 - y2)) { return true; } } if (c1 == 'U' && c2 == 'D') { if (x1 == x2 && y1 < y2) { return true; } } if (c1 == 'U' && (c2 == 'L' || c2 == 'R')) { if (y1 < y2 && std::abs(x1 - x2) == std::abs(y1 - y2)) { return true; } } return false; }; if (check(a[0], a[1])) { std::cout << "Yes\n"; } else { std::cout << "No\n"; } } int main() { std::cin.tie(nullptr)->sync_with_stdio(false); int t; std::cin >> t; while (t--) { solve(); } return 0; }