没啥好说的
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <set>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <stack>
#define INF 0x3f3f3f3f
#define IMAX 2147483646
#define LINF 0x3f3f3f3f3f3f3f3f
#define ll long long
#define ull unsigned long long
#define uint unsigned int
using namespace std;
char s[2][2111111];
int l[2],t;
void get(int x) {
for (int i = 1; i <= l[x]; i++)
s[x][l[x] + i] = s[x][i];
int i = 1, j = 2, k;
while (i <= l[x] &&j <= l[x]) {
for (k = 0; k < l[x] &&s[x][i + k] == s[x][j + k]; k++);
if (k == l[x])break;
if (s[x][i + k] > s[x][j + k]) {
i = i + k + 1;
if (i == j)i++;
}
else {
j = j + k + 1;
if (i == j)j++;
}
}
j = min(i, j);
for (int i = 1; i <= l[x]; i++)
s[x][i] = s[x][i + j - 1];
s[x][l[x] + 1] = '\0';
}
char ans1[2111111], ans2[2111111];
int main() {
scanf("%d", &t);
while (t--) {
char iname[555] = "";
char oname[555] = "";
sprintf(iname, "necklace%d.in", t + 1);
sprintf(oname, "necklace%d.out", t + 1);
freopen(iname, "r", stdin);
scanf("%s%s", s[0] + 1, s[1] + 1);
l[0] = strlen(s[0] + 1), l[1] = strlen(s[1] + 1);
if (l[0] != l[1]) {
printf("NO\n");
return 0;
}
get(0), get(1);
bool flag = 1;
for (int i = 1; i <= l[0]; i++)
if (s[0][i] != s[1][i])flag = 0;
FILE *fp = fopen(oname, "r");
fscanf(fp, "%s", ans1);
if (ans1[0] == 'Y')
fscanf(fp, "%s", ans2);
fclose(fp);
if (ans1[0] == 'Y'&&strcmp(ans2, s[0] + 1) != 0)
printf("case %d is worng\n");
/*if (flag) printf("YES %s\n", s[0] + 1);
else printf("NO\n");*/
}
return 0;
}