This problem is different from the hard version. In this version Ujan makes exactly one exchange. You can hack this problem only if you solve both problems.

After struggling and failing many times, Ujan decided to try to clean up his house again. He decided to get his strings in order first.

Ujan has two distinct strings ss and tt of length nn consisting of only of lowercase English characters. He wants to make them equal. Since Ujan is lazy, he will perform the following operation exactly once: he takes two positions ii and jj (1≤i,j≤n1≤i,j≤n, the values ii and jj can be equal or different), and swaps the characters sisi and tjtj. Can he succeed?

Note that he has to perform this operation exactly once. He has to perform this operation.

Input

The first line contains a single integer kk (1≤k≤101≤k≤10), the number of test cases.

For each of the test cases, the first line contains a single integer nn (2≤n≤1042≤n≤104), the length of the strings ss and tt.

Each of the next two lines contains the strings ss and tt, each having length exactly nn. The strings consist only of lowercase English letters. It is guaranteed that strings are different.

Output

For each test case, output "Yes" if Ujan can make the two strings equal and "No" otherwise.

You can print each letter in any case (upper or lower).

Example
input

Copy
4
5
souse
houhe
3
cat
dog
2
aa
az
3
abc
bca
output

Copy
Yes
No
No
No
Note

In the first test case, Ujan can swap characters s1s1 and t4t4, obtaining the word "house".

In the second test case, it is not possible to make the strings equal using exactly one swap of sisi and tjtj.

#include<bis/stdc++.h>
using namespace std;
int main() {
int t;
scanf("%d",&t);
while(t--) {
int n;
scanf("%d",&n);
string s,t;
cin>>s;
cin>>t;
int c1=-,c2=-;
int flag = ;
int sum=;
for(int i = ; i < n; i++) {
if(s[i] != t[i]) {
sum++;
if(sum == ) { //记录不同的位置
c1 = i;
} else if(sum == ) {
c2 = i;
} else {
flag = ;//两对以上,直接结束
break;
}
}
}
if(flag == ) {
printf("No\n");
continue;
}
if(s[c1] == s[c2]&&t[c1] == t[c2]) {
printf("Yes\n");
} else {//字母不同
printf("No\n");
}
}
return ;
}

Codeforces Round #599 (Div. 2) B1. Character Swap (Easy Version)的更多相关文章

  1. Codeforces Round #599 (Div. 2) B1. Character Swap (Easy Version) 水题

    B1. Character Swap (Easy Version) This problem is different from the hard version. In this version U ...

  2. Codeforces Round #599 (Div. 2) B2. Character Swap (Hard Version) 构造

    B2. Character Swap (Hard Version) This problem is different from the easy version. In this version U ...

  3. Codeforces Round #599 (Div. 2) B2. Character Swap (Hard Version)

    This problem is different from the easy version. In this version Ujan makes at most 2n2n swaps. In a ...

  4. Codeforces Round #540 (Div. 3) F1. Tree Cutting (Easy Version) 【DFS】

    任意门:http://codeforces.com/contest/1118/problem/F1 F1. Tree Cutting (Easy Version) time limit per tes ...

  5. Codeforces Round #540 (Div. 3)--1118F1 - Tree Cutting (Easy Version)

    https://codeforces.com/contest/1118/problem/F1 #include<bits/stdc++.h> using namespace std; in ...

  6. Codeforces Round #653 (Div. 3) E1. Reading Books (easy version) (贪心,模拟)

    题意:有\(n\)本书,A和B都至少要从喜欢的书里面读\(k\)本书,如果一本书两人都喜欢的话,那么他们就可以一起读来节省时间,问最少多长时间两人都能够读完\(k\)本书. 题解:我们可以分\(3\) ...

  7. Codeforces Round #672 (Div. 2) C1. Pokémon Army (easy version) (DP)

    题意:给你一组数\(a\),构造一个它的子序列\(b\),然后再求\(b_1-b2+b3-b4...\),问构造后的结果最大是多少. 题解:线性DP.我们用\(dp1[i]\)来表示在\(i\)位置, ...

  8. Codeforces Round #650 (Div. 3) F1. Flying Sort (Easy Version) (离散化,贪心)

    题意:有一组数,每次操作可以将某个数移到头部或者尾部,问最少操作多少次使得这组数非递减. 题解:先离散化将每个数映射为排序后所对应的位置,然后贪心,求最长连续子序列的长度,那么最少的操作次数一定为\( ...

  9. Codeforces Round #658 (Div. 2) C1. Prefix Flip (Easy Version) (构造)

    题意:给你两个长度为\(n\)的01串\(s\)和\(t\),可以选择\(s\)的前几位,取反然后反转,保证\(s\)总能通过不超过\(3n\)的操作得到\(t\),输出变换总数,和每次变换的位置. ...

随机推荐

  1. java字符串操作扩充:灵活截取字符串

    java字符串操作扩充:灵活截取字符串 public class StringUtil { static int varlen1; static int varlen2; static String ...

  2. H3C ARP配置

    一.ARP简介 ARP(Address Resolution Protocol,地址解析协议)是将IP地址解析为以太网MAC地址(或称物理地址)的协议. 在网络中,当主机或其它网络设备有数据要发送给另 ...

  3. K3标准产品的BOS单据发布至自定义模块

    在自定义模块 下先随便发布一张单据,然后后台更新数据表. select * from icclasstype where fname_chs like '付款申请单%'   --查询表单的ID upd ...

  4. Spring域属性自动注入byName和byType

    byName 方式 <!--byName约束:bean当中的域属性名必须跟所注入bean的id相同--> <bean id="student" class=&qu ...

  5. C语言运算符的优先级与结合性

    结合性:左结合是从左到右依次执行,右结合是从右到左依次执行. 优先级 运算符 名称或作用 运算类型 结合方向 特点 1 () [] -> . 小括号运算符 下标运算符 指向结构成员运算符 结构成 ...

  6. python爬虫模拟登录的图片验证码处理和会话维持

    目标网站:古诗文网 登录界面显示: 打开控制台工具,输入账号密码,在ALL栏目中进行抓包 数据如下: 登录请求的url和请求方式 登录所需参数 参数分析: __VIEWSTATE和__VIEWSTAT ...

  7. 神器扒网站——teleport ultra

    在平时的开发或者学习的过程中,我们难免会看到一些让人心动的网站,于是自己想把它搞下来,自己手工一个文件一个文件把它保存下来也可以实现,完成了也累得够呛,有一款扒站的神器,可以把你所喜欢的目标网站整个网 ...

  8. 在vue中使用swiper4.x

    需求 :实现一个左右两边有边距的轮播图vue+swiper4 轮播图左右两边含有上一张和下一张的一部分 先安装swiper: 1.npm install swiper 安装swiper   2.在入口 ...

  9. AcWing 1010. 拦截导弹

    //贪心加dp #include<iostream> using namespace std ; ; int n; int q[N]; int f[N]; int g[N];//存每个序列 ...

  10. 题解【Vijos1159】岳麓山上打水

    题面 迭代加深搜索模板题. 注意开始时要先对桶的容量从小到大排序. 达到搜索层数时使用完全背包\(\text{check}\)即可. 具体实现参考代码. #include <bits/stdc+ ...