{"problem":{"name":"K. Cyclic Shift","description":{"content":"You are given two strings a and b of the same length and consisting of lowercase English letters. You can pick at most one subsequence of string b and do a cyclic shift on that subsequence exactly onc","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":1000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF10197K"},"statements":[{"statement_type":"Markdown","content":"You are given two strings a and b of the same length and consisting of lowercase English letters. You can pick at most one subsequence of string b and do a cyclic shift on that subsequence exactly once. \n\nFor example, if you have a string \"_abcdefg_\" and you picked the letters at indices 2, 5, and 6 as a subsequence to do a cyclic shift on them, the letter at index 2 will go to index 5, the letter at index 5 will go to index 6, the letter at index 6 will go to index 2, and the string will become \"_afcdbeg_\".\n\nYour task is to check if it is possible to make string b equivalent to string a using at most one cyclic shift. Can you?\n\nThe first line contains an integer T (1 ≤ T ≤ 200) specifying the number of test cases.\n\nThe first line of each test case contains an integer n (1 ≤ n ≤ 105) specifying the length of strings a and b. Then two lines follow, giving strings a and b, respectively. Both strings consist only of lowercase English letters.\n\nFor each test case, print a single line containing \"_YES_\" (without quotes) if it is possible to make string b equivalent to string a using at most one cyclic shift. Otherwise, print \"_NO_\" (without quotes).\n\nA subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements. For example, the sequence  is a subsequence of  obtained after removal of elements , , and . \n\n## Input\n\nThe first line contains an integer T (1 ≤ T ≤ 200) specifying the number of test cases.The first line of each test case contains an integer n (1 ≤ n ≤ 105) specifying the length of strings a and b. Then two lines follow, giving strings a and b, respectively. Both strings consist only of lowercase English letters.\n\n## Output\n\nFor each test case, print a single line containing \"_YES_\" (without quotes) if it is possible to make string b equivalent to string a using at most one cyclic shift. Otherwise, print \"_NO_\" (without quotes).\n\n[samples]\n\n## Note\n\nA subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements. For example, the sequence  is a subsequence of  obtained after removal of elements , , and .","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ T \\in \\mathbb{Z} $ be the number of test cases.  \nFor each test case $ k \\in \\{1, \\dots, T\\} $:  \n- Let $ n_k \\in \\mathbb{Z} $ denote the length of strings $ a_k $ and $ b_k $.  \n- Let $ a_k = (a_{k,1}, a_{k,2}, \\dots, a_{k,n_k}) $ and $ b_k = (b_{k,1}, b_{k,2}, \\dots, b_{k,n_k}) $ be strings of length $ n_k $ over the alphabet of lowercase English letters.  \n\n**Constraints**  \n1. $ 1 \\le T \\le 200 $  \n2. For each $ k \\in \\{1, \\dots, T\\} $:  \n   - $ 1 \\le n_k \\le 10^5 $  \n   - $ a_{k,i}, b_{k,i} \\in \\{ \\text{a}, \\text{b}, \\dots, \\text{z} \\} $ for all $ i \\in \\{1, \\dots, n_k\\} $  \n\n**Objective**  \nDetermine whether there exists a subsequence $ I = (i_1, i_2, \\dots, i_m) $ of indices of $ b_k $, with $ m \\ge 1 $ and $ 1 \\le i_1 < i_2 < \\dots < i_m \\le n_k $, such that performing a **cyclic shift** on the characters of $ b_k $ at positions in $ I $ yields $ a_k $.  \n\nA cyclic shift on $ I $ means:  \n- For each $ j \\in \\{1, \\dots, m-1\\} $, the character at position $ i_j $ moves to position $ i_{j+1} $,  \n- The character at position $ i_m $ moves to position $ i_1 $,  \n- All characters not in $ I $ remain unchanged.  \n\nOutput \"YES\" if such a subsequence $ I $ exists; otherwise, output \"NO\".","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF10197K","tags":[],"sample_group":[],"created_at":"2026-03-03 11:00:39"}}