D. Unique Palindromes

A palindrome is a string that reads the same backwards as forwards. For example, the string abcba is palindrome, while the string abca is not.

Let p(t)p(t) be the number of unique palindromic substrings of string tt, i. e. the number of substrings t[l…r]t[l…r] that are palindromes themselves. Even if some substring occurs in tt several times, it's counted exactly once. (The whole string tt is also counted as a substring of tt).

For example, string tt == abcbbcabcb has p(t)=6p(t)=6 unique palindromic substrings: a, b, c, bb, bcb and cbbc.

Now, let's define p(s,m)=p(t)p(s,m)=p(t) where t=s[1…m]t=s[1…m]. In other words, p(s,m)p(s,m) is the number of palindromic substrings in the prefix of ss of length mm. For example, p(p(abcbbcabcb,5),5) == p(p(abcbb)=5)=5.

You are given an integer nn and kk "conditions" (k≤20k≤20). Let's say that string ss, consisting of nn lowercase Latin letters, is good if all kk conditions are satisfied at the same time. A condition is a pair (xi,ci)(xi,ci) and have the following meaning:

  • p(s,xi)=cip(s,xi)=ci, i. e. a prefix of ss of length xixi contains exactly cici unique palindromic substrings.

Find a good string ss or report that such ss doesn't exist.

Look in Notes if you need further clarifications.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041≤t≤104). The description of the test cases follows.

The first line of each test case contains two integers nn and kk (3≤n≤2⋅1053≤n≤2⋅105; 1≤k≤201≤k≤20) — length of good string ss and number of conditions.

The second line of each test case contains kk integers x1,x2,…,xkx1,x2,…,xk (3≤x1<x2<⋯<xk=n3≤x1<x2<⋯<xk=n) where xixi is the length of the prefix in the ii-th condition.

The third line of each test case contains kk integers c1,c2,…,ckc1,c2,…,ck (3≤c1≤c2≤⋯≤ck≤min(109,(n+1)n2)3≤c1≤c2≤⋯≤ck≤min(109,(n+1)n2)) where cici is the number of palindromic substrings in the ii-th condition.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052⋅105.

Output

For each test case, if there is no good string ss of length nn that satisfies all conditions, print NO.

Otherwise, print YES and a string ss of length nn, consisting of lowercase Latin letters, that satisfies all conditions. If there are multiple answers, print any of them.

Example

input

Copy

 

7

10 2

5 10

5 6

3 1

3

3

4 2

3 4

3 3

4 2

3 4

3 4

4 1

4

5

10 3

4 6 10

4 5 8

10 4

4 6 7 10

4 5 7 8

output

Copy

YES
abcbbcabcb
YES
foo
YES
ayda
YES
wada
NO
YES
abcbcacbab
NO

Note

In the first test case, string ss == abcbbcabcb satisfies k=2k=2 conditions:

  • p(s,x1)=p(s,5)=p(s,x1)=p(s,5)= p(p(abcbb)=5=s1)=5=s1. Palindromic substrings are a, b, c, bb and bcb.
  • p(s,x2)=p(s,10)=p(s,x2)=p(s,10)= p(p(abcbbcabcb)=6=s2)=6=s2. Palindromic substrings are the same as above, and one extra substring cbbc.

In the second test case, string foo satisfies k=1k=1 condition:

  • p(p(foo)=3)=3. Palindromic substrings are f, o and oo.

There are other possible answers.

In the third test case, string ayda satisfies k=2k=2 conditions:

  • p(p(ayd)=3)=3. Palindromic substrings are a, y and d.
  • p(p(ayda)=3)=3. Palindromic substrings are the same.

In the fourth test case, string wada satisfies k=2k=2 conditions:

  • p(p(wad)=3)=3. Palindromic substrings are w, a and d.
  • p(p(wada)=4)=4. Palindromic substrings are the same, and one extra substring ada.

In the fifth test case, it can be proven that there is no string of length 44 which has 55 palindromic substrings.

In the sixth test case, string abcbcacbab satisfies k=3k=3 conditions:

  • p(p(abcb)=4)=4. Palindromic substrings are a, b, c and bcb.
  • p(p(abcbca)=5)=5. Palindromic substrings are the same, and one extra substring cbc.
  • p(p(abcbcacbab)=8)=8. Palindromic substrings are the same, and three extra substrings cac, bab and bcacb.

#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>//to_string(value)
#include<cstdio>
#include<cmath>
#include<vector>//res.erase(unique(res.begin(), res.end()), res.end())
#include<queue>
#include<stack>
#include<map>
#include<set>//iterator,insert(),erase(),lower/upper_bound(value)/find()return end()
#define ll long long
using namespace std;
int x[200001];
int c[200001];
vector<int> q;
int y = 0,pan=1;
char wc[3] = { 'a','b','c' };
signed main() {
	int t;
	char ch = 'd';
	cin >> t;
	while (t--) {
		q.clear();
		pan = 1;
		int n, k;
		cin >> n >> k;
		for (int i = 0; i < k; i++) cin >> x[i];
		for (int i = 0; i < k; i++) cin >> c[i];
		for (int i = 0; i < k; i++) {
			if (i == 0) {
				if (c[i] > x[i]) {
					cout << "NO" << endl;
					pan = 0;
					break;
				}
				else {
					for (int j = 0; j < c[i] - 3; j++) {
						q.push_back(ch + i);
					}
					if (q.empty()) {
						q.push_back(wc[y]);
						y++;
						if (y == 3) y = 0;
					}
						while (q.size() < x[i]) {
							q.push_back(wc[y]);
							y++;
							if (y == 3) y = 0;
						}
				}
			}
			else {
				if (c[i] - c[i - 1] > x[i] - x[i - 1]) {
					cout << "NO" << endl;
					pan = 0;
					break;
				}
				else {
					for (int j = 0; j < c[i] - c[i - 1]; j++) {
						q.push_back(ch + i);
					}
					while (q.size() < x[i]) {
						q.push_back(wc[y]);
						y++;
						if (y == 3) y = 0;
					}
				}
			}
		}
		if (pan == 1) {
			while (q.size() != n) {
				q.push_back(wc[y]);
				y++;
				if (y == 3) y = 0;
			}
			cout << "YES" << endl;
			for (int i = 0; i < n; i++) {
				printf("%c", q[i]);
			}
			cout << endl;
		}
	}
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值