Construct the String CodeForces 1335B

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[lr]s[l…r] is the string sl,sl+1,,srsl,sl+1,…,sr and its length is rl+1r−l+1. In this problem you are only interestd in substrings of length aa.

Input

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

The only line of a test case contains three space-separated integers nn, aa and bb (1an2000,1bmin(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 (n2000∑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
4
7 5 3
6 1 1
6 6 1
5 2 2
Output
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.
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll inf = 1e18;
const int mod = 1000000007;
const int mx = 100; //check the limits, dummy
typedef pair<int, int> pa;
const double PI = acos(-1);
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
#define swa(a,b) a^=b^=a^=b
#define re(i,a,b) for(int i=(a),_=(b);i<_;i++)
#define rb(i,a,b) for(int i=(b),_=(a);i>=_;i--)
#define clr(a) memset(a, 0, sizeof(a))
#define lowbit(x) ((x)&(x-1))
#define mkp make_pair
void sc(int& x) { scanf("%d", &x); }void sc(int64_t& x) { scanf("%lld", &x); }void sc(double& x) { scanf("%lf", &x); }void sc(char& x) { scanf(" %c", &x); }void sc(char* x) { scanf("%s", x); }
ll  m, n,t,x,k,ans=0,sum=0;
ll a, b;
char s[mx];
int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> t;

    while (t--) {
        
        cin >> n>>a>>b;
        string s(a, ' ');
        re(i, 0, a)s[i] = (char)('a' + i % b);
        re(i, 0, n)cout << s[i%a]; cout << endl;
    }
}
原文地址:https://www.cnblogs.com/xxxsans/p/12695820.html