当前位置: 首页 > 工具软件 > Construct > 使用案例 >

B. Construct the String

曾光远
2023-12-01

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given three positive integers nn, aa and bb. You have to construct a string ss of length nn consisting of lowercase Latin letters such that each substring of length aa has exactly bb distinct letters. It is guaranteed that the answer exists.

You have to answer tt independent test cases.

Recall that the substring s[l…r]s[l…r] is the string sl,sl+1,…,srsl,sl+1,…,sr and its length is r−l+1r−l+1. In this problem you are only interested in substrings of length aa.

Input

The first line of the input contains one integer tt (1≤t≤20001≤t≤2000) — the number of test cases. Then tt test cases follow.

The only line of a test case contains three space-separated integers nn, aa and bb (1≤a≤n≤2000,1≤b≤min(26,a)1≤a≤n≤2000,1≤b≤min(26,a)), where nn is the length of the required string, aa is the length of a substring and bb is the required number of distinct letters in each substring of length aa.

It is guaranteed that the sum of nn over all test cases does not exceed 20002000 (∑n≤2000∑n≤2000).

Output

For each test case, print the answer — such a string ss of length nn consisting of lowercase Latin letters that each substring of length aa has exactly bb distinct letters. If there are multiple valid answers, print any of them. It is guaranteed that the answer exists.

Example

input

Copy

4
7 5 3
6 1 1
6 6 1
5 2 2

output

Copy

tleelte
qwerty
vvvvvv
abcde

Note

In the first test case of the example, consider all the substrings of length 55:

  • "tleel": it contains 33 distinct (unique) letters,
  • "leelt": it contains 33 distinct (unique) letters,
  • "eelte": it contains 33 distinct (unique) letters.

 

解题说明:此题是一道字符串题,只需要找出一个满足条件的字符串,b不超过26即可。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>

using namespace std;

int main()
{
	int T, a, b, n, i;
	scanf("%d", &T);
	while (T--)
	{
		scanf("%d %d %d", &n, &a, &b);
		while (n)
		{
			for (i = 0; i<b; i++)
			{
				if (n == 0)
				{
					break;
				}
				printf("%c", 97 + i);
				n--;
			}
		}
		printf("\n");
	}
	return 0;
}

 

 类似资料:

相关阅读

相关文章

相关问答