 A. Uniform String

2018-12-19 00:36:03

# 题目链接：

https://codeforces.com/contest/1092/problem/A

# 原题：

Problem Statement

You are given two integers n and k.

Your task is to construct such a string s of length n that for each i from 1 to k there is at least one i-th letter of the Latin alphabet in this string (the first letter is 'a', the second is 'b' and so on) and there are no other letters except these. You have to maximize the minimal frequency of some letter (the frequency of a letter is the number of occurrences of this letter in a string). If there are several possible answers, you can print any.

You have to answer t independent queries.

Input

The first line of the input contains one integer t (1≤t≤100) — the number of queries.

The next t lines are contain queries, one per line. The i-th line contains two integers ni and ki (1≤ni≤100,1≤ki≤min(ni,26)) — the length of the string in the i-th query and the number of characters in the i-th query.

Output

Print t lines. In the i-th line print the answer to the i-th query: any string si satisfying the conditions in the problem statement with constraints from the i-th query.

Examples

input

3
7 3
4 4
6 2

output

cbcacab
abcd
baabab

Note

In the first example query the maximum possible minimal frequency is 2, it can be easily seen that the better answer doesn't exist. Other examples of correct answers: "cbcabba", "ccbbaaa" (any permutation of given answers is also correct).

In the second example query any permutation of first four letters is acceptable (the maximum minimal frequency is 1).

In the third example query any permutation of the given answer is acceptable (the maximum minimal frequency is 3).

# AC代码：

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
typedef long long ll;
#include<vector>
#define cin(n) scanf("%lld",&(n))
#define cout(n) printf("%lld",(n))
#define couc(c) printf("%c",(c))
#define coutn printf("\n")
#define cout_ printf(" ")
#define debug() printf("haha\n")
ll t,n,k;
int main()
{
cin(t);
while(t--)
{
cin(n);
cin(k);
ll len=0;
if(n%k)
len=n-n/k*k+n/k;
else
len=n/k;
for(int i=1;i<=len;i++)
printf("%c",k+'a'-1);
ll num=n/k;
for(k=k-1;k;k--)
{
for(int i=1;i<=num;i++)
printf("%c",k+'a'-1);
}
printf("\n");
}
return 0;
}

• star
首页