#include <bits/stdc++.h>

using namespace std;
const int Nmax=1e3+7;
int h[Nmax];
int l[Nmax],r[Nmax];
int main()
{
   // freopen("a.inp","r",stdin);
//    freopen("a.out","w",stdout);
    int n,m,d,s=0;
    cin>>n>>m>>d;
    int id=0,dem=0;
    for (int i=1; i<=m; i++)
    {
        cin>>h[i];
        s=s+h[i];
    }
    if (s+m*(d-1)<n)
        cout<<"NO";
    else
    {
        cout<<"YES"<<"\n";
        while (n>0)
        {
            int man=min(n-s+1,d);
            id++;s=s-h[id];
            n=n-man-h[id]+1;
            l[id]=dem+man;
            r[id]=dem+man+h[id]-1;
            dem=dem+man+h[id]-1;
        }
    }
    int id1=1;
    for (int i=1;i<=dem;i++)
    {
        if (i<l[id1]) cout<<"0"<<" ";
        else
        if (i==r[id1])
        {
            cout<<id1<<" ";
            id1++;
        }
        else cout<<id1<<" ";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define lld long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define akarsh_singhal ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main()
{

    akarsh_singhal
    ll n, m, a,k, b,d, c, x, sum=0,t;
    ll l, r;
    cin>>n>>m>>d;
    int arr[m];
    for(int i=0;i<m;i++){
        cin>>arr[i];
        sum+=arr[i];
    }
   // cout<<sum<<endl;
    if(sum+(m+1)*d<n)
    {
        cout<<"NO";
        exit(0);
    }
    cout<<"YES"<<endl;
    a=n-sum;
    int ar[n];
    b=-1;
    memset(ar, 0, sizeof(ar));
    ll bb=1;
    a=max(bb,a);
    for(int i=1;i<=m;i++){
        int j;
        for(j=b+min(d,a);j<b+min(d,a)+arr[i-1];j++)
            ar[j]=i;
        a-=min(d-1, a);
        a=max(bb,a);
        b=j-1;
    }
    for(int i=0;i<n;i++) cout<<ar[i]<<" ";

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define lld long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define akarsh_singhal ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main()
{

    akarsh_singhal
    ll n, m, a,k, b,d, c, x, sum=0,t;
    ll l, r;
    cin>>n>>m>>d;
    int arr[m];
    for(int i=0;i<m;i++){
        cin>>arr[i];
        sum+=arr[i];
    }
   // cout<<sum<<endl;
    if(sum*d<n)
    {
        cout<<"NO";
        exit(0);
    }
    cout<<"YES"<<endl;
    a=n-sum;
    int ar[n];
    b=-1;
    memset(ar, 0, sizeof(ar));
    for(int i=1;i<=m;i++){
        int j;
        for(j=b+min(d,a);j<b+min(d,a)+arr[i-1];j++)
            ar[j]=i;
        a-=min(d-1, a);
        b=j-1;
    }
    for(int i=0;i<n;i++) cout<<ar[i]<<" ";

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define lld long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define akarsh_singhal ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main()
{

    akarsh_singhal
    ll n, m, a,k, b,d, c, x, sum=0,t;
    ll l, r;
    cin>>n>>m>>d;
    int arr[m];
    for(int i=0;i<m;i++){
        cin>>arr[i];
        sum+=arr[i];
    }
   // cout<<sum<<endl;
    if(sum+(m+1)*d<=n+1)
    {
        cout<<"NO";
        exit(0);
    }
    cout<<"YES"<<endl;
    a=n-sum;
    int ar[n];
    b=-1;
    memset(ar, 0, sizeof(ar));
    ll bb=1;
    for(int i=1;i<=m;i++){
        int j;
        for(j=b+min(d,a);j<b+min(d,a)+arr[i-1];j++)
            ar[j]=i;
        a-=min(d-1, a);
        a=max(bb,a);
        b=j-1;
    }
    for(int i=0;i<n;i++) cout<<ar[i]<<" ";

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define lld long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define akarsh_singhal ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main()
{

    akarsh_singhal
    ll n, m, a,k, b,d, c, x, sum=0,t;
    ll l, r;
    cin>>n>>m>>d;
    int arr[m];
    for(int i=0;i<m;i++){
        cin>>arr[i];
        sum+=arr[i];
    }
   // cout<<sum<<endl;
    if(sum+(m+1)*d<n)
    {
        cout<<"NO";
        exit(0);
    }
    cout<<"YES"<<endl;
    a=n-sum;
    int ar[n];
    b=-1;
    memset(ar, 0, sizeof(ar));
    ll bb=1;
    for(int i=1;i<=m;i++){
        int j;
        for(j=b+min(d,a);j<b+min(d,a)+arr[i-1];j++)
            ar[j]=i;
        a-=min(d-1, a);
        a=max(bb,a);
        b=j-1;
    }
    for(int i=0;i<n;i++) cout<<ar[i]<<" ";

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define lld long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define akarsh_singhal ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main()
{

    akarsh_singhal
    ll n, m, a,k, b,d, c, x, sum=0,t;
    ll l, r;
    cin>>n>>m>>d;
    int arr[m];
    for(int i=0;i<m;i++){
        cin>>arr[i];
        sum+=arr[i];
    }
   // cout<<sum<<endl;
    if(sum+(m+1)*d<=n+1)
    {
        cout<<"NO";
        exit(0);
    }
    cout<<"YES"<<endl;
    a=n-sum;
    int ar[n];
    b=-1;
    memset(ar, 0, sizeof(ar));
    ll bb=1;
    a=max(bb,a);
    for(int i=1;i<=m;i++){
        int j;
        for(j=b+min(d,a);j<b+min(d,a)+arr[i-1];j++)
            ar[j]=i;
        a-=min(d-1, a);
        a=max(bb,a);
        b=j-1;
    }
    for(int i=0;i<n;i++) cout<<ar[i]<<" ";

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define lld long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define akarsh_singhal ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main()
{

    akarsh_singhal
    ll n, m, a,k, b,d, c, x, sum=0,t;
    ll l, r;
    cin>>n>>m>>d;
    int arr[m];
    for(int i=0;i<m;i++){
        cin>>arr[i];
        sum+=arr[i];
    }
   // cout<<sum<<endl;
    if(sum*d<n)
    {
        cout<<"NO";
        exit(0);
    }
    cout<<"YES"<<endl;
    a=n-sum;
    int ar[n];
    b=-1;
    memset(ar, 0, sizeof(ar));
    ll bb=1;
    for(int i=1;i<=m;i++){
        int j;
        for(j=b+min(d,a);j<b+min(d,a)+arr[i-1];j++)
            ar[j]=i;
        a-=min(d-1, a);
        a=max(bb,a);
        b=j-1;
    }
    for(int i=0;i<n;i++) cout<<ar[i]<<" ";

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define lld long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define akarsh_singhal ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main()
{

    akarsh_singhal
    ll n, m, a,k, b,d, c, x, sum=0,t;
    ll l, r;
    cin>>n>>m>>d;
    int arr[m];
    for(int i=0;i<m;i++){
        cin>>arr[i];
        sum+=arr[i];
    }
   // cout<<sum<<endl;
    if(sum+(m+1)*(d-1)-n<0)
    {
        cout<<"NO";
        exit(0);
    }
    cout<<"YES"<<endl;
    a=n-sum;
    int ar[n];
    b=-1;
    memset(ar, 0, sizeof(ar));
    ll bb=1;
    a=max(bb,a);
    for(int i=1;i<=m;i++){
        int j;
        for(j=b+min(d,a);j<b+min(d,a)+arr[i-1];j++)
            ar[j]=i;
        a-=min(d-1, a);
        a=max(bb,a);
        b=j-1;
    }
    for(int i=0;i<n;i++) cout<<ar[i]<<" ";

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define lld long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define akarsh_singhal ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main()
{

    akarsh_singhal
    ll n, m, a,k, b,d, c, x, sum=0,t;
    ll l, r;
    cin>>n>>m>>d;
    int arr[m];
    for(int i=0;i<m;i++){
        cin>>arr[i];
        sum+=arr[i];
    }
    if(sum*d<n)
    {
        cout<<"NO";
        exit(0);
    }
    cout<<"YES"<<endl;
    a=n-sum;
    int ar[n];
    b=-1;
    memset(ar, 0, sizeof(ar));
    for(int i=1;i<=m;i++){
        int j;
        for(j=b+min(d,a);j<b+min(d,a)+arr[i-1];j++)
            ar[j]=i;
        a-=d-1;
        b=j-1;
    }
    for(int i=0;i<n;i++) cout<<ar[i]<<" ";

}


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

typedef long long ll;

#define FOR(i, s, n) for (int i = (s); i < (n); ++i)
#define FORALL(i, n) for (int i = 0; i < (n); ++i)
#define MOD 1000000007
#define pll pair<long long, long long>
#define pii pair<int, int>
#define fast ios_base::sync_with_stdio(false)
#define countbits(x) __builtin_popcount(x)
#define pb(x) push_back(x)
#define vi vector<int>
#define vll vector<ll>

template <typename T>
T extGcd(T a, T b, T &x, T &y)
{
    if (b == 0)
    {
        x = 1;
        y = 0;
        return a;
    }
    else
    {
        int g = extGcd(b, a % b, y, x);
        y -= a / b * x;
        return g;
    }
}

template <typename T>
T modInv(T a, T m)
{
    T x, y;
    extGcd(a, m, x, y);
    return (x % m + m) % m;
}

// long long lcm(long long a, long long b){
//     return a*(b/_gcd(a,b)); // to prevent overflow
// }
/*
factorial calculation
long long fac[n+1];
fac[0] = fac[1] = 1;
for(int i = 1; i < n+1;i++){
    fac[i] = i*fac[i-1];
}
*/

vll Linearseive(ll n)
{
    vector<bool> v(n + 1, true);
    vll primes;
    for (ll i = 2; i <= n; i++)
    {
        if (v[i])
        {
            primes.pb(i);
        }
        for (int j = 0; j < primes.size() && i * primes[j] < n; j++)
        {

            v[i * primes[j]] = false;

            if (i % primes[j] == 0)
            {
                break;
            }
        }
    }
    return primes;
}

//number of prime factors
ll numPF(ll N) {

    vll primes = Linearseive(N);
    ll PF_idx = 0, PF = primes[PF_idx], ans = 0;
    while (PF * PF <= N) {
        while (N % PF == 0) { N /= PF; ans++; }
            PF = primes[++PF_idx];
        }
    if (N != 1) ans++;
    return ans;
}

ll numDiv(ll N){

    vll primes = Linearseive(N);
    ll PF_idx = 0, PF = primes[PF_idx], ans = 1; // start from ans = 1

    while (PF * PF <= N) {
        ll power = 0;   // count the power

        while (N % PF == 0)
            { N /= PF; power++; }

            ans *= (power + 1);     // according to the formula
            PF = primes[++PF_idx];
        }

        if (N != 1) ans *= 2;   // (last factor has pow = 1, we add 1 to it)

        return ans;
}

ll sumDiv(ll N) {

    vll primes = Linearseive(N);

    ll PF_idx = 0, PF = primes[PF_idx], ans = 1;    // start from ans = 1

    while (PF * PF <= N) {
        ll power = 0;
        while (N % PF == 0)
            { N /= PF; power++; }

        ans *= ((ll)pow((double)PF, power + 1.0) - 1) / (PF - 1);
        PF = primes[++PF_idx];
        }

    if (N != 1) ans *= ((ll)pow((double)N, 2.0) - 1) / (N - 1); // last
    return ans;
}

void linearDiph(ll a, ll b, ll p, ll&x , ll &y){

    ll gcd_a_b = extGcd(a,b,x,y);

    x*=(p/gcd_a_b);
    y*=(p/gcd_a_b);

    //found initial values of x and y

    if(x<0 or y<0){
      ll nx=0,ny=0;
      //nx = x + (y/gcd_a_b)*n
      //-1*x/(y)
      ll i = ceil(-1*((double)x)/((double)b/(double)gcd_a_b));
      ll j = floor(((double)y)/((double)a/(double)gcd_a_b));
      // cout<<i<<' '<<j<<endl;
      for(;i<=j;i++){
        // cout<<"Before: "<<nx<<' '<<ny<<endl;
        nx = x + b*i;
        ny = y - a*i;
        // cout<<"After: "<<nx<<' '<<ny<<endl;

        if(nx>=0 and ny>=0){
          x= nx;
          y = ny;
          return;
        }
      }
      x = -1;
      y = -1;
    }
  return;
}

class Graph
{
    int V;
    list<int> *adj;

public:
    Graph(int V);
    void addEdge(int v, int w);

    int solve(int u, int sum, int[]);
};

int Graph::solve(int u, int sum, int w[])
{
    if (!w[u])
    {
        sum = sum * 10 + 1;
    }
    else
        sum *= 10;
    int ans = sum;
    int j = 0;
    for (auto i : this->adj[u])
    {
        if (j == 0)
            ans = solve(i, sum, w), j++;
        ans = min(ans, solve(i, sum, w));
    }
    return ans;
}

Graph::Graph(int V)
{
    this->V = V;
    this->adj = new list<int>[V];
}
void Graph::addEdge(int v, int w)
{
    adj[v].push_back(w);
    adj[w].push_back(v);
}

void solve(){
int n;
cin>>n;
vector<int> v(n*2);
FORALL(i,2*n){
	cin>>v[i];
}

sort(v.begin(), v.end());

vector<int> x(n);
vector<int> y(n);
for(int i=0;i<n;i++){
	x[i] = v[i];
}
for(int i=n;i<2*n;i++){
	y[i] = v[i];
}

}

bool solve(int d, vi c, vi &ans){

    int n = ans.size();
    int m = c.size();

    int k = m-1;
    int x;

    vi back;
    vi front;
    int j = n-1;

    for(int i = m-1;i>=0;i--){
        x=c[i];
            back.push_back(j);
        while(x--){
            ans[j] = i+1;
            j--;
        }
        front.push_back(j+1);
    }

    x= front[front.size()-1];

    if(x+1<=d ) return true;
    else{
        int diff = x + 1 - d;
        for(int i=back.size()-1;i>=0;i--){
            front[i]-=diff;
            back[i]-=diff;

            if(i>0) {
                if(front[i-1]<=back[i]+d)
                    break;
                else{
                    diff = front[i-1] - back[i] - d;
                }
            }
            else{
                if((back[i] + 1 + d ) < (n+1))
                return false;
            }
        }
/*
0...1 2 3 4 5 6 7.....8
    0 0 1 2 2 3 0
    0 1 2 2 0 3 0
*/

        FORALL(i,n) ans[i] = 0;
        for(int i=0;i<m;i++){
            for(int j = front[i]; j <=back[i] ; j++){
                ans[j] = m - i;
            }
        }
        return true;
    }
}

int main()
{
    fast;

    int n,m,d;
    cin>>n>>m>>d;

    vi c(m);
    FORALL(i,m){
        cin>>c[i];
    }

    vi ans(n,0);
    bool back = solve(d,c,ans);

    if(back){
        cout<<"YES"<<endl;
        FORALL(i,n){
            cout<<ans[i]<<' ';
        }
        cout<<endl;
    }
    else cout<<"NO"<<endl;
    return 0;
}


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

typedef long long ll;

#define FOR(i, s, n) for (int i = (s); i < (n); ++i)
#define FORALL(i, n) for (int i = 0; i < (n); ++i)
#define MOD 1000000007
#define pll pair<long long, long long>
#define pii pair<int, int>
#define fast ios_base::sync_with_stdio(false)
#define countbits(x) __builtin_popcount(x)
#define pb(x) push_back(x)
#define vi vector<int>
#define vll vector<ll>

template <typename T>
T extGcd(T a, T b, T &x, T &y)
{
    if (b == 0)
    {
        x = 1;
        y = 0;
        return a;
    }
    else
    {
        int g = extGcd(b, a % b, y, x);
        y -= a / b * x;
        return g;
    }
}

template <typename T>
T modInv(T a, T m)
{
    T x, y;
    extGcd(a, m, x, y);
    return (x % m + m) % m;
}

// long long lcm(long long a, long long b){
//     return a*(b/_gcd(a,b)); // to prevent overflow
// }
/*
factorial calculation
long long fac[n+1];
fac[0] = fac[1] = 1;
for(int i = 1; i < n+1;i++){
    fac[i] = i*fac[i-1];
}
*/

vll Linearseive(ll n)
{
    vector<bool> v(n + 1, true);
    vll primes;
    for (ll i = 2; i <= n; i++)
    {
        if (v[i])
        {
            primes.pb(i);
        }
        for (int j = 0; j < primes.size() && i * primes[j] < n; j++)
        {

            v[i * primes[j]] = false;

            if (i % primes[j] == 0)
            {
                break;
            }
        }
    }
    return primes;
}

//number of prime factors
ll numPF(ll N) {

    vll primes = Linearseive(N);
    ll PF_idx = 0, PF = primes[PF_idx], ans = 0;
    while (PF * PF <= N) {
        while (N % PF == 0) { N /= PF; ans++; }
            PF = primes[++PF_idx];
        }
    if (N != 1) ans++;
    return ans;
}

ll numDiv(ll N){

    vll primes = Linearseive(N);
    ll PF_idx = 0, PF = primes[PF_idx], ans = 1; // start from ans = 1

    while (PF * PF <= N) {
        ll power = 0;   // count the power

        while (N % PF == 0)
            { N /= PF; power++; }

            ans *= (power + 1);     // according to the formula
            PF = primes[++PF_idx];
        }

        if (N != 1) ans *= 2;   // (last factor has pow = 1, we add 1 to it)

        return ans;
}

ll sumDiv(ll N) {

    vll primes = Linearseive(N);

    ll PF_idx = 0, PF = primes[PF_idx], ans = 1;    // start from ans = 1

    while (PF * PF <= N) {
        ll power = 0;
        while (N % PF == 0)
            { N /= PF; power++; }

        ans *= ((ll)pow((double)PF, power + 1.0) - 1) / (PF - 1);
        PF = primes[++PF_idx];
        }

    if (N != 1) ans *= ((ll)pow((double)N, 2.0) - 1) / (N - 1); // last
    return ans;
}

void linearDiph(ll a, ll b, ll p, ll&x , ll &y){

    ll gcd_a_b = extGcd(a,b,x,y);

    x*=(p/gcd_a_b);
    y*=(p/gcd_a_b);

    //found initial values of x and y

    if(x<0 or y<0){
      ll nx=0,ny=0;
      //nx = x + (y/gcd_a_b)*n
      //-1*x/(y)
      ll i = ceil(-1*((double)x)/((double)b/(double)gcd_a_b));
      ll j = floor(((double)y)/((double)a/(double)gcd_a_b));
      // cout<<i<<' '<<j<<endl;
      for(;i<=j;i++){
        // cout<<"Before: "<<nx<<' '<<ny<<endl;
        nx = x + b*i;
        ny = y - a*i;
        // cout<<"After: "<<nx<<' '<<ny<<endl;

        if(nx>=0 and ny>=0){
          x= nx;
          y = ny;
          return;
        }
      }
      x = -1;
      y = -1;
    }
  return;
}

class Graph
{
    int V;
    list<int> *adj;

public:
    Graph(int V);
    void addEdge(int v, int w);

    int solve(int u, int sum, int[]);
};

int Graph::solve(int u, int sum, int w[])
{
    if (!w[u])
    {
        sum = sum * 10 + 1;
    }
    else
        sum *= 10;
    int ans = sum;
    int j = 0;
    for (auto i : this->adj[u])
    {
        if (j == 0)
            ans = solve(i, sum, w), j++;
        ans = min(ans, solve(i, sum, w));
    }
    return ans;
}

Graph::Graph(int V)
{
    this->V = V;
    this->adj = new list<int>[V];
}
void Graph::addEdge(int v, int w)
{
    adj[v].push_back(w);
    adj[w].push_back(v);
}

void solve(){
int n;
cin>>n;
vector<int> v(n*2);
FORALL(i,2*n){
	cin>>v[i];
}

sort(v.begin(), v.end());

vector<int> x(n);
vector<int> y(n);
for(int i=0;i<n;i++){
	x[i] = v[i];
}
for(int i=n;i<2*n;i++){
	y[i] = v[i];
}

}

bool solve(int current, int index, int d, vi c, vi &ans)
{
    int m = c.size();
    if(index==m){
        int n = ans.size();
        // cout<<"n+1 > current " << n+1<<' '<<current<<endl;
        // cout<<"n+1 <= current + d  " << n+1 <<' '<<current+d + c[m-1]<<endl;
        if(n+1 > (current /*1 + c[m-1] */) and n+1 <= (current+ c[m-1]+ d)) return true;
        else return false;
    }

    bool res = false;
    int cur;
    if(current==-1) cur = current;
    else cur = current - 1 + c[index-1];
    FOR(i,1,d+1){
        // cout<<cur+i<<endl;
        res |= solve(cur+i, index+1,d,c,ans);
        if(res){
            FOR(j,cur+i,cur+i+c[index]){
                ans[j] = index+1;
            }
            return true;
        }
    }
    return false;
}

int main()
{
    fast;

    int n,m,d;
    cin>>n>>m>>d;

    vi c(m);
    FORALL(i,m){
        cin>>c[i];
    }

    vi ans(n,0);
    int cur = -1;
    int index = 0;
    bool res = solve(cur,index,d,c,ans);

    if(res){
        cout<<"YES"<<endl;
        FORALL(i,n){
            cout<<ans[i]<<' ';
        }
        cout<<endl;
    }
    else cout<<"NO"<<endl;
    return 0;
}


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

typedef long long ll;

#define FOR(i, s, n) for (int i = (s); i < (n); ++i)
#define FORALL(i, n) for (int i = 0; i < (n); ++i)
#define MOD 1000000007
#define pll pair<long long, long long>
#define pii pair<int, int>
#define fast ios_base::sync_with_stdio(false)
#define countbits(x) __builtin_popcount(x)
#define pb(x) push_back(x)
#define vi vector<int>
#define vll vector<ll>

template <typename T>
T extGcd(T a, T b, T &x, T &y)
{
    if (b == 0)
    {
        x = 1;
        y = 0;
        return a;
    }
    else
    {
        int g = extGcd(b, a % b, y, x);
        y -= a / b * x;
        return g;
    }
}

template <typename T>
T modInv(T a, T m)
{
    T x, y;
    extGcd(a, m, x, y);
    return (x % m + m) % m;
}

// long long lcm(long long a, long long b){
//     return a*(b/_gcd(a,b)); // to prevent overflow
// }
/*
factorial calculation
long long fac[n+1];
fac[0] = fac[1] = 1;
for(int i = 1; i < n+1;i++){
    fac[i] = i*fac[i-1];
}
*/

vll Linearseive(ll n)
{
    vector<bool> v(n + 1, true);
    vll primes;
    for (ll i = 2; i <= n; i++)
    {
        if (v[i])
        {
            primes.pb(i);
        }
        for (int j = 0; j < primes.size() && i * primes[j] < n; j++)
        {

            v[i * primes[j]] = false;

            if (i % primes[j] == 0)
            {
                break;
            }
        }
    }
    return primes;
}

//number of prime factors
ll numPF(ll N) {

    vll primes = Linearseive(N);
    ll PF_idx = 0, PF = primes[PF_idx], ans = 0;
    while (PF * PF <= N) {
        while (N % PF == 0) { N /= PF; ans++; }
            PF = primes[++PF_idx];
        }
    if (N != 1) ans++;
    return ans;
}

ll numDiv(ll N){

    vll primes = Linearseive(N);
    ll PF_idx = 0, PF = primes[PF_idx], ans = 1; // start from ans = 1

    while (PF * PF <= N) {
        ll power = 0;   // count the power

        while (N % PF == 0)
            { N /= PF; power++; }

            ans *= (power + 1);     // according to the formula
            PF = primes[++PF_idx];
        }

        if (N != 1) ans *= 2;   // (last factor has pow = 1, we add 1 to it)

        return ans;
}

ll sumDiv(ll N) {

    vll primes = Linearseive(N);

    ll PF_idx = 0, PF = primes[PF_idx], ans = 1;    // start from ans = 1

    while (PF * PF <= N) {
        ll power = 0;
        while (N % PF == 0)
            { N /= PF; power++; }

        ans *= ((ll)pow((double)PF, power + 1.0) - 1) / (PF - 1);
        PF = primes[++PF_idx];
        }

    if (N != 1) ans *= ((ll)pow((double)N, 2.0) - 1) / (N - 1); // last
    return ans;
}

void linearDiph(ll a, ll b, ll p, ll&x , ll &y){

    ll gcd_a_b = extGcd(a,b,x,y);

    x*=(p/gcd_a_b);
    y*=(p/gcd_a_b);

    //found initial values of x and y

    if(x<0 or y<0){
      ll nx=0,ny=0;
      //nx = x + (y/gcd_a_b)*n
      //-1*x/(y)
      ll i = ceil(-1*((double)x)/((double)b/(double)gcd_a_b));
      ll j = floor(((double)y)/((double)a/(double)gcd_a_b));
      // cout<<i<<' '<<j<<endl;
      for(;i<=j;i++){
        // cout<<"Before: "<<nx<<' '<<ny<<endl;
        nx = x + b*i;
        ny = y - a*i;
        // cout<<"After: "<<nx<<' '<<ny<<endl;

        if(nx>=0 and ny>=0){
          x= nx;
          y = ny;
          return;
        }
      }
      x = -1;
      y = -1;
    }
  return;
}

class Graph
{
    int V;
    list<int> *adj;

public:
    Graph(int V);
    void addEdge(int v, int w);

    int solve(int u, int sum, int[]);
};

int Graph::solve(int u, int sum, int w[])
{
    if (!w[u])
    {
        sum = sum * 10 + 1;
    }
    else
        sum *= 10;
    int ans = sum;
    int j = 0;
    for (auto i : this->adj[u])
    {
        if (j == 0)
            ans = solve(i, sum, w), j++;
        ans = min(ans, solve(i, sum, w));
    }
    return ans;
}

Graph::Graph(int V)
{
    this->V = V;
    this->adj = new list<int>[V];
}
void Graph::addEdge(int v, int w)
{
    adj[v].push_back(w);
    adj[w].push_back(v);
}

void solve(){
int n;
cin>>n;
vector<int> v(n*2);
FORALL(i,2*n){
	cin>>v[i];
}

sort(v.begin(), v.end());

vector<int> x(n);
vector<int> y(n);
for(int i=0;i<n;i++){
	x[i] = v[i];
}
for(int i=n;i<2*n;i++){
	y[i] = v[i];
}

}

bool solve(int d, vi c, vi &ans){

    int n = ans.size();
    int m = c.size();

    int k = m-1;
    int x;

    vi back;
    vi front;
    int j = n-1;

    for(int i = m-1;i>=0;i--){
        x=c[i];
            back.push_back(j);
        while(x--){
            ans[j] = i+1;
            j--;
        }
        front.push_back(j+1);
    }

    x= front[front.size()-1];

    if(x+1<=d ) return true;
    else{
        int diff = x + 1 - d;
        for(int i=back.size()-1;i>=0;i--){
            front[i]-=diff;
            back[i]-=diff;

            if(i>0) {
                if(front[i-1]<=back[i]+d)
                    break;
                else{
                    diff = front[i-1] - back[i] - d;
                }
            }
            else{
                if((back[i] + 1 + c[m-1]+d ) < (n+1))
                return false;
            }
        }
/*
0...1 2 3 4 5 6 7.....8
    0 0 1 2 2 3 0
    0 1 2 2 0 3 0
*/

        FORALL(i,n) ans[i] = 0;
        for(int i=0;i<m;i++){
            for(int j = front[i]; j <=back[i] ; j++){
                ans[j] = m - i;
            }
        }
        return true;
    }
}

int main()
{
    fast;

    int n,m,d;
    cin>>n>>m>>d;

    vi c(m);
    FORALL(i,m){
        cin>>c[i];
    }

    vi ans(n,0);
    bool back = solve(d,c,ans);

    if(back){
        cout<<"YES"<<endl;
        FORALL(i,n){
            cout<<ans[i]<<' ';
        }
        cout<<endl;
    }
    else cout<<"NO"<<endl;
    return 0;
}


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

typedef long long ll;

#define FOR(i, s, n) for (int i = (s); i < (n); ++i)
#define FORALL(i, n) for (int i = 0; i < (n); ++i)
#define MOD 1000000007
#define pll pair<long long, long long>
#define pii pair<int, int>
#define fast ios_base::sync_with_stdio(false)
#define countbits(x) __builtin_popcount(x)
#define pb(x) push_back(x)
#define vi vector<int>
#define vll vector<ll>

template <typename T>
T extGcd(T a, T b, T &x, T &y)
{
    if (b == 0)
    {
        x = 1;
        y = 0;
        return a;
    }
    else
    {
        int g = extGcd(b, a % b, y, x);
        y -= a / b * x;
        return g;
    }
}

template <typename T>
T modInv(T a, T m)
{
    T x, y;
    extGcd(a, m, x, y);
    return (x % m + m) % m;
}

// long long lcm(long long a, long long b){
//     return a*(b/_gcd(a,b)); // to prevent overflow
// }
/*
factorial calculation
long long fac[n+1];
fac[0] = fac[1] = 1;
for(int i = 1; i < n+1;i++){
    fac[i] = i*fac[i-1];
}
*/

vll Linearseive(ll n)
{
    vector<bool> v(n + 1, true);
    vll primes;
    for (ll i = 2; i <= n; i++)
    {
        if (v[i])
        {
            primes.pb(i);
        }
        for (int j = 0; j < primes.size() && i * primes[j] < n; j++)
        {

            v[i * primes[j]] = false;

            if (i % primes[j] == 0)
            {
                break;
            }
        }
    }
    return primes;
}

//number of prime factors
ll numPF(ll N) {

    vll primes = Linearseive(N);
    ll PF_idx = 0, PF = primes[PF_idx], ans = 0;
    while (PF * PF <= N) {
        while (N % PF == 0) { N /= PF; ans++; }
            PF = primes[++PF_idx];
        }
    if (N != 1) ans++;
    return ans;
}

ll numDiv(ll N){

    vll primes = Linearseive(N);
    ll PF_idx = 0, PF = primes[PF_idx], ans = 1; // start from ans = 1

    while (PF * PF <= N) {
        ll power = 0;   // count the power

        while (N % PF == 0)
            { N /= PF; power++; }

            ans *= (power + 1);     // according to the formula
            PF = primes[++PF_idx];
        }

        if (N != 1) ans *= 2;   // (last factor has pow = 1, we add 1 to it)

        return ans;
}

ll sumDiv(ll N) {

    vll primes = Linearseive(N);

    ll PF_idx = 0, PF = primes[PF_idx], ans = 1;    // start from ans = 1

    while (PF * PF <= N) {
        ll power = 0;
        while (N % PF == 0)
            { N /= PF; power++; }

        ans *= ((ll)pow((double)PF, power + 1.0) - 1) / (PF - 1);
        PF = primes[++PF_idx];
        }

    if (N != 1) ans *= ((ll)pow((double)N, 2.0) - 1) / (N - 1); // last
    return ans;
}

void linearDiph(ll a, ll b, ll p, ll&x , ll &y){

    ll gcd_a_b = extGcd(a,b,x,y);

    x*=(p/gcd_a_b);
    y*=(p/gcd_a_b);

    //found initial values of x and y

    if(x<0 or y<0){
      ll nx=0,ny=0;
      //nx = x + (y/gcd_a_b)*n
      //-1*x/(y)
      ll i = ceil(-1*((double)x)/((double)b/(double)gcd_a_b));
      ll j = floor(((double)y)/((double)a/(double)gcd_a_b));
      // cout<<i<<' '<<j<<endl;
      for(;i<=j;i++){
        // cout<<"Before: "<<nx<<' '<<ny<<endl;
        nx = x + b*i;
        ny = y - a*i;
        // cout<<"After: "<<nx<<' '<<ny<<endl;

        if(nx>=0 and ny>=0){
          x= nx;
          y = ny;
          return;
        }
      }
      x = -1;
      y = -1;
    }
  return;
}

class Graph
{
    int V;
    list<int> *adj;

public:
    Graph(int V);
    void addEdge(int v, int w);

    int solve(int u, int sum, int[]);
};

int Graph::solve(int u, int sum, int w[])
{
    if (!w[u])
    {
        sum = sum * 10 + 1;
    }
    else
        sum *= 10;
    int ans = sum;
    int j = 0;
    for (auto i : this->adj[u])
    {
        if (j == 0)
            ans = solve(i, sum, w), j++;
        ans = min(ans, solve(i, sum, w));
    }
    return ans;
}

Graph::Graph(int V)
{
    this->V = V;
    this->adj = new list<int>[V];
}
void Graph::addEdge(int v, int w)
{
    adj[v].push_back(w);
    adj[w].push_back(v);
}

void solve(){
int n;
cin>>n;
vector<int> v(n*2);
FORALL(i,2*n){
	cin>>v[i];
}

sort(v.begin(), v.end());

vector<int> x(n);
vector<int> y(n);
for(int i=0;i<n;i++){
	x[i] = v[i];
}
for(int i=n;i<2*n;i++){
	y[i] = v[i];
}

}

bool solve(int d, vi c, vi &ans){

    int n = ans.size();
    int m = c.size();

    int k = m-1;
    int x;

    vi res;

    for(int i=n-1;i>=0 and k>=0; i--){
        x = c[k];
        res.push_back(i);
        while(x--){
            ans[i] = k+1;
            i--;
        }
        k--;
    }

    x=0;
    while(x<n){
        if(ans[x]!=0) break;
        x++;
    }
    if(x+1<=d ) return true;
    else{

        int diff = x +2- d;

        int flag = 0;
        for(int i=res.size()-1;i>=0;i--){
            res[i]-=diff;
            if(i>0) {
                if(res[i-1]+1<=d)
                    break;
                else{
                    diff = res[i-1] + 1 - d;
                }
            }
            else{
                if((res[i]+1+c[m-1]+d )< (n+1))
                return false;
            }
        }
            // for (int i = 0; i < res.size(); ++i)
            // {
            //      code
            //     cout<<res[i]<<' ';
            // }

            // cout<<endl;
        x = res.size()-1;

        int y = m;
        for(int i=0;i<n;i++){
            ans[i] = 0;
            if(x>=0 and res[x]==i){
                while(c[m-1]--){
                    ans[i] = y;
                    i++;
                }
                m--;
                x--;
                y--;
            }
        }
        return true;
    }
}

int main()
{
    fast;

    int n,m,d;
    cin>>n>>m>>d;

    vi c(m);
    FORALL(i,m){
        cin>>c[i];
    }

    vi ans(n,0);
    bool res = solve(d,c,ans);

    if(res){
        cout<<"YES"<<endl;
        FORALL(i,n){
            cout<<ans[i]<<' ';
        }
        cout<<endl;
    }
    else cout<<"NO"<<endl;
    return 0;
}


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

typedef long long ll;

#define FOR(i, s, n) for (int i = (s); i < (n); ++i)
#define FORALL(i, n) for (int i = 0; i < (n); ++i)
#define MOD 1000000007
#define pll pair<long long, long long>
#define pii pair<int, int>
#define fast ios_base::sync_with_stdio(false)
#define countbits(x) __builtin_popcount(x)
#define pb(x) push_back(x)
#define vi vector<int>
#define vll vector<ll>

template <typename T>
T extGcd(T a, T b, T &x, T &y)
{
    if (b == 0)
    {
        x = 1;
        y = 0;
        return a;
    }
    else
    {
        int g = extGcd(b, a % b, y, x);
        y -= a / b * x;
        return g;
    }
}

template <typename T>
T modInv(T a, T m)
{
    T x, y;
    extGcd(a, m, x, y);
    return (x % m + m) % m;
}

// long long lcm(long long a, long long b){
//     return a*(b/_gcd(a,b)); // to prevent overflow
// }
/*
factorial calculation
long long fac[n+1];
fac[0] = fac[1] = 1;
for(int i = 1; i < n+1;i++){
    fac[i] = i*fac[i-1];
}
*/

vll Linearseive(ll n)
{
    vector<bool> v(n + 1, true);
    vll primes;
    for (ll i = 2; i <= n; i++)
    {
        if (v[i])
        {
            primes.pb(i);
        }
        for (int j = 0; j < primes.size() && i * primes[j] < n; j++)
        {

            v[i * primes[j]] = false;

            if (i % primes[j] == 0)
            {
                break;
            }
        }
    }
    return primes;
}

//number of prime factors
ll numPF(ll N) {

    vll primes = Linearseive(N);
    ll PF_idx = 0, PF = primes[PF_idx], ans = 0;
    while (PF * PF <= N) {
        while (N % PF == 0) { N /= PF; ans++; }
            PF = primes[++PF_idx];
        }
    if (N != 1) ans++;
    return ans;
}

ll numDiv(ll N){

    vll primes = Linearseive(N);
    ll PF_idx = 0, PF = primes[PF_idx], ans = 1; // start from ans = 1

    while (PF * PF <= N) {
        ll power = 0;   // count the power

        while (N % PF == 0)
            { N /= PF; power++; }

            ans *= (power + 1);     // according to the formula
            PF = primes[++PF_idx];
        }

        if (N != 1) ans *= 2;   // (last factor has pow = 1, we add 1 to it)

        return ans;
}

ll sumDiv(ll N) {

    vll primes = Linearseive(N);

    ll PF_idx = 0, PF = primes[PF_idx], ans = 1;    // start from ans = 1

    while (PF * PF <= N) {
        ll power = 0;
        while (N % PF == 0)
            { N /= PF; power++; }

        ans *= ((ll)pow((double)PF, power + 1.0) - 1) / (PF - 1);
        PF = primes[++PF_idx];
        }

    if (N != 1) ans *= ((ll)pow((double)N, 2.0) - 1) / (N - 1); // last
    return ans;
}

void linearDiph(ll a, ll b, ll p, ll&x , ll &y){

    ll gcd_a_b = extGcd(a,b,x,y);

    x*=(p/gcd_a_b);
    y*=(p/gcd_a_b);

    //found initial values of x and y

    if(x<0 or y<0){
      ll nx=0,ny=0;
      //nx = x + (y/gcd_a_b)*n
      //-1*x/(y)
      ll i = ceil(-1*((double)x)/((double)b/(double)gcd_a_b));
      ll j = floor(((double)y)/((double)a/(double)gcd_a_b));
      // cout<<i<<' '<<j<<endl;
      for(;i<=j;i++){
        // cout<<"Before: "<<nx<<' '<<ny<<endl;
        nx = x + b*i;
        ny = y - a*i;
        // cout<<"After: "<<nx<<' '<<ny<<endl;

        if(nx>=0 and ny>=0){
          x= nx;
          y = ny;
          return;
        }
      }
      x = -1;
      y = -1;
    }
  return;
}

class Graph
{
    int V;
    list<int> *adj;

public:
    Graph(int V);
    void addEdge(int v, int w);

    int solve(int u, int sum, int[]);
};

int Graph::solve(int u, int sum, int w[])
{
    if (!w[u])
    {
        sum = sum * 10 + 1;
    }
    else
        sum *= 10;
    int ans = sum;
    int j = 0;
    for (auto i : this->adj[u])
    {
        if (j == 0)
            ans = solve(i, sum, w), j++;
        ans = min(ans, solve(i, sum, w));
    }
    return ans;
}

Graph::Graph(int V)
{
    this->V = V;
    this->adj = new list<int>[V];
}
void Graph::addEdge(int v, int w)
{
    adj[v].push_back(w);
    adj[w].push_back(v);
}

void solve(){
int n;
cin>>n;
vector<int> v(n*2);
FORALL(i,2*n){
	cin>>v[i];
}

sort(v.begin(), v.end());

vector<int> x(n);
vector<int> y(n);
for(int i=0;i<n;i++){
	x[i] = v[i];
}
for(int i=n;i<2*n;i++){
	y[i] = v[i];
}

}

bool solve(int d, vi c, vi &ans){

    int n = ans.size();
    int m = c.size();

    int k = m-1;
    int x;

    vi back;
    vi front;
    int j = n-1;

    for(int i = m-1;i>=0;i--){
        x=c[i];
            back.push_back(j);
        while(x--){
            ans[j] = i+1;
            j--;
        }
        front.push_back(j+1);
    }

    x= front[front.size()-1];

    if(x+1<=d ) return true;
    else{
        int diff = x + 1 - d;
        for(int i=back.size()-1;i>=0;i--){
            front[i]-=diff;
            back[i]-=diff;

            if(i>0) {
                if(front[i-1]<=back[i]+d)
                    break;
                else{
                    diff = front[i-1] - back[i] - d;
                }
            }
            else{
                if((back[i] + c[m-1]+d ) < (n+1))
                return false;
            }
        }
/*
0...1 2 3 4 5 6 7.....8
    0 0 1 2 2 3 0
    0 1 2 2 0 3 0
*/

        FORALL(i,n) ans[i] = 0;
        for(int i=0;i<m;i++){
            for(int j = front[i]; j <=back[i] ; j++){
                ans[j] = m - i;
            }
        }
        return true;
    }
}

int main()
{
    fast;

    int n,m,d;
    cin>>n>>m>>d;

    vi c(m);
    FORALL(i,m){
        cin>>c[i];
    }

    vi ans(n,0);
    bool back = solve(d,c,ans);

    if(back){
        cout<<"YES"<<endl;
        FORALL(i,n){
            cout<<ans[i]<<' ';
        }
        cout<<endl;
    }
    else cout<<"NO"<<endl;
    return 0;
}


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

typedef long long ll;

#define FOR(i, s, n) for (int i = (s); i < (n); ++i)
#define FORALL(i, n) for (int i = 0; i < (n); ++i)
#define MOD 1000000007
#define pll pair<long long, long long>
#define pii pair<int, int>
#define fast ios_base::sync_with_stdio(false)
#define countbits(x) __builtin_popcount(x)
#define pb(x) push_back(x)
#define vi vector<int>
#define vll vector<ll>

template <typename T>
T extGcd(T a, T b, T &x, T &y)
{
    if (b == 0)
    {
        x = 1;
        y = 0;
        return a;
    }
    else
    {
        int g = extGcd(b, a % b, y, x);
        y -= a / b * x;
        return g;
    }
}

template <typename T>
T modInv(T a, T m)
{
    T x, y;
    extGcd(a, m, x, y);
    return (x % m + m) % m;
}

// long long lcm(long long a, long long b){
//     return a*(b/_gcd(a,b)); // to prevent overflow
// }
/*
factorial calculation
long long fac[n+1];
fac[0] = fac[1] = 1;
for(int i = 1; i < n+1;i++){
    fac[i] = i*fac[i-1];
}
*/

vll Linearseive(ll n)
{
    vector<bool> v(n + 1, true);
    vll primes;
    for (ll i = 2; i <= n; i++)
    {
        if (v[i])
        {
            primes.pb(i);
        }
        for (int j = 0; j < primes.size() && i * primes[j] < n; j++)
        {

            v[i * primes[j]] = false;

            if (i % primes[j] == 0)
            {
                break;
            }
        }
    }
    return primes;
}

//number of prime factors
ll numPF(ll N) {

    vll primes = Linearseive(N);
    ll PF_idx = 0, PF = primes[PF_idx], ans = 0;
    while (PF * PF <= N) {
        while (N % PF == 0) { N /= PF; ans++; }
            PF = primes[++PF_idx];
        }
    if (N != 1) ans++;
    return ans;
}

ll numDiv(ll N){

    vll primes = Linearseive(N);
    ll PF_idx = 0, PF = primes[PF_idx], ans = 1; // start from ans = 1

    while (PF * PF <= N) {
        ll power = 0;   // count the power

        while (N % PF == 0)
            { N /= PF; power++; }

            ans *= (power + 1);     // according to the formula
            PF = primes[++PF_idx];
        }

        if (N != 1) ans *= 2;   // (last factor has pow = 1, we add 1 to it)

        return ans;
}

ll sumDiv(ll N) {

    vll primes = Linearseive(N);

    ll PF_idx = 0, PF = primes[PF_idx], ans = 1;    // start from ans = 1

    while (PF * PF <= N) {
        ll power = 0;
        while (N % PF == 0)
            { N /= PF; power++; }

        ans *= ((ll)pow((double)PF, power + 1.0) - 1) / (PF - 1);
        PF = primes[++PF_idx];
        }

    if (N != 1) ans *= ((ll)pow((double)N, 2.0) - 1) / (N - 1); // last
    return ans;
}

void linearDiph(ll a, ll b, ll p, ll&x , ll &y){

    ll gcd_a_b = extGcd(a,b,x,y);

    x*=(p/gcd_a_b);
    y*=(p/gcd_a_b);

    //found initial values of x and y

    if(x<0 or y<0){
      ll nx=0,ny=0;
      //nx = x + (y/gcd_a_b)*n
      //-1*x/(y)
      ll i = ceil(-1*((double)x)/((double)b/(double)gcd_a_b));
      ll j = floor(((double)y)/((double)a/(double)gcd_a_b));
      // cout<<i<<' '<<j<<endl;
      for(;i<=j;i++){
        // cout<<"Before: "<<nx<<' '<<ny<<endl;
        nx = x + b*i;
        ny = y - a*i;
        // cout<<"After: "<<nx<<' '<<ny<<endl;

        if(nx>=0 and ny>=0){
          x= nx;
          y = ny;
          return;
        }
      }
      x = -1;
      y = -1;
    }
  return;
}

class Graph
{
    int V;
    list<int> *adj;

public:
    Graph(int V);
    void addEdge(int v, int w);

    int solve(int u, int sum, int[]);
};

int Graph::solve(int u, int sum, int w[])
{
    if (!w[u])
    {
        sum = sum * 10 + 1;
    }
    else
        sum *= 10;
    int ans = sum;
    int j = 0;
    for (auto i : this->adj[u])
    {
        if (j == 0)
            ans = solve(i, sum, w), j++;
        ans = min(ans, solve(i, sum, w));
    }
    return ans;
}

Graph::Graph(int V)
{
    this->V = V;
    this->adj = new list<int>[V];
}
void Graph::addEdge(int v, int w)
{
    adj[v].push_back(w);
    adj[w].push_back(v);
}

void solve(){
int n;
cin>>n;
vector<int> v(n*2);
FORALL(i,2*n){
	cin>>v[i];
}

sort(v.begin(), v.end());

vector<int> x(n);
vector<int> y(n);
for(int i=0;i<n;i++){
	x[i] = v[i];
}
for(int i=n;i<2*n;i++){
	y[i] = v[i];
}

}

bool solve(int d, vi c, vi &ans){

    int n = ans.size();
    int m = c.size();

    int k = m-1;
    int x;

    vi res;

    for(int i=n-1;i>=0 and k>=0; i--){
        x = c[k];
        res.push_back(i);
        while(x--){
            ans[i] = k+1;
            i--;
        }
        k--;
    }

    x=0;
    while(x<n){
        if(ans[x]!=0) break;
        x++;
    }
    if(x+1<=d ) return true;
    else{

        int diff = x +2- d;

        int flag = 0;
        for(int i=res.size()-1;i>=0;i--){
            res[i]-=diff;
            if(i>0) {
                if(res[i-1]+1<=d)
                    break;
                else{
                    diff = res[i-1] + 1 - d;
                }
            }
            else{
                if((res[i]+c[m-1]+d )< (n+1))
                return false;
            }
        }
            // for (int i = 0; i < res.size(); ++i)
            // {
            //      code
            //     cout<<res[i]<<' ';
            // }

            // cout<<endl;
        x = res.size()-1;

        int y = m;
        for(int i=0;i<n;i++){
            ans[i] = 0;
            if(x>=0 and res[x]==i){
                while(c[m-1]--){
                    ans[i] = y;
                    i++;
                }
                m--;
                x--;
                y--;
            }
        }
        return true;
    }
}

int main()
{
    fast;

    int n,m,d;
    cin>>n>>m>>d;

    vi c(m);
    FORALL(i,m){
        cin>>c[i];
    }

    vi ans(n,0);
    bool res = solve(d,c,ans);

    if(res){
        cout<<"YES"<<endl;
        FORALL(i,n){
            cout<<ans[i]<<' ';
        }
        cout<<endl;
    }
    else cout<<"NO"<<endl;
    return 0;
}


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

typedef long long ll;

#define FOR(i, s, n) for (int i = (s); i < (n); ++i)
#define FORALL(i, n) for (int i = 0; i < (n); ++i)
#define MOD 1000000007
#define pll pair<long long, long long>
#define pii pair<int, int>
#define fast ios_base::sync_with_stdio(false)
#define countbits(x) __builtin_popcount(x)
#define pb(x) push_back(x)
#define vi vector<int>
#define vll vector<ll>

template <typename T>
T extGcd(T a, T b, T &x, T &y)
{
    if (b == 0)
    {
        x = 1;
        y = 0;
        return a;
    }
    else
    {
        int g = extGcd(b, a % b, y, x);
        y -= a / b * x;
        return g;
    }
}

template <typename T>
T modInv(T a, T m)
{
    T x, y;
    extGcd(a, m, x, y);
    return (x % m + m) % m;
}

// long long lcm(long long a, long long b){
//     return a*(b/_gcd(a,b)); // to prevent overflow
// }
/*
factorial calculation
long long fac[n+1];
fac[0] = fac[1] = 1;
for(int i = 1; i < n+1;i++){
    fac[i] = i*fac[i-1];
}
*/

vll Linearseive(ll n)
{
    vector<bool> v(n + 1, true);
    vll primes;
    for (ll i = 2; i <= n; i++)
    {
        if (v[i])
        {
            primes.pb(i);
        }
        for (int j = 0; j < primes.size() && i * primes[j] < n; j++)
        {

            v[i * primes[j]] = false;

            if (i % primes[j] == 0)
            {
                break;
            }
        }
    }
    return primes;
}

//number of prime factors
ll numPF(ll N) {

    vll primes = Linearseive(N);
    ll PF_idx = 0, PF = primes[PF_idx], ans = 0;
    while (PF * PF <= N) {
        while (N % PF == 0) { N /= PF; ans++; }
            PF = primes[++PF_idx];
        }
    if (N != 1) ans++;
    return ans;
}

ll numDiv(ll N){

    vll primes = Linearseive(N);
    ll PF_idx = 0, PF = primes[PF_idx], ans = 1; // start from ans = 1

    while (PF * PF <= N) {
        ll power = 0;   // count the power

        while (N % PF == 0)
            { N /= PF; power++; }

            ans *= (power + 1);     // according to the formula
            PF = primes[++PF_idx];
        }

        if (N != 1) ans *= 2;   // (last factor has pow = 1, we add 1 to it)

        return ans;
}

ll sumDiv(ll N) {

    vll primes = Linearseive(N);

    ll PF_idx = 0, PF = primes[PF_idx], ans = 1;    // start from ans = 1

    while (PF * PF <= N) {
        ll power = 0;
        while (N % PF == 0)
            { N /= PF; power++; }

        ans *= ((ll)pow((double)PF, power + 1.0) - 1) / (PF - 1);
        PF = primes[++PF_idx];
        }

    if (N != 1) ans *= ((ll)pow((double)N, 2.0) - 1) / (N - 1); // last
    return ans;
}

void linearDiph(ll a, ll b, ll p, ll&x , ll &y){

    ll gcd_a_b = extGcd(a,b,x,y);

    x*=(p/gcd_a_b);
    y*=(p/gcd_a_b);

    //found initial values of x and y

    if(x<0 or y<0){
      ll nx=0,ny=0;
      //nx = x + (y/gcd_a_b)*n
      //-1*x/(y)
      ll i = ceil(-1*((double)x)/((double)b/(double)gcd_a_b));
      ll j = floor(((double)y)/((double)a/(double)gcd_a_b));
      // cout<<i<<' '<<j<<endl;
      for(;i<=j;i++){
        // cout<<"Before: "<<nx<<' '<<ny<<endl;
        nx = x + b*i;
        ny = y - a*i;
        // cout<<"After: "<<nx<<' '<<ny<<endl;

        if(nx>=0 and ny>=0){
          x= nx;
          y = ny;
          return;
        }
      }
      x = -1;
      y = -1;
    }
  return;
}

class Graph
{
    int V;
    list<int> *adj;

public:
    Graph(int V);
    void addEdge(int v, int w);

    int solve(int u, int sum, int[]);
};

int Graph::solve(int u, int sum, int w[])
{
    if (!w[u])
    {
        sum = sum * 10 + 1;
    }
    else
        sum *= 10;
    int ans = sum;
    int j = 0;
    for (auto i : this->adj[u])
    {
        if (j == 0)
            ans = solve(i, sum, w), j++;
        ans = min(ans, solve(i, sum, w));
    }
    return ans;
}

Graph::Graph(int V)
{
    this->V = V;
    this->adj = new list<int>[V];
}
void Graph::addEdge(int v, int w)
{
    adj[v].push_back(w);
    adj[w].push_back(v);
}

void solve(){
int n;
cin>>n;
vector<int> v(n*2);
FORALL(i,2*n){
	cin>>v[i];
}

sort(v.begin(), v.end());

vector<int> x(n);
vector<int> y(n);
for(int i=0;i<n;i++){
	x[i] = v[i];
}
for(int i=n;i<2*n;i++){
	y[i] = v[i];
}

}

bool solve(int d, vi c, vi &ans){

    int n = ans.size();
    int m = c.size();

    int k = m-1;
    int x;

    vi res;

    for(int i=n-1;i>=0 and k>=0; i--){
        x = c[k];
        res.push_back(i);
        while(x--){
            ans[i] = k+1;
            i--;
        }
        k--;
    }

    x=0;
    while(x<n){
        if(ans[x]!=0) break;
        x++;
    }
    if(x+1<=d ) return true;
    else{

        int diff = x +2- d;

        int flag = 0;
        for(int i=res.size()-1;i>=0;i--){
            res[i]-=diff;
            if(i>0) {
                if(res[i-1]+1<=d)
                    break;
                else{
                    diff = res[i-1] + 2 - d;
                }
            }
            else{
                if((res[i]+1 + c[m-1]+d )< (n+1))
                return false;
            }
        }
            // for (int i = 0; i < res.size(); ++i)
            // {
            //      code
            //     cout<<res[i]<<' ';
            // }

            // cout<<endl;
        x = res.size()-1;

        int y = m;
        for(int i=0;i<n;i++){
            ans[i] = 0;
            if(x>=0 and res[x]==i){
                while(c[m-1]--){
                    ans[i] = y;
                    i++;
                }
                m--;
                x--;
                y--;
            }
        }
        return true;
    }
}

int main()
{
    fast;

    int n,m,d;
    cin>>n>>m>>d;

    vi c(m);
    FORALL(i,m){
        cin>>c[i];
    }

    vi ans(n,0);
    bool res = solve(d,c,ans);

    if(res){
        cout<<"YES"<<endl;
        FORALL(i,n){
            cout<<ans[i]<<' ';
        }
        cout<<endl;
    }
    else cout<<"NO"<<endl;
    return 0;
}


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

typedef long long ll;

#define FOR(i, s, n) for (int i = (s); i < (n); ++i)
#define FORALL(i, n) for (int i = 0; i < (n); ++i)
#define MOD 1000000007
#define pll pair<long long, long long>
#define pii pair<int, int>
#define fast ios_base::sync_with_stdio(false)
#define countbits(x) __builtin_popcount(x)
#define pb(x) push_back(x)
#define vi vector<int>
#define vll vector<ll>

template <typename T>
T extGcd(T a, T b, T &x, T &y)
{
    if (b == 0)
    {
        x = 1;
        y = 0;
        return a;
    }
    else
    {
        int g = extGcd(b, a % b, y, x);
        y -= a / b * x;
        return g;
    }
}

template <typename T>
T modInv(T a, T m)
{
    T x, y;
    extGcd(a, m, x, y);
    return (x % m + m) % m;
}

// long long lcm(long long a, long long b){
//     return a*(b/_gcd(a,b)); // to prevent overflow
// }
/*
factorial calculation
long long fac[n+1];
fac[0] = fac[1] = 1;
for(int i = 1; i < n+1;i++){
    fac[i] = i*fac[i-1];
}
*/

vll Linearseive(ll n)
{
    vector<bool> v(n + 1, true);
    vll primes;
    for (ll i = 2; i <= n; i++)
    {
        if (v[i])
        {
            primes.pb(i);
        }
        for (int j = 0; j < primes.size() && i * primes[j] < n; j++)
        {

            v[i * primes[j]] = false;

            if (i % primes[j] == 0)
            {
                break;
            }
        }
    }
    return primes;
}

//number of prime factors
ll numPF(ll N) {

    vll primes = Linearseive(N);
    ll PF_idx = 0, PF = primes[PF_idx], ans = 0;
    while (PF * PF <= N) {
        while (N % PF == 0) { N /= PF; ans++; }
            PF = primes[++PF_idx];
        }
    if (N != 1) ans++;
    return ans;
}

ll numDiv(ll N){

    vll primes = Linearseive(N);
    ll PF_idx = 0, PF = primes[PF_idx], ans = 1; // start from ans = 1

    while (PF * PF <= N) {
        ll power = 0;   // count the power

        while (N % PF == 0)
            { N /= PF; power++; }

            ans *= (power + 1);     // according to the formula
            PF = primes[++PF_idx];
        }

        if (N != 1) ans *= 2;   // (last factor has pow = 1, we add 1 to it)

        return ans;
}

ll sumDiv(ll N) {

    vll primes = Linearseive(N);

    ll PF_idx = 0, PF = primes[PF_idx], ans = 1;    // start from ans = 1

    while (PF * PF <= N) {
        ll power = 0;
        while (N % PF == 0)
            { N /= PF; power++; }

        ans *= ((ll)pow((double)PF, power + 1.0) - 1) / (PF - 1);
        PF = primes[++PF_idx];
        }

    if (N != 1) ans *= ((ll)pow((double)N, 2.0) - 1) / (N - 1); // last
    return ans;
}

void linearDiph(ll a, ll b, ll p, ll&x , ll &y){

    ll gcd_a_b = extGcd(a,b,x,y);

    x*=(p/gcd_a_b);
    y*=(p/gcd_a_b);

    //found initial values of x and y

    if(x<0 or y<0){
      ll nx=0,ny=0;
      //nx = x + (y/gcd_a_b)*n
      //-1*x/(y)
      ll i = ceil(-1*((double)x)/((double)b/(double)gcd_a_b));
      ll j = floor(((double)y)/((double)a/(double)gcd_a_b));
      // cout<<i<<' '<<j<<endl;
      for(;i<=j;i++){
        // cout<<"Before: "<<nx<<' '<<ny<<endl;
        nx = x + b*i;
        ny = y - a*i;
        // cout<<"After: "<<nx<<' '<<ny<<endl;

        if(nx>=0 and ny>=0){
          x= nx;
          y = ny;
          return;
        }
      }
      x = -1;
      y = -1;
    }
  return;
}

class Graph
{
    int V;
    list<int> *adj;

public:
    Graph(int V);
    void addEdge(int v, int w);

    int solve(int u, int sum, int[]);
};

int Graph::solve(int u, int sum, int w[])
{
    if (!w[u])
    {
        sum = sum * 10 + 1;
    }
    else
        sum *= 10;
    int ans = sum;
    int j = 0;
    for (auto i : this->adj[u])
    {
        if (j == 0)
            ans = solve(i, sum, w), j++;
        ans = min(ans, solve(i, sum, w));
    }
    return ans;
}

Graph::Graph(int V)
{
    this->V = V;
    this->adj = new list<int>[V];
}
void Graph::addEdge(int v, int w)
{
    adj[v].push_back(w);
    adj[w].push_back(v);
}

void solve(){
int n;
cin>>n;
vector<int> v(n*2);
FORALL(i,2*n){
	cin>>v[i];
}

sort(v.begin(), v.end());

vector<int> x(n);
vector<int> y(n);
for(int i=0;i<n;i++){
	x[i] = v[i];
}
for(int i=n;i<2*n;i++){
	y[i] = v[i];
}

}

bool solve(int current, int index, int d, vi c, vi &ans)
{
    int m = c.size();
    if(index==m){
        int n = ans.size();
        // cout<<"n+1 > current " << n+1<<' '<<current<<endl;
        // cout<<"n+1 <= current + d  " << n+1 <<' '<<current+d + c[m-1]<<endl;
        if(n+1 > (current /*1 + c[m-1] */) and n+1 <= (current+ c[m-1]+ d)) return true;
        else return false;
    }

    bool res = false;
    int cur;
    if(current==-1) cur = current;
    else cur = current - 1 + c[index-1];
    for(int i = d;i>=1;i--){
        // cout<<cur+i<<endl;
        res |= solve(cur+i, index+1,d,c,ans);
        if(res){
            FOR(j,cur+i,cur+i+c[index]){
                ans[j] = index+1;
            }
            return true;
        }
    }
    return false;
}

int main()
{
    fast;

    int n,m,d;
    cin>>n>>m>>d;

    vi c(m);
    FORALL(i,m){
        cin>>c[i];
    }

    vi ans(n,0);
    int cur = -1;
    int index = 0;
    bool res = solve(cur,index,d,c,ans);

    if(res){
        cout<<"YES"<<endl;
        FORALL(i,n){
            cout<<ans[i]<<' ';
        }
        cout<<endl;
    }
    else cout<<"NO"<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,m,d;
int a[1024];int sum;
vector<pair<int,int> >v;
int main()
{
    cin>>n>>m>>d;
    for (int i=0;i<m;i++)
    {
        cin>>a[i];sum+=a[i];
    }
    sum+=(m+1)*d;
    if (sum>=n+1)
    {
        cout<<"YES"<<endl;
        sum-=(m+1)*d;
        int diff=n+1-sum;
        for (int i=0;i<m;i++)
        {
            if (diff>=d)
            {
                if (i==0)
                {
                 //   cout<<"a";
                    v.push_back(make_pair(d,d+a[0]));
                    //v[0].first--;v[0].second--;
                    diff-=d;;
                    d--;
                }
                else
                {
                  //  cout<<"b";
                    v.push_back(make_pair(v.back().second+d,v.back().second+d+a[i]));
                    diff-=d;
                }

            }
            else
            if (diff<d)
            {
                if (i==0)
                {
                  //  cout<<"c";
                    v.push_back(make_pair(diff,diff+a[0]));
                  //  v[0].first--;v[0].second--;
                    diff=0;
                    d--;
                }
                else
                {
                  //  cout<<"d";
                    v.push_back(make_pair(diff+v.back().second,diff+v.back().second+a[i]));
                    diff=0;
                }
            }
        }
      //  cout<<endl;

        int col[1024];memset(col,0,sizeof(col));
        for (int i=0;i<m;i++)
        {
           // cout<<v[i].first<<" "<<v[i].second<<endl;
            for (int j=v[i].first;j<v[i].second;j++)
            {
                col[j]=i+1;
            }
        }
        for (int i=1;i<=n;i++)
        {
            cout<<col[i]<<" ";
        }
        cout<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,m,d;
int a[1024];int sum;
vector<pair<int,int> >v;
int main()
{
    cin>>n>>m>>d;
    for (int i=0;i<m;i++)
    {
        cin>>a[i];sum+=a[i];
    }
    sum+=(m+1)*d;
    if (sum>=n-1)
    {
        cout<<"YES"<<endl;
        sum-=(m+1)*d;
        int diff=n-1-sum;
        for (int i=0;i<m;i++)
        {
            if (diff>=d)
            {
                if (i==0)
                {
                    v.push_back(make_pair(d,d+a[0]));
                    diff-=d;;
                }
                else
                {
                    v.push_back(make_pair(v.back().second+d,v.back().second+d+a[i]));
                    diff-=d;
                }

            }
            else
            if (diff<d)
            {
                if (i==0)
                {
                    v.push_back(make_pair(diff,diff+a[0]));
                    diff=0;
                }
                else
                {
                    v.push_back(make_pair(diff+v.back().second,diff+v.back().second+a[i]));
                    diff=0;
                }
            }
        }

        int col[1024];memset(col,0,sizeof(col));
        for (int i=0;i<m;i++)
        {
         //   cout<<v[i].first<<" "<<v[i].second<<endl;
            for (int j=v[i].first;j<v[i].second;j++)
            {
                col[j]=i+1;
            }
        }
        for (int i=0;i<n;i++)
        {
            cout<<col[i]<<" ";
        }
        cout<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,m,d;
int a[1024];int sum;
vector<pair<int,int> >v;
int main()
{
    cin>>n>>m>>d;
    for (int i=0;i<m;i++)
    {
        cin>>a[i];sum+=a[i];
    }
    sum+=(m+1)*d;
    if (sum>=n)
    {
        cout<<"YES"<<endl;
        sum-=(m+1)*d;
        int diff=n+1-sum;
        for (int i=0;i<m;i++)
        {
            if (diff>=d)
            {
                if (i==0)
                {
                 //   cout<<"a";
                    v.push_back(make_pair(d,d+a[0]));
                    //v[0].first--;v[0].second--;
                    diff-=d;;
                    d--;
                }
                else
                {
                  //  cout<<"b";
                    v.push_back(make_pair(v.back().second+d,v.back().second+d+a[i]));
                    diff-=d;
                }

            }
            else
            if (diff<d)
            {
                if (i==0)
                {
                  //  cout<<"c";
                    v.push_back(make_pair(diff,diff+a[0]));
                  //  v[0].first--;v[0].second--;
                    diff=0;
                    d--;
                }
                else
                {
                  //  cout<<"d";
                    v.push_back(make_pair(diff+v.back().second,diff+v.back().second+a[i]));
                    diff=0;
                }
            }
        }
      //  cout<<endl;

        int col[1024];memset(col,0,sizeof(col));
        for (int i=0;i<m;i++)
        {
           // cout<<v[i].first<<" "<<v[i].second<<endl;
            for (int j=v[i].first;j<v[i].second;j++)
            {
                col[j]=i+1;
            }
        }
        for (int i=1;i<=n;i++)
        {
            cout<<col[i]<<" ";
        }
        cout<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define PB push_back
#define ff first
#define ss second
#define MP make_pair
#define MXX 10000000000
int main(){
   ll t;cin>>t;
   while(t--){
        ll n,k,mx,arr[26]={0};cin>>n>>k;
        string s;cin>>s;
        for(ll i=0;i<n;i++)
           arr[s[i]-'a']++;
        for(ll i=1;i<=n;i++){
            ll ans=0,temp=i/__gcd(i,k);
            for(ll j=0;j<26;j++)
                ans+=(arr[j]/temp)*temp;
            if(ans>=i)
                mx=i;
        }
        cout<<mx<<endl;
   }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define PB push_back
#define ff first
#define ss second
#define MP make_pair
#define MXX 10000000000
int main(){
   ll t;cin>>t;
   while(t--){
        ll n,k,mx;cin>>n>>k;
        ll arr[27]={0};
        string s;cin>>s;
        for(ll i=0;i<n;i++)
           arr[s[i]-'a']++;
        for(ll i=1;i<=n;i++){
            ll ans=0;
            ll tt=__gcd(i,k);
            // if(k%i==0)
            //     mx=i;
            // else if(i%(k%i)==0){
            //     ll temp=i/(k%i);
            //     for(ll j=0;j<26;j++)
            //         ans+=(arr[j]/temp)*temp;
            //     if(ans>=i)
            //         mx=i;
            // }
            // else if(i%(i-k%i)==0){
                 ll temp=i/tt;
                for(ll j=0;j<26;j++)
                    ans+=(arr[j]/temp)*temp;
                if(ans>=i)
                    mx=i;
            //}
        }
        cout<<mx<<endl;
   }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define PB push_back
#define ff first
#define ss second
#define MP make_pair
#define MXX 10000000000
int main(){
   ll t;cin>>t;
   while(t--){
        ll n,k,mx;cin>>n>>k;
        ll arr[27]={0};
        string s;cin>>s;
        for(ll i=0;i<n;i++)
           arr[s[i]-'a']++;
        for(ll i=1;i<=n;i++){
            ll ans=0;
            if(k%i==0)
                mx=i;
            else if(i%(k%i)==0){
                ll temp=i/(k%i);
                for(ll j=0;j<26;j++)
                    ans+=(arr[j]/temp)*temp;
                if(ans>=i)
                    mx=i;
            }
            else if(i%(i-k%i)==0){
                ans=0;
                ll temp=i/(i-k%i);
                for(ll j=0;j<26;j++)
                    ans+=(arr[j]/temp)*temp;
                if(ans>=i)
                    mx=i;
            }
        }
        cout<<mx<<endl;
   }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define PB push_back
#define ff first
#define ss second
#define MP make_pair
#define MXX 10000000000
int main(){
   ll t;cin>>t;
   while(t--){
        ll n,k,mx;cin>>n>>k;
        ll arr[27]={0};
        string s;cin>>s;
        for(ll i=0;i<n;i++)
           arr[s[i]-'a']++;
        for(ll i=1;i<=n;i++){
            ll ans=0;
            if(k%i==0)
                mx=i;
            else{
            if(i%(k%i)==0){
                ll temp=i/(k%i);
                for(ll j=0;j<26;j++)
                    ans+=(arr[j]/temp)*temp;
                if(ans>=i)
                    mx=i;
            }
            if(i%(i-k%i)==0){
                ans=0;
                ll temp=i/(i-k%i);
                for(ll j=0;j<26;j++)
                    ans+=(arr[j]/temp)*temp;
                if(ans>=i)
                    mx=i;
            }
            }
        }
        cout<<mx<<endl;
   }
}


#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>
#include<limits.h>
using namespace std;
using T = tuple<int,int,int>;

#define eb emplace_back
#define pb push_back
#define MP make_pair
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define rep(i,j,n) for (int i = j; i < n; ++i)
#define repn(i,j,n) for (int i = j; i <= n; ++i)
#define revn(i,j,n) for (int i = j; i >= n; --i)
#define sz(i) i.size()
#define mem(i,v) memset(i,v,sizeof(i))
#define all(v) v.begin(), v.end()
//#define endl '\n'
#define int long long
#define INF 1e7
#define ss second
#define ff first
#define vi vector<int>
#define pri(arr,a,b) repn(i,1,a){repn(j,i+1,b){cout<<arr[i][j]<<" ";}cout<<endl;}

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair<int,pair<int,int>> piii;

string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

const int mod=1e9+7;
//const int mod=998244353;
const int up=1e5+10;
const int MAXN=1e6+10;

void solve()
{
    int n,k;
    string si;
    cin>>n>>k;
    cin>>si;
    int mp[26];
    mem(mp,0);
    repn(i,1,sz(si)){
        mp[si[i-1]-'a']++;
    }
    set<int,greater<int>>s;
    if(k<=n){
        int ans=k,cnt;
        //cout<<ans<<endl;
        for(int v=k+1;v<=n;v++){
           int p=__gcd(v,k);
           int sz=v/p;
           cnt=0;
           repn(i,0,25){
                cnt+=mp[i]/sz;
           }
           if(cnt>=p){
            ans=v;
           }
        }
        cout<<ans<<endl;
    }
    else{
        int ans=n;
        for(int i=1;i<=n;i++){
            if(k%i==0){
                //cout<<i<<endl;
                ans=i;
            }
        }
        cout<<ans<<endl;
    }
}

int32_t main()
{
    fast_cin();
    int T;
    //sieve();
    cin>>T;
    //T=1;
    int t1=1;
    while(true)
    {
        //cout<<"Test case #"<<t1<<endl;
        solve();
        t1++;
        if(t1>T)
            break;
    }
    //cout<<ans<<endl;
}


#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>
#include<limits.h>
using namespace std;
using T = tuple<int,int,int>;

#define eb emplace_back
#define pb push_back
#define MP make_pair
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define rep(i,j,n) for (int i = j; i < n; ++i)
#define repn(i,j,n) for (int i = j; i <= n; ++i)
#define revn(i,j,n) for (int i = j; i >= n; --i)
#define sz(i) i.size()
#define mem(i,v) memset(i,v,sizeof(i))
#define all(v) v.begin(), v.end()
//#define endl '\n'
#define int long long
#define INF 1e7
#define ss second
#define ff first
#define vi vector<int>
#define pri(arr,a,b) repn(i,1,a){repn(j,i+1,b){cout<<arr[i][j]<<" ";}cout<<endl;}

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair<int,pair<int,int>> piii;

string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

const int mod=1e9+7;
//const int mod=998244353;
const int up=1e5+10;
const int MAXN=1e6+10;

void solve()
{
    int n,k;
    string si;
    cin>>n>>k;
    cin>>si;
    int mp[26],cnt;
    mem(mp,0);
    int mx=-1;
    repn(i,1,sz(si)){
        mp[si[i-1]-'a']++;
        mx=max(mx,mp[si[i-1]-'a']);
    }
    set<int,greater<int>>s;
    if(k<=n){
        int ans=k,cnt;
        //cout<<ans<<endl;
        for(int v=k+1;v<=n;v++){
           int p=__gcd(v,k);
           int sz=v/p;
           cnt=0;
           repn(i,0,25){
                cnt+=mp[i]/sz;
           }
           if(cnt>=p){
            ans=v;
           }
        }
        cout<<ans<<endl;
    }
    else{
        int ans;
        for(int v=1;v<=n;v++){
            if(k%v==0)
                ans=v;
           int p=__gcd(v,k);
           int sz=v/p;
           cnt=0;
           repn(i,0,25){
                cnt+=mp[i]/sz;
           }
           if(cnt>=p){
            ans=v;
           }
        }
        cout<<max(ans,mx)<<endl;
    }
}

int32_t main()
{
    fast_cin();
    int T;
    //sieve();
    cin>>T;
    //T=1;
    int t1=1;
    while(true)
    {
        //cout<<"Test case #"<<t1<<endl;
        solve();
        t1++;
        if(t1>T)
            break;
    }
    //cout<<ans<<endl;
}


#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>
#include<limits.h>
using namespace std;
using T = tuple<int,int,int>;

#define eb emplace_back
#define pb push_back
#define MP make_pair
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define rep(i,j,n) for (int i = j; i < n; ++i)
#define repn(i,j,n) for (int i = j; i <= n; ++i)
#define revn(i,j,n) for (int i = j; i >= n; --i)
#define sz(i) i.size()
#define mem(i,v) memset(i,v,sizeof(i))
#define all(v) v.begin(), v.end()
//#define endl '\n'
#define int long long
#define INF 1e7
#define ss second
#define ff first
#define vi vector<int>
#define pri(arr,a,b) repn(i,1,a){repn(j,i+1,b){cout<<arr[i][j]<<" ";}cout<<endl;}

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair<int,pair<int,int>> piii;

string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

const int mod=1e9+7;
//const int mod=998244353;
const int up=1e5+10;
const int MAXN=1e6+10;

void solve()
{
    int n,k;
    string si;
    cin>>n>>k;
    cin>>si;
    vector<int> divi;
    for(int i=2;i<=sqrt(k);i++){
        if(k%i==0){
            divi.push_back(i);
            if(i!=k/i){
                divi.push_back(k/i);
            }
        }
    }
    divi.push_back(k);
    int mp[26];
    mem(mp,0);
    repn(i,1,sz(si)){
        mp[si[i-1]-'a']++;
    }
    set<int,greater<int>>s;
    if(k<=n){
        int ans=0,cnt;
        for(auto v:divi){
            //cout<<v<<endl;
            for(int i=v;i<=n;i+=v)
            {
                cnt=0;
                repn(j,0,25){
                    cnt+=(mp[j]/(i/v));
                }
                if(cnt<v){
                    break;
                }
                ans=max(ans,i);
            }
        }
        cout<<ans<<endl;
    }
    else{
        int ans=n;
        for(int i=1;i<=n;i++){
            if(k%i==0){
                //cout<<i<<endl;
                ans=i;
            }
        }
        cout<<ans<<endl;
    }
}

int32_t main()
{
    fast_cin();
    int T;
    //sieve();
    cin>>T;
    //T=1;
    int t1=1;
    while(true)
    {
        //cout<<"Test case #"<<t1<<endl;
        solve();
        t1++;
        if(t1>T)
            break;
    }
    //cout<<ans<<endl;
}


#include<bits/stdc++.h>
#include <time.h>
using namespace std;
#include <math.h>
#define ll long long
// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
//clock_t tStart = clock();
//printf("Time taken: %.9fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
#define max1 200002
long long int mod =1e9+7;
//int vis[max1];

int main(){
	int t;
	cin>>t;
	while(t--){
		int n,k;
		cin>>n>>k;
		string s;
		cin>>s;
		sort(s.begin(),s.end());
		//cout<<s<<endl;
		int f[26];
		memset(f,0,sizeof(f));
		for (int i = 0; i < n; ++i)
		{
			f[s[i]-'a']++;
		}
		// for (int i = 0; i < 26; ++i)
		// {
		// 	cout<<f[i]<<" ";
		// }
		// cout<<endl;
		if(s[0]==s[n-1]){
			cout<<n<<endl;
		}
		else if(k==1){
			int ans=0;
			for (int i = 0; i < 26; ++i)
			{
				ans=max(ans,f[i]);
			}
			cout<<ans<<endl;
		}
		// else if(k>n){
		// 	int ans=1;
		// 	for(int i=2;i<=n;i++){
		// 		if(k%i==0){
		// 			ans=i;
		// 		}
		// 	}
		// 	cout<<ans<<endl;
		// }
		else if(k%n==0){
			cout<<n<<endl;
		}
		else{
			int fans=0;
			for(int i=2;i<=min(k,n);i++){
			if(k%i!=0)
				continue;
				int maxl=n/i;
				//maxl=maxl*i;
				int ans=i;
				int m=2;
				while(m<=maxl){
					int tans=0;
					for(int j=0;j<26;j++){
						int x=f[j]/m;
						tans+=x;
					}
					if(tans>=i){
						ans=m*i;
					}
					m++;
			}
			fans=max(fans,ans);
		}
			cout<<fans<<endl;

	}

}

}


#include<bits/stdc++.h>
#include <time.h>
using namespace std;
#include <math.h>
#define ll long long
// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
//clock_t tStart = clock();
//printf("Time taken: %.9fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
#define max1 200002
long long int mod =1e9+7;
//int vis[max1];

int main(){
	int t;
	cin>>t;
	while(t--){
		int n,k;
		cin>>n>>k;
		string s;
		cin>>s;
		int f[26];
		memset(f,0,sizeof(f));
		for (int i = 0; i < n; ++i)
		{
			f[s[i]-'a']++;
		}
		// for (int i = 0; i < 26; ++i)
		// {
		// 	cout<<f[i]<<" ";
		// }
		// cout<<endl;
		if(k>n){
			int ans=1;
			for(int i=2;i<=n;i++){
				if(k%i==0){
					ans=i;
				}
			}
			cout<<ans<<endl;
		}
		else if(k==n){
			cout<<n<<endl;
		}
		else{
			int fans=k;
			for(int i=2;i<=k;i++){
			if(k%i!=0)
				continue;
				int maxl=n/i;
				maxl=maxl*i;
				int ans=i;
				int m=2;
				while(m*i<=maxl){
					int tans=0;
					int flag=1;
					for(int j=0;j<26;j++){
						tans+=(f[j]/m);
					}
					if(tans>=i){
						ans=m*i;
					}
					//cout<<tans<<endl;
					//cout<<tans<<endl;
					m++;
		}
			fans=max(fans,ans);
		}
		cout<<fans<<endl;

	}

}

}


#include<bits/stdc++.h>
#include <time.h>
using namespace std;
#include <math.h>
#define ll long long
// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
//clock_t tStart = clock();
//printf("Time taken: %.9fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
#define max1 200002
long long int mod =1e9+7;
//int vis[max1];

int main(){
	int t;
	cin>>t;
	while(t--){
		int n,k;
		cin>>n>>k;
		string s;
		cin>>s;
		sort(s.begin(),s.end());
		//cout<<s<<endl;
		int f[26];
		memset(f,0,sizeof(f));
		for (int i = 0; i < n; ++i)
		{
			f[s[i]-'a']++;
		}
		// for (int i = 0; i < 26; ++i)
		// {
		// 	cout<<f[i]<<" ";
		// }
		// cout<<endl;
		if(s[0]==s[n-1]){
			cout<<n<<endl;
		}
		else if(k==1){
			int ans=0;
			for (int i = 0; i < 26; ++i)
			{
				ans=max(ans,f[i]);
			}
			cout<<ans<<endl;
		}
		// else if(k>n){
		// 	int ans=1;
		// 	for(int i=2;i<=n;i++){
		// 		if(k%i==0){
		// 			ans=i;
		// 		}
		// 	}
		// 	cout<<ans<<endl;
		// }
		else if(k%n==0){
			cout<<n<<endl;
		}
		else{
			int fans=0;
			int flag=1;
			for(int i=2;i<=min(k,n);i++){
			if(k%i!=0)
				continue;
			flag=0;
				int maxl=n/i;
				//maxl=maxl*i;
				int ans=i;
				int m=2;
				while(m<=maxl){
					int tans=0;
					for(int j=0;j<26;j++){
						int x=f[j]/m;
						tans+=x;
					}
					if(tans>=i){
						ans=m*i;
					}
					m++;
			}
			fans=max(fans,ans);
		}
		if(flag){
			int ans=0;
			for (int i = 0; i < 26; ++i)
			{
				ans=max(ans,f[i]);
			}
			cout<<ans<<endl;
		}
		else{
		cout<<fans<<endl;
	}

	}

}

}


#include<bits/stdc++.h>
#include <time.h>
using namespace std;
#include <math.h>
#define ll long long
// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
//clock_t tStart = clock();
//printf("Time taken: %.9fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
#define max1 200002
long long int mod =1e9+7;
//int vis[max1];

int main(){
	int t;
	cin>>t;
	while(t--){
		int n,k;
		cin>>n>>k;
		string s;
		cin>>s;
		sort(s.begin(),s.end());
		//cout<<s<<endl;
		int f[26];
		memset(f,0,sizeof(f));
		for (int i = 0; i < n; ++i)
		{
			f[s[i]-'a']++;
		}
		// for (int i = 0; i < 26; ++i)
		// {
		// 	cout<<f[i]<<" ";
		// }
		// cout<<endl;
		if(s[0]==s[n-1]){
			cout<<n<<endl;
		}
		else if(k==1||n==1){
			cout<<1<<endl;
		}
		// else if(k>n){
		// 	int ans=1;
		// 	for(int i=2;i<=n;i++){
		// 		if(k%i==0){
		// 			ans=i;
		// 		}
		// 	}
		// 	cout<<ans<<endl;
		// }
		else if(k%n==0){
			cout<<n<<endl;
		}
		else{
			int fans=0;
			for(int i=2;i<=min(k,n);i++){
			if(k%i!=0)
				continue;
				int maxl=n/i;
				//maxl=maxl*i;
				int ans=i;
				int m=2;
				while(m<=maxl){
					int tans=0;
					for(int j=0;j<26;j++){
						int x=f[j]/m;
						tans+=x;
					}
					if(tans>=i){
						ans=m*i;
					}
					m++;
			}
			fans=max(fans,ans);
		}
			cout<<fans<<endl;

	}

}

}


#include<bits/stdc++.h>
#include <time.h>
using namespace std;
#include <math.h>
#define ll long long
// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
//clock_t tStart = clock();
//printf("Time taken: %.9fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
#define max1 200002
long long int mod =1e9+7;
//int vis[max1];

int main(){
	int t;
	cin>>t;
	while(t--){
		int n,k;
		cin>>n>>k;
		string s;
		cin>>s;
		sort(s.begin(),s.end());
		//cout<<s<<endl;
		int f[26];
		memset(f,0,sizeof(f));
		for (int i = 0; i < n; ++i)
		{
			f[s[i]-'a']++;
		}
		// for (int i = 0; i < 26; ++i)
		// {
		// 	cout<<f[i]<<" ";
		// }
		// cout<<endl;
		if(s[0]==s[n-1]){
			cout<<n<<endl;
		}
		else if(k>n){
			int ans=1;
			for(int i=2;i<=n;i++){
				if(k%i==0){
					ans=i;
				}
			}
			cout<<ans<<endl;
		}
		else if(k==n){
			cout<<n<<endl;
		}
		else{
			int fans=k;
			for(int i=2;i<=k;i++){
			if(k%i!=0)
				continue;
				int maxl=n/i;
				maxl=maxl*i;
				int ans=i;
				int m=2;
				while(m*i<=maxl){
					int tans=0;
					for(int j=0;j<26;j++){
						tans+=(f[j]/m);
					}
					if(tans>=i){
						ans=m*i;
					}
					m++;
			}
			fans=max(fans,ans);
		}
		cout<<fans<<endl;

	}

}

}


#include<bits/stdc++.h>
#include <time.h>
using namespace std;
#include <math.h>
#define ll long long
// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
//clock_t tStart = clock();
//printf("Time taken: %.9fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
#define max1 200002
long long int mod =1e9+7;
//int vis[max1];

int main(){
	int t;
	cin>>t;
	while(t--){
		int n,k;
		cin>>n>>k;
		string s;
		cin>>s;
		sort(s.begin(),s.end());
		//cout<<s<<endl;
		int f[26];
		memset(f,0,sizeof(f));
		for (int i = 0; i < n; ++i)
		{
			f[s[i]-'a']++;
		}
		// for (int i = 0; i < 26; ++i)
		// {
		// 	cout<<f[i]<<" ";
		// }
		// cout<<endl;
		if(s[0]==s[n-1]){
			cout<<n<<endl;
		}
		// else if(k>n){
		// 	int ans=1;
		// 	for(int i=2;i<=n;i++){
		// 		if(k%i==0){
		// 			ans=i;
		// 		}
		// 	}
		// 	cout<<ans<<endl;
		// }
		else if(k==n){
			cout<<n<<endl;
		}
		else{
			int fans=0;
			for(int i=2;i<=min(k,n);i++){
			if(k%i!=0)
			continue;
				int maxl=n/i;
				//maxl=maxl*i;
				int ans=i;
				int m=2;
				while(m<=maxl){
					int tans=0;
					for(int j=0;j<26;j++){
						int x=f[j]/m;
						tans+=x;
					}
					if(tans>=i){
						ans=m*i;
					}
					m++;
			}
			fans=max(fans,ans);
		}
		cout<<fans<<endl;

	}

}

}


#include<bits/stdc++.h>
#include <time.h>
using namespace std;
#include <math.h>
#define ll long long
// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
//clock_t tStart = clock();
//printf("Time taken: %.9fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
#define max1 200002
long long int mod =1e9+7;
//int vis[max1];

int main(){
	int t;
	cin>>t;
	while(t--){
		int n,k;
		cin>>n>>k;
		string s;
		cin>>s;
		sort(s.begin(),s.end());
		//cout<<s<<endl;
		int f[26];
		memset(f,0,sizeof(f));
		for (int i = 0; i < n; ++i)
		{
			f[s[i]-'a']++;
		}
		// for (int i = 0; i < 26; ++i)
		// {
		// 	cout<<f[i]<<" ";
		// }
		// cout<<endl;
		if(s[0]==s[n-1]){
			cout<<n<<endl;
		}
		else if(k==1){
			int ans=0;
			for (int i = 0; i < 26; ++i)
			{
				ans=max(ans,f[i]);
			}
			cout<<ans<<endl;
		}
		// else if(k>n){
		// 	int ans=1;
		// 	for(int i=2;i<=n;i++){
		// 		if(k%i==0){
		// 			ans=i;
		// 		}
		// 	}
		// 	cout<<ans<<endl;
		// }
		else if(k%n==0){
			cout<<n<<endl;
		}
		else{
			int fans=0;
			for (int i = 0; i < 26; ++i)
			{
				fans=max(fans,f[i]);
			}
			for(int i=2;i<=min(k,n);i++){
			if(k%i!=0)
				continue;
			//flag=0;
				int maxl=n/i;
				//maxl=maxl*i;
				int ans=i;
				int m=2;
				while(m<=maxl){
					int tans=0;
					for(int j=0;j<26;j++){
						int x=f[j]/m;
						tans+=x;
					}
					if(tans>=i){
						ans=m*i;
					}
					m++;
			}
			fans=max(fans,ans);
		}
		cout<<fans<<endl;

	}

}

}


#include<bits/stdc++.h>
#include <time.h>
using namespace std;
#include <math.h>
#define ll long long
// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
//clock_t tStart = clock();
//printf("Time taken: %.9fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
#define max1 200002
long long int mod =1e9+7;
//int vis[max1];

int main(){
	int t;
	cin>>t;
	while(t--){
		int n,k;
		cin>>n>>k;
		string s;
		cin>>s;
		sort(s.begin(),s.end());
		//cout<<s<<endl;
		int f[26];
		memset(f,0,sizeof(f));
		for (int i = 0; i < n; ++i)
		{
			f[s[i]-'a']++;
		}
		// for (int i = 0; i < 26; ++i)
		// {
		// 	cout<<f[i]<<" ";
		// }
		// cout<<endl;
		if(s[0]==s[n-1]){
			cout<<n<<endl;
		}
		// else if(k>n){
		// 	int ans=1;
		// 	for(int i=2;i<=n;i++){
		// 		if(k%i==0){
		// 			ans=i;
		// 		}
		// 	}
		// 	cout<<ans<<endl;
		// }
		else if(k%n==0){
			cout<<n<<endl;
		}
		else{
			int fans=0;
			for(int i=2;i<=min(k,n);i++){
			if(k%i!=0)
				continue;
				int maxl=n/i;
				//maxl=maxl*i;
				int ans=i;
				int m=2;
				while(m<=maxl){
					int tans=0;
					for(int j=0;j<26;j++){
						int x=f[j]/m;
						tans+=x;
					}
					if(tans>=i){
						ans=m*i;
					}
					m++;
			}
			fans=max(fans,ans);
		}
			cout<<fans<<endl;

	}

}

}


#include<bits/stdc++.h>
#include<assert.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define f first
#define s second

#define all(s) s.begin(),s.end()
#define spresent(s,v) ((s).find(v)!=s.end())
#define present(s,v) (find(all(s),v)!=s.end())

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL)

#define fill_1d(a,val) fill(a,a+sizeof(a)/sizeof(a[0]),val)
#define fill_2d(a,val) fill(&a[0][0],&a[0][0]+sizeof(a)/sizeof(a[0][0]),val)
#define fill_nd(a,p2f,val) fill(p2f,p2f+sizeof(a)/sizeof(*p2f),val)

#define deb(x) cout<<#x<<" = "<<x<<endl
#define dout(i,s) cout<<"Case #"<<i<<": "<<s<<"\n"

#define For(a,n) for(int i=a; (a<n?i<n:i>n) ; (a<n?++i:--i))

typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

typedef struct node{
	ll val,more=0,less=0;
	bool operator <(const node& a){
		return val<a.val;
	}
}node;

const int N = 1e5+5;
const int M = 998244353;

ll pow_mod(ll,ll);

vi graph[N];

void solve(){
	int n,k;
	cin>>n>>k;

	int freq[26]={0};
	string s;
	cin>>s;
	For(0,n)
		++freq[s[i]-'a'];

	int ma=1;
	For(1,n+1){
		// int _k = k%i;
		int pairsize = i/__gcd(i,_k);
		int cntpair = 0;
		For(0,26)
			cntpair+=freq[i]/pairsize;
		if(cntpair>=i/pairsize)
			ma = max(ma,i);
	}
	cout<<ma<<"\n";
}

//D

// void solve(){
// 	string s;
// 	cin>>s;
// 	int freq[26] = {0};
// 	For(0,s.length())
// 		++freq[s[i] - 'a'];
// 	int m;
// 	cin>>m;
// 	int b[m];
// 	For(0,m)
// 		cin>>b[i];

// 	int sum[m] = {0};
// 	bool visited[m] ={0};
// 	int priority[m];

// 	queue<int> q;
// 	For(0,m)
// 	if(b[i]==0){
// 		visited[i]=1;
// 		q.push(i);
// 		priority[i]=0;
// 	}

// 	vector< vector<int> > group(m+1, vector<int>());

// 	while(!q.empty()){
// 		int cur = q.front();
// 		q.pop();
// 		For(0,m){
// 			if(!visited[i]){
// 				sum[i]+=abs(cur-i);
// 				if(sum[i]==b[i]){
// 					visited[i]=1;
// 					q.push(i);
// 					priority[i]=priority[cur]+1;
// 				}
// 			}
// 		}
// 	}

// 	For(0,m){
// 		assert(visited[i]);
// 		// deb(i);
// 		// deb(priority[i]);
// 		group[priority[i]].pb(i);
// 	}

// 	int ans[m];
// 	int counter=25;
// 	For(0,m){
// 		if(group[i].size()==0)
// 			break;
// 		while(freq[counter]<group[i].size())
// 			--counter;

// 		assert(counter>=0);

// 		if(freq[counter]>=group[i].size()){
// 			for(int j=0;j<group[i].size();++j){
// 				ans[group[i][j]] = (97+counter);
// 				// deb(97+counter);
// 			}
// 			--counter;
// 		}
// 	}

// 	For(0,m)
// 	cout<<(char)ans[i];
// 	cout<<"\n";

// }

// C
// int n,k;
// string s;

// int get(int ind){
// 	For(ind,min(n,ind+k+1)){
// 		if(s[i]=='1')
// 			return i;
// 	}
// 	return ind;
// }

// void solve(){

// 	cin>>n>>k;

// 	cin>>s;

// 	int prev=-k-1;

// 	int cnt=0;
// 	For(0,n){
// 		if(s[i]=='0' && i-prev>k){
// 			int place = get(i);
// 			// deb(i),deb(place);
// 			if(place==i){
// 				++cnt;
// 				prev=i;
// 				i+=k;
// 			}
// 			else
// 				prev=i=place;

// 		}
// 		else if(s[i]=='1')
// 			prev=i;
// 	}
// 	cout<<cnt<<"\n";

// 	// int prev=-k-1;
// 	// int cnt=0;
// 	// if(s.find('1')==-1){
// 	// 	cout<<max(1,n/(k+1))<<"\n";
// 	// 	return;
// 	// }
// 	// For(0,n){
// 	// 	if(s[i]=='1'){
// 	// 		cnt+= max(0,i-prev-1-k)/(k+1);
// 	// 		prev=i;
// 	// 	}
// 	// }
// 	// cnt+=(n-1-prev)/(k+1);
// 	// cout<<cnt<<"\n";

// }

int main(){
	// fastio();

	int t=1;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

ll pow_mod(ll base, ll pow){
	ll ans = 1;
	while(pow){
		if(pow&1)
			ans = ans*base%M;
		base = base*base%M;
		pow>>=1;
	}
	return ans;
}


#include<bits/stdc++.h>
#include<assert.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define f first
#define s second

#define all(s) s.begin(),s.end()
#define spresent(s,v) ((s).find(v)!=s.end())
#define present(s,v) (find(all(s),v)!=s.end())

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL)

#define fill_1d(a,val) fill(a,a+sizeof(a)/sizeof(a[0]),val)
#define fill_2d(a,val) fill(&a[0][0],&a[0][0]+sizeof(a)/sizeof(a[0][0]),val)
#define fill_nd(a,p2f,val) fill(p2f,p2f+sizeof(a)/sizeof(*p2f),val)

#define deb(x) cout<<#x<<" = "<<x<<endl
#define dout(i,s) cout<<"Case #"<<i<<": "<<s<<"\n"

#define For(a,n) for(int i=a; (a<n?i<n:i>n) ; (a<n?++i:--i))

typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

typedef struct node{
	ll val,more=0,less=0;
	bool operator <(const node& a){
		return val<a.val;
	}
}node;

const int N = 1e5+5;
const int M = 998244353;

ll pow_mod(ll,ll);

vi graph[N];

void solve(){
	int n,k;
	cin>>n>>k;

	int freq[26]={0};
	string s;
	cin>>s;
	For(0,n)
		++freq[s[i]-'a'];

	int ma=1;
	For(1,n+1){
		int _k = k%i;
		int pairsize = i/__gcd(i,_k);
		int cntpair = 0;
		For(0,26)
			cntpair+=freq[i]/pairsize;
		if(cntpair>=i/pairsize)
			ma = max(ma,i);
	}
	cout<<ma<<"\n";
}

//D

// void solve(){
// 	string s;
// 	cin>>s;
// 	int freq[26] = {0};
// 	For(0,s.length())
// 		++freq[s[i] - 'a'];
// 	int m;
// 	cin>>m;
// 	int b[m];
// 	For(0,m)
// 		cin>>b[i];

// 	int sum[m] = {0};
// 	bool visited[m] ={0};
// 	int priority[m];

// 	queue<int> q;
// 	For(0,m)
// 	if(b[i]==0){
// 		visited[i]=1;
// 		q.push(i);
// 		priority[i]=0;
// 	}

// 	vector< vector<int> > group(m+1, vector<int>());

// 	while(!q.empty()){
// 		int cur = q.front();
// 		q.pop();
// 		For(0,m){
// 			if(!visited[i]){
// 				sum[i]+=abs(cur-i);
// 				if(sum[i]==b[i]){
// 					visited[i]=1;
// 					q.push(i);
// 					priority[i]=priority[cur]+1;
// 				}
// 			}
// 		}
// 	}

// 	For(0,m){
// 		assert(visited[i]);
// 		// deb(i);
// 		// deb(priority[i]);
// 		group[priority[i]].pb(i);
// 	}

// 	int ans[m];
// 	int counter=25;
// 	For(0,m){
// 		if(group[i].size()==0)
// 			break;
// 		while(freq[counter]<group[i].size())
// 			--counter;

// 		assert(counter>=0);

// 		if(freq[counter]>=group[i].size()){
// 			for(int j=0;j<group[i].size();++j){
// 				ans[group[i][j]] = (97+counter);
// 				// deb(97+counter);
// 			}
// 			--counter;
// 		}
// 	}

// 	For(0,m)
// 	cout<<(char)ans[i];
// 	cout<<"\n";

// }

// C
// int n,k;
// string s;

// int get(int ind){
// 	For(ind,min(n,ind+k+1)){
// 		if(s[i]=='1')
// 			return i;
// 	}
// 	return ind;
// }

// void solve(){

// 	cin>>n>>k;

// 	cin>>s;

// 	int prev=-k-1;

// 	int cnt=0;
// 	For(0,n){
// 		if(s[i]=='0' && i-prev>k){
// 			int place = get(i);
// 			// deb(i),deb(place);
// 			if(place==i){
// 				++cnt;
// 				prev=i;
// 				i+=k;
// 			}
// 			else
// 				prev=i=place;

// 		}
// 		else if(s[i]=='1')
// 			prev=i;
// 	}
// 	cout<<cnt<<"\n";

// 	// int prev=-k-1;
// 	// int cnt=0;
// 	// if(s.find('1')==-1){
// 	// 	cout<<max(1,n/(k+1))<<"\n";
// 	// 	return;
// 	// }
// 	// For(0,n){
// 	// 	if(s[i]=='1'){
// 	// 		cnt+= max(0,i-prev-1-k)/(k+1);
// 	// 		prev=i;
// 	// 	}
// 	// }
// 	// cnt+=(n-1-prev)/(k+1);
// 	// cout<<cnt<<"\n";

// }

int main(){
	// fastio();

	int t=1;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

ll pow_mod(ll base, ll pow){
	ll ans = 1;
	while(pow){
		if(pow&1)
			ans = ans*base%M;
		base = base*base%M;
		pow>>=1;
	}
	return ans;
}


#include<bits/stdc++.h>
#include<assert.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define f first
#define s second

#define all(s) s.begin(),s.end()
#define spresent(s,v) ((s).find(v)!=s.end())
#define present(s,v) (find(all(s),v)!=s.end())

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL)

#define fill_1d(a,val) fill(a,a+sizeof(a)/sizeof(a[0]),val)
#define fill_2d(a,val) fill(&a[0][0],&a[0][0]+sizeof(a)/sizeof(a[0][0]),val)
#define fill_nd(a,p2f,val) fill(p2f,p2f+sizeof(a)/sizeof(*p2f),val)

#define deb(x) cout<<#x<<" = "<<x<<endl
#define dout(i,s) cout<<"Case #"<<i<<": "<<s<<"\n"

#define For(a,n) for(int i=a; (a<n?i<n:i>n) ; (a<n?++i:--i))

typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

typedef struct node{
	ll val,more=0,less=0;
	bool operator <(const node& a){
		return val<a.val;
	}
}node;

const int N = 1e5+5;
const int M = 998244353;

ll pow_mod(ll,ll);

vi graph[N];

void solve(){
	int n,k;
	cin>>n>>k;

	int freq[26]={0};
	string s;
	cin>>s;
	For(0,n)
		++freq[s[i]-'a'];

	int ma=1;
	For(1,n+1){
		// int _k = k%i;
		int pairsize = i/__gcd(i,k);
		int cntpair = 0;
		For(0,26)
			cntpair+=freq[i]/pairsize;
		if(cntpair>=i/pairsize)
			ma = max(ma,i);
	}
	cout<<ma<<"\n";
}

//D

// void solve(){
// 	string s;
// 	cin>>s;
// 	int freq[26] = {0};
// 	For(0,s.length())
// 		++freq[s[i] - 'a'];
// 	int m;
// 	cin>>m;
// 	int b[m];
// 	For(0,m)
// 		cin>>b[i];

// 	int sum[m] = {0};
// 	bool visited[m] ={0};
// 	int priority[m];

// 	queue<int> q;
// 	For(0,m)
// 	if(b[i]==0){
// 		visited[i]=1;
// 		q.push(i);
// 		priority[i]=0;
// 	}

// 	vector< vector<int> > group(m+1, vector<int>());

// 	while(!q.empty()){
// 		int cur = q.front();
// 		q.pop();
// 		For(0,m){
// 			if(!visited[i]){
// 				sum[i]+=abs(cur-i);
// 				if(sum[i]==b[i]){
// 					visited[i]=1;
// 					q.push(i);
// 					priority[i]=priority[cur]+1;
// 				}
// 			}
// 		}
// 	}

// 	For(0,m){
// 		assert(visited[i]);
// 		// deb(i);
// 		// deb(priority[i]);
// 		group[priority[i]].pb(i);
// 	}

// 	int ans[m];
// 	int counter=25;
// 	For(0,m){
// 		if(group[i].size()==0)
// 			break;
// 		while(freq[counter]<group[i].size())
// 			--counter;

// 		assert(counter>=0);

// 		if(freq[counter]>=group[i].size()){
// 			for(int j=0;j<group[i].size();++j){
// 				ans[group[i][j]] = (97+counter);
// 				// deb(97+counter);
// 			}
// 			--counter;
// 		}
// 	}

// 	For(0,m)
// 	cout<<(char)ans[i];
// 	cout<<"\n";

// }

// C
// int n,k;
// string s;

// int get(int ind){
// 	For(ind,min(n,ind+k+1)){
// 		if(s[i]=='1')
// 			return i;
// 	}
// 	return ind;
// }

// void solve(){

// 	cin>>n>>k;

// 	cin>>s;

// 	int prev=-k-1;

// 	int cnt=0;
// 	For(0,n){
// 		if(s[i]=='0' && i-prev>k){
// 			int place = get(i);
// 			// deb(i),deb(place);
// 			if(place==i){
// 				++cnt;
// 				prev=i;
// 				i+=k;
// 			}
// 			else
// 				prev=i=place;

// 		}
// 		else if(s[i]=='1')
// 			prev=i;
// 	}
// 	cout<<cnt<<"\n";

// 	// int prev=-k-1;
// 	// int cnt=0;
// 	// if(s.find('1')==-1){
// 	// 	cout<<max(1,n/(k+1))<<"\n";
// 	// 	return;
// 	// }
// 	// For(0,n){
// 	// 	if(s[i]=='1'){
// 	// 		cnt+= max(0,i-prev-1-k)/(k+1);
// 	// 		prev=i;
// 	// 	}
// 	// }
// 	// cnt+=(n-1-prev)/(k+1);
// 	// cout<<cnt<<"\n";

// }

int main(){
	// fastio();

	int t=1;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

ll pow_mod(ll base, ll pow){
	ll ans = 1;
	while(pow){
		if(pow&1)
			ans = ans*base%M;
		base = base*base%M;
		pow>>=1;
	}
	return ans;
}


#include <bits/stdc++.h>
#define ull unsigned long long int
#define ll long long int
#define LL_MAX 9223372036854775807
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define vl vector<ll>
#define bs(v, x) binary_search(v.begin(), v.end(), x)
#define popf pop_front
#define p() cout << '\n'
#define p0(x) cout << x << " "
#define p1(x) cout << x << '\n'
#define p2(x, y) cout << x << " " << y << '\n'
#define p3(x, y, z) cout << x << " " << y << " " << z << '\n'
#define printv(v)                   \
	for (ll i = 0; i < v.size(); ++i) \
		cout << v[i] << " ";            \
	cout << '\n'
#define pr1(x) cout << fixed << setprecision(15) << x << '\n'
#define mod 1000000007
#define mod1 998244353
#define fio                         \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL)
#define get(n) \
	ll n;        \
	cin >> n
#define getvec(v, n)         \
	vector<ll> v(n);           \
	for (ll i = 0; i < n; i++) \
		cin >> v[i];
#define getstr(s) \
	string s;       \
	cin >> s
#define all(x) x.begin(), x.end()
#define countBits(x) __builtin_popcount(x)
using namespace std;

ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}

int main()
{
	fio;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	get(t);
	while (t--)
	{
		get(n);
		get(k);
		getstr(s);
		map<char, ll> m;
		for (int i = 0; i < n; i++)
			++m[s[i]];
		ll ans = 1;
		for (ll i = 2; i <= n; i++)
		{
			ll kt = gcd(i, k);
			ll req = i / kt;
			ll cnt = 0;
			for (char a = 'a'; a <= 'z'; a++)
				if (m[a] >= req)
					cnt += (m[a] / req);
			if (cnt >= kt)
				ans = i;
		}
		p1(ans);
	}
	return 0;
}


#include <bits/stdc++.h>
#define ull unsigned long long int
#define ll long long int
#define LL_MAX 9223372036854775807
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define vl vector<ll>
#define bs(v, x) binary_search(v.begin(), v.end(), x)
#define popf pop_front
#define p() cout << '\n'
#define p0(x) cout << x << " "
#define p1(x) cout << x << '\n'
#define p2(x, y) cout << x << " " << y << '\n'
#define p3(x, y, z) cout << x << " " << y << " " << z << '\n'
#define printv(v)                   \
  for (ll i = 0; i < v.size(); ++i) \
    cout << v[i] << " ";            \
  cout << '\n'
#define pr1(x) cout << fixed << setprecision(15) << x << '\n'
#define mod 1000000007
#define mod1 998244353
#define fio                         \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL)
#define get(n) \
  ll n;        \
  cin >> n
#define getvec(v, n)         \
  vector<ll> v(n);           \
  for (ll i = 0; i < n; i++) \
    cin >> v[i];
#define getstr(s) \
  string s;       \
  cin >> s
#define all(x) x.begin(), x.end()
#define countBits(x) __builtin_popcount(x)
using namespace std;

ll gcd(ll a, ll b)
{
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

int main()
{
  fio;
  get(t);
  while (t--)
  {
    get(n);
    get(k);
    getstr(s);
    map<char, ll> m;
    for (int i = 0; i < n; i++)
      ++m[s[i]];
    ll ans = 1;
    for (ll i = 2; i <= n; i++)
    {
      ll kt = gcd(i, k);
      ll req = i / kt;
      ll cnt = 0;
      for (char a = 'a'; a <= 'z'; a++)
        if (m[a] >= req)
          cnt += (m[a] / req);
      if (cnt >= kt)
        ans = i;
    }
    p1(ans);
  }
  return 0;
}


#include <bits/stdc++.h>
#define ull unsigned long long int
#define ll long long int
#define LL_MAX 9223372036854775807
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define vl vector<ll>
#define bs(v, x) binary_search(v.begin(), v.end(), x)
#define popf pop_front
#define p() cout << '\n'
#define p0(x) cout << x << " "
#define p1(x) cout << x << '\n'
#define p2(x, y) cout << x << " " << y << '\n'
#define p3(x, y, z) cout << x << " " << y << " " << z << '\n'
#define printv(v)                   \
  for (ll i = 0; i < v.size(); ++i) \
    cout << v[i] << " ";            \
  cout << '\n'
#define pr1(x) cout << fixed << setprecision(15) << x << '\n'
#define mod 1000000007
#define mod1 998244353
#define fio                         \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL)
#define get(n) \
  ll n;        \
  cin >> n
#define getvec(v, n)         \
  vector<ll> v(n);           \
  for (ll i = 0; i < n; i++) \
    cin >> v[i];
#define getstr(s) \
  string s;       \
  cin >> s
#define all(x) x.begin(), x.end()
#define countBits(x) __builtin_popcount(x)
using namespace std;

ll gcd(ll a, ll b)
{
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

void mainSolve()
{
  get(n);
  get(k);
  getstr(s);
  map<char, ll> m;
  for (int i = 0; i < n; i++)
    ++m[s[i]];
  ll ans = 1;
  for (ll i = 2; i <= n; i++)
  {
    ll kt = gcd(i, k);
    ll req = i / kt;
    ll cnt = 0;
    for (char a = 'a'; a <= 'z'; a++)
      if (m[a] >= req)
        cnt += (m[a] / req);
    if (cnt >= kt)
      ans = i;
  }
  p1(ans);
}

int main()
{
  fio;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  get(t);
  while (t--)
  {
    mainSolve();
  }
  return 0;
}