Algorithm


B. Construct the String
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given three positive integers na and b. You have to construct a string s of length n consisting of lowercase Latin letters such that each substring of length a has exactly b distinct letters. It is guaranteed that the answer exists.

You have to answer t independent test cases.

Recall that the substring s[lr]�[�…�] is the string sl,sl+1,,sr��,��+1,…,�� and its length is rl+1�−�+1. In this problem you are only interested in substrings of length a.

Input

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

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

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

Output

For each test case, print the answer — such a string s of length n consisting of lowercase Latin letters that each substring of length a has exactly b 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.

 



 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include<bits/stdc++.h>
using namespace std;


#define ll long long
#define endl '\n'
#define debug(n) cout<<(n)<<endl;
const ll INF = 2e18 + 99;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int t;
  cin>>t;
  while(t--){
    int n, a, b;
    cin>>n>>a>>b;
    string s = "";
    char c = 'a';
    for(int i = 0; i < n; i++){
      if(i % b == 0){
        c = 'a';
      }
      s += c;
      c = char(c + 1);
    }
    cout<<s<<endl;
  }

}
Copy The Code & Try With Live Editor

Input

x
+
cmd
4
7 5 3
6 1 1
6 6 1
5 2 2

Output

x
+
cmd
tleelte
qwerty
vvvvvv
abcde
Advertisements

Demonstration


Codeforcess solution 1335-B B. Construct the String,  ,C++, Java, Js and Python, 1335-B, Codeforcess solution

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+