/* -*- coding: utf-8 -*- * * 3798.cc: No.3798 algo to goal - yukicoder */ #include #include #include #include using namespace std; /* constant */ const int MAX_N = 1000000; /* typedef */ using ll = long long; using vi = vector; template struct BIT { int n; vector bits; BIT() {} BIT(int _n) { init(_n); } void init(int _n) { n = _n; bits.assign(n + 1, 0); } T sum(int x) { x = min(x, n); T s = 0; while (x > 0) { s += bits[x]; x -= (x & -x); } return s; } void add(int x, T v) { if (x <= 0) return; while (x <= n) { bits[x] += v; x += (x & -x); } } }; /* global variables */ char s[MAX_N + 4], t[MAX_N + 4]; /* subroutines */ vi extract(int n, char s[], int p) { vi v; for (int i = p; i < n; i += 2) v.push_back(s[i] - 'a'); return v; } vi anagram(vi v) { vi av(26, 0); for (auto u: v) av[u]++; return av; } ll invcnt(vi v) { BIT bit; bit.init(26); ll sum = 0; for (auto u: v) { sum += bit.sum(26) - bit.sum(u); bit.add(u + 1, 1); } return sum; } /* main */ int main() { int tn; scanf("%d", &tn); while (tn--) { scanf("%s%s", s, t); int n = strlen(s); auto sv0 = extract(n, s, 0); auto sv1 = extract(n, s, 1); auto tv0 = extract(n, t, 0); auto tv1 = extract(n, t, 1); auto asv0 = anagram(sv0); auto asv1 = anagram(sv1); auto atv0 = anagram(tv0); auto atv1 = anagram(tv1); if (asv0 != atv0 || asv1 != atv1) { puts("No"); continue; } int maxc0 = *max_element(asv0.begin(), asv0.end()); int maxc1 = *max_element(asv1.begin(), asv1.end()); if (maxc0 > 1 || maxc1 > 1) { puts("Yes"); continue; } ll sinv = invcnt(sv0) + invcnt(sv1); ll tinv = invcnt(tv0) + invcnt(tv1); if ((sinv & 1) == (tinv & 1)) puts("Yes"); else puts("No"); } return 0; }