awoo‘s Favorite Problem(思维)

You are given two strings ss and tt, both of length nn. Each character in both string is 'a', 'b' or 'c'.

In one move, you can perform one of the following actions:

  • choose an occurrence of "ab" in ss and replace it with "ba";
  • choose an occurrence of "bc" in ss and replace it with "cb".

You are allowed to perform an arbitrary amount of moves (possibly, zero). Can you change string ss to make it equal to string tt?

Input

The first line contains a single integer qq (1≤q≤1041≤q≤104) — the number of testcases.

The first line of each testcase contains a single integer nn (1≤n≤1051≤n≤105) — the length of strings ss and tt.

The second line contains string ss of length nn. Each character is 'a', 'b' or 'c'.

The third line contains string tt of length nn. Each character is 'a', 'b' or 'c'.

The sum of nn over all testcases doesn't exceed 105105.

Output

For each testcase, print "YES" if you can change string ss to make it equal to string tt by performing an arbitrary amount of moves (possibly, zero). Otherwise, print "NO".

Example

input

Copy

5
3
cab
cab
1
a
b
6
abbabc
bbaacb
10
bcaabababc
cbbababaac
2
ba
ab

output

Copy

YES
NO
YES
YES
NOs

思路:

1,透过操作要求,找到一些相对不变的规则

2,读假题了,“ab”是个连续的字串,因此a只能相对后移,c只能相对的前移

3,代码是通过验证通过的,需要符合2,以及去掉b后的字符串要一致

代码:

#include<bits/stdc++.h>
using namespace std;
#define int long long
#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")//
const int maxj=3e5+100,mod=998244353;
void solve(){//构造验证,a的位置只会后移,c的位置只会前移,a,c的个数各自相同
    int n;cin>>n;
    string s,t;
    cin>>s>>t;
    int cnt1=0,cnt2=0;
    int ct1=0,ct2=0;
    vector<int>a1,a2,c1,c2;
    string ss1="",ss2="";
    for(int i=0;i<n;++i){
        if(s[i]!='b') ss1+=s[i];
        if(t[i]!='b') ss2+=t[i];
        if(s[i]=='a') a1.emplace_back(i);
        if(s[i]=='c') c1.emplace_back(i);
        if(t[i]=='a') a2.emplace_back(i);
        if(t[i]=='c') c2.emplace_back(i);
    }
    if(ss1!=ss2){//a,c相对位置不变,abc,cba这个不做考虑
        cout<<"NO"<<'\n';
        return ;
    }
    bool k=0;
    for(int i=0;i<a1.size();++i){
        if(a1[i]>a2[i]){
            cout<<"NO"<<'\n';
            return ;
        }
    }
    for(int i=0;i<c1.size();++i){
        if(c1[i]<c2[i]){
            cout<<"NO"<<'\n';
            return ;
        }
    }
    cout<<"YES"<<'\n';
}
int32_t main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    // t=1;
    while(t--)solve();
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值