#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef pair<int,int> PII;
typedef pair<ll,int> Pli;
typedef pair<ll,ll> Pll;
typedef vector<int> VI;
typedef vector<PII> VII;
//typedef pair<ll,ll>P;
#define fi first
#define se second
#define MP make_pair
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define per(i,a,b) for(int i=(int)a;i>=(int)b;i--)
#define REP(i,n) for(int i=0;i<n;++i)
#define lowbit(x) x&(-x)
#define Rand (rand()*(1<<16)+rand())
#define id(x) ((x)<=B?(x):m-n/(x)+1)
#define fors(i) for(auto i:e[x]) if(i!=p)
#define ls p<<1
#define rs p<<1|1
#define L t[x].l
#define R t[x].r

const int N=555555,M=8888888;
      ll MOD=10007;
      int intINF=int(1e9);
      ll llINF=ll(1e18);
      db eps=1e-8;
      int dx[4]={-1,1,0,0};
      int dy[4]={0,0,-1,1};
      long double pi=acos(-1.0L);
     // ld s2=sqrt(2.0);

int read()
{
   int v=0,f=1;
   char c=getchar();
   while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
   while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
   return v*f;
}

ll readll()
{
   ll v=0,f=1;
   char c=getchar();
   while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
   while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
   return v*f;
}

inline char nc()
{
    static char buf[100000],*p1,*p2;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}

int rd()
{
    int x=0; char ch=nc();
    while(ch<'0'||ch>'9') ch=nc();
    while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=nc();
    return x;
}

/*void pr128(__int128 x)
{
    if(x<0) putchar('-'),x=-x;
    if(x<10) return putchar('0'+x),void();
    pr128(x/10),putchar('0'+(x%10));
}

ll pw(ll x,ll y)
{
    ll res=1;
    while(y)
    {
        if(y&1) res=res*x%MOD;
        x=x*x%MOD;
        y>>=1;
    }
    return res;
}*/

int head[N],vet[N],nxt[N],dis[N],n,tot;
VI d[N],c;
char s[N];

void predo()
{
}

void add(int a,int b)
{
    nxt[++tot]=head[a];
    vet[tot]=b;
    head[a]=tot;
}

PII query(VI a)
{
    printf("? %d",(int)a.size());
    for(auto t:a) printf(" %d",t);
    printf("\n");
    fflush(stdout);
    int x=read(),y=read();
    return MP(x,y);
}

void init()
{
    n=read();
    rep(i,1,n) head[i]=0;
    tot=0;
    rep(i,1,n-1)
    {
        int x=read(),y=read();
        add(x,y);
        add(y,x);
    }
}

void dfs(int u,int pre)
{
    int e=head[u];
    while(e)
    {
        int v=vet[e];
        if(dis[v]==intINF&&v!=pre)
        {
            dis[v]=dis[u]+1;
            dfs(v,u);
        }
        e=nxt[e];
    }
}

void solve()
{
    c.clear();
    rep(i,1,n) c.pb(i);
    PII tmp=query(c);
    int root=tmp.fi,len=tmp.se;
    rep(i,1,n) dis[i]=intINF;
    dis[root]=0;
    dfs(root,0);
    rep(i,0,n) d[i].clear();
    rep(i,1,n) d[dis[i]].pb(i);

    int l=len/2,r=len,u=root;
    if(l*2<len) l++;
    while(l<=r)
    {
        int mid=(l+r)>>1;
        c.clear();
        for(auto t:d[mid]) c.pb(t);
        PII tmp=query(c);
        if(tmp.se==len){u=tmp.fi;l=mid+1;}
         else r=mid-1;
    }

    rep(i,1,n) dis[i]=intINF;
    dis[u]=0;
    dfs(u,0);
    c.clear();
    rep(i,1,n)
     if(dis[i]==len) c.pb(i);
    tmp=query(c);
    int v=tmp.fi;
    printf("! %d %d\n",u,v);
    fflush(stdout);
    scanf("%s",s+1);
}

int main()
{
    //freopen("1.in","r",stdin);
    int cas=read();
    //int cas=1;
    predo();
    while(cas--)
    {
       init();
       solve();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef pair<int,int> PII;
typedef pair<ll,int> Pli;
typedef pair<ll,ll> Pll;
typedef vector<int> VI;
typedef vector<PII> VII;
//typedef pair<ll,ll>P;
#define fi first
#define se second
#define MP make_pair
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define per(i,a,b) for(int i=(int)a;i>=(int)b;i--)
#define REP(i,n) for(int i=0;i<n;++i)
#define lowbit(x) x&(-x)
#define Rand (rand()*(1<<16)+rand())
#define id(x) ((x)<=B?(x):m-n/(x)+1)
#define fors(i) for(auto i:e[x]) if(i!=p)
#define ls p<<1
#define rs p<<1|1
#define L t[x].l
#define R t[x].r

const int N=555555,M=8888888;
      ll MOD=10007;
      int intINF=int(1e9);
      ll llINF=ll(1e18);
      db eps=1e-8;
      int dx[4]={-1,1,0,0};
      int dy[4]={0,0,-1,1};
      long double pi=acos(-1.0L);
     // ld s2=sqrt(2.0);

int read()
{
   int v=0,f=1;
   char c=getchar();
   while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
   while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
   return v*f;
}

ll readll()
{
   ll v=0,f=1;
   char c=getchar();
   while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
   while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
   return v*f;
}

inline char nc()
{
    static char buf[100000],*p1,*p2;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}

int rd()
{
    int x=0; char ch=nc();
    while(ch<'0'||ch>'9') ch=nc();
    while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=nc();
    return x;
}

/*void pr128(__int128 x)
{
    if(x<0) putchar('-'),x=-x;
    if(x<10) return putchar('0'+x),void();
    pr128(x/10),putchar('0'+(x%10));
}

ll pw(ll x,ll y)
{
    ll res=1;
    while(y)
    {
        if(y&1) res=res*x%MOD;
        x=x*x%MOD;
        y>>=1;
    }
    return res;
}*/

int head[N],vet[N],nxt[N],dis[N],n,tot;
VI d[N],c;
char s[N];

void predo()
{
}

void add(int a,int b)
{
    nxt[++tot]=head[a];
    vet[tot]=b;
    head[a]=tot;
}

PII query(VI a)
{
    printf("? %d",(int)a.size());
    for(auto t:a) printf(" %d",t);
    printf("\n");
    fflush(stdout);
    int x=read(),y=read();
    return MP(x,y);
}

void init()
{
    n=read();
    rep(i,1,n) head[i]=0;
    tot=0;
    rep(i,1,n-1)
    {
        int x=read(),y=read();
        add(x,y);
        add(y,x);
    }
}

void dfs(int u,int pre)
{
    int e=head[u];
    while(e)
    {
        int v=vet[e];
        if(!dis[v]&&v!=pre)
        {
            dis[v]=dis[u]+1;
            dfs(v,u);
        }
        e=nxt[e];
    }
}

void solve()
{
    c.clear();
    rep(i,1,n) c.pb(i);
    PII tmp=query(c);
    int root=tmp.fi,len=tmp.se;
    rep(i,1,n) dis[i]=0;
    dis[root]=0;
    dfs(root,0);
    rep(i,0,n) d[i].clear();
    rep(i,1,n) d[dis[i]].pb(i);

    int l=0,r=len/2,u=root;
    if(r*2<len) r++;
    while(l<=r)
    {
        int mid=(l+r)>>1;
        c.clear();
        for(auto t:d[mid]) c.pb(t);
        PII tmp=query(c);
        if(tmp.se==len){u=tmp.fi;l=mid+1;}
         else r=mid-1;
    }

    rep(i,1,n) dis[i]=0;
    dfs(u,0);
    c.clear();
    rep(i,1,n)
     if(dis[i]==len) c.pb(i);
    tmp=query(c);
    int v=tmp.fi;
    printf("! %d %d\n",u,v);
    fflush(stdout);
    scanf("%s",s+1);
}

int main()
{
    //freopen("1.in","r",stdin);
    int cas=read();
    //int cas=1;
    predo();
    while(cas--)
    {
       init();
       solve();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef pair<int,int> PII;
typedef pair<ll,int> Pli;
typedef pair<ll,ll> Pll;
typedef vector<int> VI;
typedef vector<PII> VII;
//typedef pair<ll,ll>P;
#define fi first
#define se second
#define MP make_pair
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define per(i,a,b) for(int i=(int)a;i>=(int)b;i--)
#define REP(i,n) for(int i=0;i<n;++i)
#define lowbit(x) x&(-x)
#define Rand (rand()*(1<<16)+rand())
#define id(x) ((x)<=B?(x):m-n/(x)+1)
#define fors(i) for(auto i:e[x]) if(i!=p)
#define ls p<<1
#define rs p<<1|1
#define L t[x].l
#define R t[x].r

const int N=555555,M=8888888;
      ll MOD=10007;
      int intINF=int(1e9);
      ll llINF=ll(1e18);
      db eps=1e-8;
      int dx[4]={-1,1,0,0};
      int dy[4]={0,0,-1,1};
      long double pi=acos(-1.0L);
     // ld s2=sqrt(2.0);

int read()
{
   int v=0,f=1;
   char c=getchar();
   while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
   while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
   return v*f;
}

ll readll()
{
   ll v=0,f=1;
   char c=getchar();
   while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
   while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
   return v*f;
}

inline char nc()
{
    static char buf[100000],*p1,*p2;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}

int rd()
{
    int x=0; char ch=nc();
    while(ch<'0'||ch>'9') ch=nc();
    while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=nc();
    return x;
}

/*void pr128(__int128 x)
{
    if(x<0) putchar('-'),x=-x;
    if(x<10) return putchar('0'+x),void();
    pr128(x/10),putchar('0'+(x%10));
}

ll pw(ll x,ll y)
{
    ll res=1;
    while(y)
    {
        if(y&1) res=res*x%MOD;
        x=x*x%MOD;
        y>>=1;
    }
    return res;
}*/

int head[N],vet[N],nxt[N],dis[N],n,tot;
VI d[N],c;
char s[N];

void predo()
{
}

void add(int a,int b)
{
    nxt[++tot]=head[a];
    vet[tot]=b;
    head[a]=tot;
}

PII query(VI a)
{
    printf("? %d",(int)a.size());
    for(auto t:a) printf(" %d",t);
    printf("\n");
    fflush(stdout);
    int x=read(),y=read();
    return MP(x,y);
}

void init()
{
    n=read();
    rep(i,1,n) head[i]=0;
    tot=0;
    rep(i,1,n-1)
    {
        int x=read(),y=read();
        add(x,y);
        add(y,x);
    }
}

void dfs(int u,int pre)
{
    int e=head[u];
    while(e)
    {
        int v=vet[e];
        if(!dis[v]&&v!=pre)
        {
            dis[v]=dis[u]+1;
            dfs(v,u);
        }
        e=nxt[e];
    }
}

void solve()
{
    c.clear();
    rep(i,1,n) c.pb(i);
    PII tmp=query(c);
    int root=tmp.fi,len=tmp.se;
    rep(i,1,n) dis[i]=0;
    dis[root]=0;
    dfs(root,0);
    rep(i,0,n) d[i].clear();
    rep(i,1,n) d[dis[i]].pb(i);

    int l=0,r=len/2,u=root;
    while(l<=r)
    {
        int mid=(l+r)>>1;
        c=d[mid];
        PII tmp=query(c);
        if(tmp.se==len){u=tmp.fi;l=mid+1;}
         else r=mid-1;
    }

    rep(i,1,n) dis[i]=0;
    dfs(u,0);
    c.clear();
    rep(i,1,n)
     if(dis[i]==len) c.pb(i);
    tmp=query(c);
    int v=tmp.fi;
    printf("! %d %d\n",u,v);
    fflush(stdout);
    scanf("%s",s+1);
}

int main()
{
    //freopen("1.in","r",stdin);
    int cas=read();
    //int cas=1;
    predo();
    while(cas--)
    {
       init();
       solve();
    }
    return 0;
}


#include<set>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<climits>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long
int read(){
	int f=0,x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return !f?x:-x;
}
#define mp make_pair
const int MAXN=100000;
const int INF=0x3f3f3f3f;
int dep[MAXN+5],Max;
vector<int> G[MAXN+5],V[MAXN+5];
void DFS(int u,int fa){
	Max=max(Max,dep[u]);
	V[dep[u]].push_back(u);
	for(int i=0;i<(int)G[u].size();i++){
		int v=G[u][i];
		if(v==fa) continue;
		dep[v]=dep[u]+1,DFS(v,u);
	}
	return ;
}
int rt,Len;
int main(){
	int T=read();
	while(T--){
		Max=0;
		int n=read();
		for(int i=1;i<=n;i++)
			V[i].clear(),G[i].clear();
		for(int i=1;i<n;i++){
			int u=read(),v=read();
			G[u].push_back(v);
			G[v].push_back(u);
		}
		cout<<'?'<<' '<<n;
		for(int i=1;i<=n;i++)
			cout<<' '<<i;
		cout<<endl,cout<<flush;
		rt=read(),Len=read();
		dep[rt]=0,DFS(rt,0);
		int L=(Len+1)/2-1,R=min(Len,Max)+1,lst=rt;
		while(L+1<R){
			int Mid=(L+R)>>1;
			cout<<'?'<<' '<<V[Mid].size();
			for(int i=0;i<(int)V[Mid].size();i++)
				cout<<' '<<V[Mid][i];
			cout<<endl,cout<<flush;
			int u=read(),l=read();
			if(l==Len) lst=u,L=Mid;
			else R=Mid;
		}
		for(int i=1;i<=n;i++)
			V[i].clear();
		dep[lst]=0,DFS(lst,0);
		cout<<"? "<<V[Len].size();
		for(int i=0;i<(int)V[Len].size();i++)
			cout<<' '<<V[Len][i];
		cout<<endl<<flush;
		int w=read(),read();
		printf("! %d %d\n",lst,w);
		string s;
		cin>>s;
		//if(s!="Correct")
		//	exit(0);
	}
	return 0;
}


#include<set>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<climits>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long
int read(){
	int f=0,x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return !f?x:-x;
}
#define mp make_pair
const int MAXN=100000;
const int INF=0x3f3f3f3f;
int dep[MAXN+5],Max;
vector<int> G[MAXN+5],V[MAXN+5];
void DFS(int u,int fa){
	Max=max(Max,dep[u]);
	V[dep[u]].push_back(u);
	for(int i=0;i<(int)G[u].size();i++){
		int v=G[u][i];
		if(v==fa) continue;
		dep[v]=dep[u]+1,DFS(v,u);
	}
	return ;
}
int rt,Len;
int main(){
	int T=read();
	while(T--){
		Max=0;
		int n=read();
		for(int i=1;i<=n;i++)
			V[i].clear(),G[i].clear();
		for(int i=1;i<n;i++){
			int u=read(),v=read();
			G[u].push_back(v);
			G[v].push_back(u);
		}
		cout<<'?'<<' '<<n;
		for(int i=1;i<=n;i++)
			cout<<' '<<i;
		cout<<endl,cout<<flush;
		rt=read(),Len=read();
		dep[rt]=0,DFS(rt,0);
		int L=(Len+1)/2,R=min(Len,Max)+1,lst=rt;
		while(L+1<R){
			int Mid=(L+R)>>1;
			cout<<'?'<<' '<<V[Mid].size();
			for(int i=0;i<(int)V[Mid].size();i++)
				cout<<' '<<V[Mid][i];
			cout<<endl,cout<<flush;
			read();
			int l=read();
			if(l==Len) L=Mid;
			else R=Mid;
		}

		cout<<'?'<<' '<<V[L].size();
		for(int i=0;i<(int)V[L].size();i++)
			cout<<' '<<V[L][i];
		cout<<endl,cout<<flush;
		lst=read(),read();
		for(int i=1;i<=n;i++)
			V[i].clear();
		dep[lst]=0,DFS(lst,0);
		cout<<"? "<<V[Len].size();
		for(int i=0;i<(int)V[Len].size();i++)
			cout<<' '<<V[Len][i];
		cout<<endl<<flush;
		int w=read(),read();
		printf("! %d %d\n",lst,w);
		string s;
		cin>>s;
		//if(s!="Correct")
		//	exit(0);
	}
	return 0;
}


#include<set>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<climits>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long
int read(){
	int f=0,x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return !f?x:-x;
}
#define mp make_pair
const int MAXN=100000;
const int INF=0x3f3f3f3f;
int dep[MAXN+5],Max;
vector<int> G[MAXN+5],V[MAXN+5];
void DFS(int u,int fa){
	Max=max(Max,dep[u]);
	V[dep[u]].push_back(u);
	for(int i=0;i<(int)G[u].size();i++){
		int v=G[u][i];
		if(v==fa) continue;
		dep[v]=dep[u]+1,DFS(v,u);
	}
	return ;
}
int rt,Len;
int main(){
	int T=read();
	while(T--){
		Max=0;
		int n=read();
		for(int i=1;i<=n;i++)
			V[i].clear(),G[i].clear();
		for(int i=1;i<n;i++){
			int u=read(),v=read();
			G[u].push_back(v);
			G[v].push_back(u);
		}
		cout<<'?'<<' '<<n;
		for(int i=1;i<=n;i++)
			cout<<' '<<i;
		cout<<'\n',cout<<flush;
		rt=read(),Len=read();
		dep[rt]=0,DFS(rt,0);
		int L=(Len+1)/2-1,R=min(Len,Max)+1,lst=rt;
		while(L+1<R){
			int Mid=(L+R)>>1;
			cout<<'?'<<' '<<V[Mid].size();
			for(int i=0;i<(int)V[Mid].size();i++)
				cout<<' '<<V[Mid][i];
			cout<<'\n',cout<<flush;
			int u=read(),l=read();
			if(l==Len) lst=u,L=Mid;
			else R=Mid;
		}
		for(int i=1;i<=n;i++)
			V[i].clear();
		dep[lst]=0,DFS(lst,0);
		cout<<"? "<<V[Len].size();
		for(int i=0;i<(int)V[Len].size();i++)
			cout<<' '<<V[Len][i];
		cout<<'\n'<<flush;
		int w=read(),read();
		printf("! %d %d\n",lst,w);
		string s;
		cin>>s;
		//if(s!="Correct")
		//	exit(0);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=2001;
int he[maxn],ne[maxn<<1],to[maxn<<1],cnt,de[maxn],md,n;
#define addedge(x,y) ne[++cnt]=he[x],he[x]=cnt,to[cnt]=y
vector<int>dd[maxn];
void dfs(int x,int fa)
{
	de[x]=de[fa]+1;
	for(int i=he[x];i;i=ne[i])
	{
		if(to[i]==fa)continue;
		dfs(to[i],x);
	}
	de[x]--;
	dd[de[x]].push_back(x);
	md=max(md,de[x]);
}
void solve()
{
	cnt=0;md=0;
	cin>>n;
	for(int i=1;i<=n;i++)he[i]=0,dd[i].clear();
	for(int i=2;i<=n;i++)
	{
		int a,b;
		cin>>a>>b;
		addedge(a,b),addedge(b,a);
	}
	cout<<"? "<<n<<" ";
	for(int i=1;i<=n;i++)cout<<i<<" ";cout<<"\n";
	fflush(stdout);
	int rt,d;cin>>rt>>d;
	dfs(rt,0);
	int emm=0;
	int a,b,aa=rt;
	for(int i=10;i>=0;i--)
	{
		int em=emm+(1<<i);
		if(em>d)continue;
//		cout<<em<<"!!!\n";
        if(em<=d/2)emm=em;
		cout<<"? "<<dd[em].size()<<" ";
		for(int j=0;j<dd[em].size();j++)cout<<dd[em][j]<<" ";cout<<"\n";
		fflush(stdout);
		cin>>a>>b;
		if(b==d)emm=em,aa=a;
	}
//	cout<<emm<<"deafakioi\n";
	for(int i=1;i<=n;i++)dd[i].clear();
    a=aa;
	dfs(a,0);
	cout<<"? "<<dd[d].size()<<" ";
	for(int j=0;j<dd[d].size();j++)cout<<dd[d][j]<<" ";cout<<"\n";
	fflush(stdout);
    int x,y;
	cin>>x>>y;
	assert(y==d);
	cout<<"! "<<a<<" "<<x<<"\n";
	fflush(stdout);
	string dfk;
	cin>>dfk;
	return;
}
int main()
{
	int t;
	cin>>t;
	while(t--)solve();
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=2001;
int he[maxn],ne[maxn<<1],to[maxn<<1],cnt,de[maxn],md,n;
#define addedge(x,y) ne[++cnt]=he[x],he[x]=cnt,to[cnt]=y
vector<int>dd[maxn];
void dfs(int x,int fa)
{
	dd[de[x]].push_back(x);
	md=max(md,de[x]);
	for(int i=he[x];i;i=ne[i])
	{
		if(to[i]==fa)continue;
	    de[to[i]]=de[x]+1;
		dfs(to[i],x);
	}
}
void solve()
{
	cnt=0;md=0;
	cin>>n;
	for(int i=0;i<=n;i++)he[i]=0,dd[i].clear();
	for(int i=2;i<=n;i++)
	{
		int a,b;
		cin>>a>>b;
		addedge(a,b),addedge(b,a);
	}
	cout<<"? "<<n<<" ";
	for(int i=1;i<=n;i++)cout<<i<<" ";cout<<"\n";
	fflush(stdout);
	int rt,d;cin>>rt>>d;
	de[rt]=0;
	dfs(rt,0);
	int emm=0;
	int a,b,aa=rt,ndd=0;
	for(int i=10;i>=0;i--)
	{
		int em=emm+(1<<i);
		if(em>d||em>md)continue;
//		cout<<em<<"!!!\n";
        if(em<=d/2){emm=em;ndd=0;continue;}
		cout<<"? "<<dd[em].size()<<" ";
		for(int j=0;j<dd[em].size();j++)cout<<dd[em][j]<<" ";cout<<"\n";
		fflush(stdout);
		cin>>a>>b;
		if(b==d)emm=em,aa=a,ndd=1;
	}
//	cout<<aa<<"deafakioi\n";
	/*
	8
8 7
6 4
7 2
4 1
4 8
5 8
3 7
2 6
	*/
	if(ndd==0)
	{
		int em=emm;
		cout<<"? "<<dd[em].size()<<" ";
		for(int j=0;j<dd[em].size();j++)cout<<dd[em][j]<<" ";cout<<"\n";
		fflush(stdout);
		cin>>a>>b;
		if(b==d)emm=em,aa=a,ndd=1;
	}
	for(int i=0;i<=n;i++)dd[i].clear();
    a=aa;
    de[a]=0;
	dfs(a,0);
	cout<<"? "<<dd[d].size()<<" ";
	for(int j=0;j<dd[d].size();j++)cout<<dd[d][j]<<" ";cout<<"\n";
	fflush(stdout);
    int x,y;
	cin>>x>>y;
	assert(y==d);
	cout<<"! "<<a<<" "<<x<<"\n";
	fflush(stdout);
	string dfk;
	cin>>dfk;
	return;
}
int main()
{
	int t;
	cin>>t;
	while(t--)solve();
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=2001;
int he[maxn],ne[maxn<<1],to[maxn<<1],cnt,de[maxn],md,n;
#define addedge(x,y) ne[++cnt]=he[x],he[x]=cnt,to[cnt]=y
vector<int>dd[maxn];
void dfs(int x,int fa)
{
	de[x]=de[fa]+1;
	for(int i=he[x];i;i=ne[i])
	{
		if(to[i]==fa)continue;
		dfs(to[i],x);
	}
	de[x]--;
	dd[de[x]].push_back(x);
	md=max(md,de[x]);
}
void solve()
{
	cnt=0;md=0;
	cin>>n;
	for(int i=1;i<=n;i++)he[i]=0,dd[i].clear();
	for(int i=2;i<=n;i++)
	{
		int a,b;
		cin>>a>>b;
		addedge(a,b),addedge(b,a);
	}
	cout<<"? "<<n<<" ";
	for(int i=1;i<=n;i++)cout<<i<<" ";cout<<"\n";
	fflush(stdout);
	int rt,d;cin>>rt>>d;
	dfs(rt,0);
	int emm=0;
	int a,b,aa=rt;
	for(int i=10;i>=0;i--)
	{
		int em=emm+(1<<i);
		if(em>d)continue;
//		cout<<em<<"!!!\n";
        if(em<=d/2){emm=em;continue;}
		cout<<"? "<<dd[em].size()<<" ";
		for(int j=0;j<dd[em].size();j++)cout<<dd[em][j]<<" ";cout<<"\n";
		fflush(stdout);
		cin>>a>>b;
		if(b==d)emm=em,aa=a;
	}
//	cout<<emm<<"deafakioi\n";
	for(int i=1;i<=n;i++)dd[i].clear();
    a=aa;
	dfs(a,0);
	cout<<"? "<<dd[d].size()<<" ";
	for(int j=0;j<dd[d].size();j++)cout<<dd[d][j]<<" ";cout<<"\n";
	fflush(stdout);
    int x,y;
	cin>>x>>y;
	assert(y==d);
	cout<<"! "<<a<<" "<<x<<"\n";
	fflush(stdout);
	string dfk;
	cin>>dfk;
	return;
}
int main()
{
	int t;
	cin>>t;
	while(t--)solve();
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=2001;
int he[maxn],ne[maxn<<1],to[maxn<<1],cnt,de[maxn],md,n;
#define addedge(x,y) ne[++cnt]=he[x],he[x]=cnt,to[cnt]=y
vector<int>dd[maxn];
void dfs(int x,int fa)
{
	de[x]=de[fa]+1;
	for(int i=he[x];i;i=ne[i])
	{
		if(to[i]==fa)continue;
		dfs(to[i],x);
	}
	de[x]--;
	dd[de[x]].push_back(x);
	md=max(md,de[x]);
}
void solve()
{
	cnt=0;md=0;
	cin>>n;
	for(int i=1;i<=n;i++)he[i]=0,dd[i].clear();
	for(int i=2;i<=n;i++)
	{
		int a,b;
		cin>>a>>b;
		addedge(a,b),addedge(b,a);
	}
	cout<<"? "<<n<<" ";
	for(int i=1;i<=n;i++)cout<<i<<" ";cout<<"\n";
	fflush(stdout);
	int rt,d;cin>>rt>>d;
	dfs(rt,0);
	int emm=0;
	int a,b,aa=rt;
	for(int i=10;i>=0;i--)
	{
		int em=emm+(1<<i);
		if(em>md)continue;
//		cout<<em<<"!!!\n";
		cout<<"? "<<dd[em].size()<<" ";
		for(int j=0;j<dd[em].size();j++)cout<<dd[em][j]<<" ";cout<<"\n";
		fflush(stdout);
		cin>>a>>b;
		if(b==d)emm=em,aa=a;
	}
//	cout<<emm<<"deafakioi\n";
	for(int i=1;i<=n;i++)dd[i].clear();
    a=aa;
	dfs(a,0);
	cout<<"? "<<dd[d].size()<<" ";
	for(int j=0;j<dd[d].size();j++)cout<<dd[d][j]<<" ";cout<<"\n";
	fflush(stdout);
    int x,y;
	cin>>x>>y;
	assert(y==d);
	cout<<"! "<<a<<" "<<x<<"\n";
	fflush(stdout);
	string dfk;
	cin>>dfk;
	return;
}
int main()
{
	int t;
	cin>>t;
	while(t--)solve();
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=2001;
int he[maxn],ne[maxn<<1],to[maxn<<1],cnt,de[maxn],md,n;
#define addedge(x,y) ne[++cnt]=he[x],he[x]=cnt,to[cnt]=y
vector<int>dd[maxn];
void dfs(int x,int fa)
{
	de[x]=de[fa]+1;
	for(int i=he[x];i;i=ne[i])
	{
		if(to[i]==fa)continue;
		dfs(to[i],x);
	}
	de[x]--;
	dd[de[x]].push_back(x);
	md=max(md,de[x]);
}
void solve()
{
	cnt=0;md=0;
	cin>>n;
	for(int i=1;i<=n;i++)he[i]=0,dd[i].clear();
	for(int i=2;i<=n;i++)
	{
		int a,b;
		cin>>a>>b;
		addedge(a,b),addedge(b,a);
	}
	cout<<"? "<<n<<" ";
	for(int i=1;i<=n;i++)cout<<i<<" ";cout<<"\n";
	fflush(stdout);
	int rt,d;cin>>rt>>d;
	dfs(rt,0);
	int emm=0;
	int a,b;
	for(int i=10;i>=0;i--)
	{
		int em=emm+(1<<i);
		if(em>d)continue;
//		cout<<em<<"!!!\n";
		cout<<"? "<<dd[em].size()<<" ";
		for(int j=0;j<dd[em].size();j++)cout<<dd[em][j]<<" ";cout<<"\n";
		fflush(stdout);
		cin>>a>>b;
		if(b==d)emm=em;
	}
//	cout<<emm<<"deafakioi\n";
	for(int i=1;i<=n;i++)dd[i].clear();
    dfs(a,0);
	cout<<"? "<<dd[d].size()<<" ";
	for(int j=0;j<dd[d].size();j++)cout<<dd[d][j]<<" ";cout<<"\n";
	fflush(stdout);
    int x,y;
	cin>>x>>y;
	assert(y==d);
	cout<<"! "<<a<<" "<<x<<"\n";
	fflush(stdout);
	string dfk;
	cin>>dfk;
	return;
}
int main()
{
	int t;
	cin>>t;
	while(t--)solve();
}


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

const int MAXN = 1e3 + 30;

int n, k;
int b[MAXN], a[MAXN];
bool mark[MAXN];

int main(){
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> b[i];
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			if (!mark[j] && b[j] == 0){
				a[i] = j;
				mark[j] = 1;
				for (int w = 0; w < j; w++)
					if (w + k <= j)
						b[w]--;
				break;
			}
	for (int i = 0; i < n; i++)
		cout << a[i] + 1 << " ";
	cout << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int b[1005];
int main()
{
    int n,k;
    cin >> n >> k;
    for(int i=1;i<=n;i++) cin >> b[i];
    vector<int> v;
    for(int i=1;i<=n;i++)
        if(b[i]==0) v.emplace_back(i);
    for(int i=n;i>=1;i--) {
        if(b[i]==0) continue;
        int cnt=0,q=0;
        for(vector<int>::iterator x=v.begin();x!=v.end();x++) {
            if(cnt==b[i]) {v.insert(x,i); q=1; break;}
            if(i+k<=(*x)) cnt++;
        }
        if(q==0&&cnt==b[i]) v.emplace_back(i);
        //printf("%d %d\n",i,cnt);
        //for(auto x : v) printf("%d ",x);
       //printf("\n");

    }
    for(auto x : v) printf("%d ",x);
}


#include <bits/stdc++.h>
#include <pthread.h>
#include <ext/rope>

#define L(a) (int)((a).size())
#define sqr(x) ((x) * 1ll * (x))
#define vi vector<int>
#define mp make_pair
#define pub push_back
#define pob pop_back
#define ii pair<int, int>
#define vii vector <ii>
#define all(s) (s).begin(),(s).end()
#define allb(s,b) (s).begin()+b,(s).end()
#define rall(s) (s).rbegin(),(s).rend()
#define fore(i, l ,r) for(int i = (int)l; i <= (int)r; i++)
#define forn(i, l ,r) for(int i = (int)l; i >= (int)r; i--)
#define TRACE(x) cout << #x << " : " << x << endl
#define _ << " - " <<

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

int n,k;
int a[1005];
int b[1005];
int main(){
	cin>>n>>k;
	fore(i,1,n) cin>>b[i];
	fore(i,1,n)
	{
		int x = n;
		fore(j,1,n)
		{
			if(b[j]==0)
			{
				a[i]=j;
				b[j] = -1;
				x = j;
				break;
			}
		}
		forn(z,x-k,1)
			b[z]--;
	}
	cout<<a[1];
	fore(i,2,n) cout<<" "<<a[i];
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 50;
int a[maxn], b[maxn];
int main()
{
    std::ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    for(int i = 1;i <= n;i++) cin >> b[i];
    for(int i = 1;i <= n;i++)
    {
        int now = 1;
        while(b[now] != 0) now++;
        a[i] = now;
        b[now]--;
        for(int j = 1;j <= now - k;j++) b[j]--;
    }
    for(int i = 1;i <= n;i++) cout << a[i] << " ";
    return 0;
}


#include <cstdio>
#include <cstring>
#include <cassert>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using pll = pair<ll, ll>;

const int N = 1010;
int a[N], b[N], n, k;

int findZero () {
	for (int i = 1; i <= n; i++) if (!b[i])
		return i;
	return -1;
}

int main() {
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
	for (int i = 1; i <= n; i++) {
		int t = findZero();
		assert(t != -1);
		b[t] = -1;
		a[i] = t;
		for (int j = 1; j <= t - k; j++) b[j]--;
	}
	for (int i = 1; i <= n; i++) printf("%d ", a[i]);
	printf("\n");
}


#include <bits/stdc++.h>
using namespace std;
int main()	{
	int n,k;
	cin>>n>>k;
	int a[1010];
	for(int i=0;i<n;i++)	{
		cin>>a[i];
	}
	for(int i=0;i<n;i++)	{
		int j;
		for(j=0;j<n;j++)	{
			if(!a[j])	{
				break;
			}
		}
		cout<<j+1<<" ";
		a[j]=-1;
		for(int p=0;p<=j-k;p++)	{
			a[p]--;

		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

int n, k;
vector<int> b;
vector<int> final;

int find(int v, int qt){
	for (int i = 0; i < final.size(); ++i)
	{
		if(v <= final[i])
			qt--;
		if(qt == 0){
			// cout << v << " " << qt << " " << i << endl;
			return i;
		}
	}
	cout << "PANIC\n";
	return 0;
}

int main() {
	cin >> n >> k;

	b.resize(n+1);
	for (int i = 1; i <= n; ++i)
	{
		cin >> b[i];
	}

	int i = n;
	while (i > 0) {
		if(i + k > n)
			final.insert(final.begin(), i);
		else{
			int idx = find(i+k, b[i]);
			if(b[i] == 0)
				final.insert(final.begin(), i);
			else
				final.insert(final.begin() + idx+1, i);
		}
		i--;
		// for (int i = 0; i < final.size(); ++i)
		// {
		// 	cout << final[i] <<  " ";
		// }
		// cout << endl << "$" << endl;
	}
	for (int i = 0; i < final.size(); ++i)
	{
		cout << final[i] <<  " ";
	}
	cout << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

int n, k;
vector<int> b;
vector<int> final;

int find(int v){
	for (int i = 0; i < final.size(); ++i)
	{
		if(v <= final[i])
			return i;
	}
	cout << "PANIC\n";
	return 0;
}

int main() {
	cin >> n >> k;

	b.resize(n);
	for (int i = 1; i <= n; ++i)
	{
		cin >> b[i];
	}

	int i = n;
	while (i > 0) {
		if(i + k > n)
			final.insert(final.begin(), i);
		else{
			int idx = find(i+k);
			if(b[i] == 0)
				final.insert(final.begin(), i);
			else
				final.insert(final.begin() + idx + b[i], i);
		}
		i--;
		// for (int i = 0; i < final.size(); ++i)
		// {
		// 	cout << final[i] <<  " ";
		// }
		// cout << endl << "$" << endl;
	}
	for (int i = 0; i < final.size(); ++i)
	{
		cout << final[i] <<  " ";
	}
	cout << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

int n, k;
vector<int> b;
vector<int> final;

int find(int v, int qt){
	for (int i = 0; i < final.size(); ++i)
	{
		if(v <= final[i])
			qt--;
		if(qt == 0){
			// cout << v << " " << qt << " " << i << endl;
			return i;
		}
	}
	cout << v << " " << qt << " PANIC\n";
	return 0;
}

int main() {
	cin >> n >> k;

	b.resize(n+1);
	for (int i = 1; i <= n; ++i)
	{
		cin >> b[i];
	}

	int i = n;
	while (i > 0) {
		if(i + k > n)
			final.insert(final.begin(), i);
		else{
			if(b[i] == 0)
				final.insert(final.begin(), i);
			else{
				int idx = find(i+k, b[i]);
				final.insert(final.begin() + idx+1, i);
			}
		}
		i--;
		// for (int i = 0; i < final.size(); ++i)
		// {
		// 	cout << final[i] <<  " ";
		// }
		// cout << endl << "$" << endl;
	}
	for (int i = 0; i < final.size(); ++i)
	{
		cout << final[i] <<  " ";
	}
	cout << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rep(i,l,r) for(int i=(l);i<(r);++i)
#define per(i,l,r) for(int i=(r)-1;i>=(l);--i)
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl
const int N = 1e3 + 7;
int n, k, b[N];
void solve() {
	rep(i, 1, n + 1) scanf("%d", &b[i]);
	priority_queue<int> stk;
	rep(i, 1, n + 1) if (!b[i]) stk.push(-i);
	rep(i, 1, n + 1) {
		int u = -stk.top(); stk.pop();
		printf("%d%c", u, " \n"[i == n]);
		rep(j, 1, u - k + 1) if (!--b[j]) stk.push(-j);
	}
}
int main() {
	while (~scanf("%d%d", &n, &k)) solve();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define int long long
#define endl '\n'
#define N 100000
#define pi acos(-1)
#define tora acos(-1)/180
#define tode 180/acos(-1)
typedef pair < int, int > ii;
typedef vector < int > vi;
typedef vector < vi > vii;
int mod = 1000000007 ;
int f[1009], cur, ans[1009], n, k;
signed main()
{
	ios_base::sync_with_stdio(0);
	cin >> n >> k;
	for(int i = 1; i <= n; i++)
		cin >> f[i];
	for(int i = n; i > 0; i--)
	{
		cur = 0;
		for(int j = 1; j <= n; j++)
		{
			if(cur > f[i] || (cur == f[i] && ans[j] > i))
			{
				ans[j - 1] = i;
				break;
			}
			else
				ans[j - 1] = ans[j];
			if(j == n)
				ans[j] = i;
			if(ans[j] >= i + k)
				cur ++;
		}
	}
	for(int i = 1; i <= n; i++)
		cout << ans[i] << ' ';
}


#include <bits/stdc++.h>

using namespace std;

int n, k, b[1010], pos;

int main() {
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> b[i];
    }
    for (int i = 1; i <= n; i++) {
        for (int i1 = 1; i1 <= n; i1++) {
            if (b[i1] == 0) {
                pos = i1;
                break;
            }
        }
        b[pos] = -1e9;
        cout << pos << " ";
        for (int i1 = 1; i1 <= n; i1++) {
            if (i1 + k <= pos && b[i1] > 0) {
                b[i1]--;
            }
        }
     }
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;

const int NMAX = 1010;
int n, k;
int a[NMAX], nxt[NMAX], b[NMAX];

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    cin >> n >> k;
    for(int i=1;i<=n;++i) {
        cin >> b[i];
    }
    int sz = 1;
    int cur = 0;
    for(int i=n;i>0;--i) {
        int seen = 0;
        int prev = cur;
        while(seen < b[i]) {
            prev = nxt[prev];
            seen += a[prev] >= k+i;
        }
        nxt[sz] = nxt[prev];
        nxt[prev] = sz;
        a[sz] = i;
        ++sz;
    }
    cur = nxt[cur];
    while(cur != 0) {
        cout << a[cur] << " ";
        cur = nxt[cur];
    }
    cout << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string.h>
#include <limits.h>
#include <cfloat>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <cassert>
using namespace std;
#define mem(flag) memset(flag,0,sizeof(flag))
#define Mem(flag) memset(flag,-1,sizeof(flag))
#define read(a) a=getInt()
#define En printf("\n")
#define P(a) printf("%d ",a)
#define Pn(a) printf("%d\n",a)
#define dbg(x) cout << (#x) << " = " << (x) << endl
#define rep(flag, a, b) for (int flag = (a); flag <= (b); ++flag)
#define Rep(flag, a, b) for (int flag = (a); flag >= (b); --flag)

const int MAX = 1020;

struct List1 {
    struct node {
        int key, prev, nxt;
        node() {}
        node(int a, int b, int c) : key(a), prev(b), nxt(c) {}
    };
    node an[MAX];
    int front, tail, cnt;
    List1() { front = tail = -1, cnt = 0; }
    bool isEmpty() { return front == -1; }
    void insert_b(int pos, int key) { // insert behind node[pos],
        int idx = cnt; ++cnt, an[idx].key = key;
        an[idx].nxt = an[pos].nxt, an[idx].prev = pos;
        if (an[pos].nxt != -1) an[an[pos].nxt].prev = idx;
        an[pos].nxt = idx;
        if (an[idx].nxt == -1) tail = idx;
    }
    void push_front(int key) {
        int idx = cnt; ++cnt, an[idx].key = key;
        if (front == -1) {
            an[idx].nxt = an[idx].prev = -1, front = tail = idx;
        } else {
            an[idx].prev = -1, an[idx].nxt = front, an[front].prev = idx;
            front = idx;
        }
    }
    int getK(int idx) { return an[idx].key; }
};

List1 ans;
int bn[MAX];
int n, k;

int main() {
    scanf("%d%d", &n, &k);
    rep (i, 1, n) scanf("%d", &bn[i]);
    ans.push_front(n);
    Rep (i, n - 1, 1) {
        int t1 = i + k, t2 = n - t1 + 1;
        if (t2 <= 0) ans.push_front(i);
        else {
            int bound = t2 - bn[i];
            int idx = ans.tail;
            while (!(bound == 0 && (idx == -1 || ans.getK(idx) >= t1))){
                if (ans.getK(idx) >= t1) bound--, idx = ans.an[idx].prev;
                else idx = ans.an[idx].prev;
            }
            if (idx == -1) ans.push_front(i);
            else ans.insert_b(idx, i);
        }
    }
    for (int idx = ans.front; idx != -1; idx = ans.an[idx].nxt) printf("%d ", ans.getK(idx));
    printf("\n");
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>

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

  int n, k;
  std::cin >> n >> k;

  std::vector<int> B(n), ans(n);
  for (int i = 0; i < n; i++)
    std::cin >> B[i];

  for (int i = 0; i < n; i++) {
    int best = std::find(B.begin(), B.end(), 0) - B.begin();
    B[best] = -1, ans[i] = best;
    for (int j = 0; j <= best - k; j++)
      B[j]--;
  }

  for (int v : ans)
    std::cout << v + 1 << ' ';
  std::cout << '\n';

  return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>

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

  int n, k;
  std::cin >> n >> k;

  std::vector<int> B(n), ans(n);
  for (int i = 0; i < n; i++)
    std::cin >> B[i];

  for (int i = 0; i < n; i++) {
    int best = std::min(std::find(B.begin(), B.end(), 0) - B.begin(), n - 1);
    B[best] = -1, ans[i] = best;
    for (int j = 0; j <= best - k; j++)
      B[j]--;
  }

  for (int v : ans)
    std::cout << v + 1 << ' ';
  std::cout << '\n';

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a; i<=b; i++)
#define repr(i,a,b) for(int i=a; i>=b; i--)
#define fi first
#define se second
#define ll long long
#define endl "\n"
#define pb push_back
#define ii pair <int, int>
#define all(a) a.begin(), a.end()
#define mod 998244353ll
#define ma 2750135
#define bit(i) (i & (-i))
#define base 2750135

void process(){
    int n, k;
    cin>>n>>k;
    vector <int> a(n);
    for(int &i:a) cin>>i;
    vector <int> ans;
    repr(i,n-1,0){
        int t= i+k+1;
        int j =0;
        for(;j<ans.size() && a[i]; j++){
            if(ans[j]>=t) a[i]--;
        }
        ans.insert(ans.begin() + j, i+1);
    }
    for(int i:ans) cout<<i<<' ';
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
//	freopen("Test.inp", "r", stdin);
//	freopen("Test.out", "w", stdout);
    int t=1;
//    cin>>t;
    while(t--){
        process();
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

ifstream in("restoration_of_the_permutation.in");
ofstream out("restoration_of_the_permutation.out");

int main()
{
    int n, k, nr;
    cin >> n >> k;
    nr = n;

    vector<int> B(n + 1);

    for (int i = 1; i <= n; i++)
        cin >> B[i];

    while(nr)
    {
        for (int i = 1; i <= n; i++)
            if (B[i] == 0)
        {
            nr--;
            cout << i << ' ';
            B[i] = -1;

            for (int j = 1; j <= i - k; j++)
                B[j]--;

            break;
        }
    }

    return 0;
}


#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

ifstream in("restoration_of_the_permutation.in");
ofstream out("restoration_of_the_permutation.out");

int main()
{
    int n, k, nr;
    cin.sync_with_stdio(false);
    cin >> n >> k;
    nr = n;

    vector<int> B(n + 1);

    for (int i = 1; i <= n; i++)
        cin >> B[i];

    while(nr)
    {
        for (int i = 1; i <= n; i++)
            if (B[i] == 0)
        {
            nr--;
            cout << i << ' ';
            B[i] = -1;

            for (int j = 1; j <= i - k; j++)
                B[j]--;

            break;
        }
    }

    return 0;
}


#include <iostream>
using namespace std;

const int Maxn = 1001;

int n, k, b[Maxn], a[Maxn];

int main()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> b[i];
    for (int i = 1; i <= n; i++) {
        int take;
        for (int j = 1; j <= n; j++) if (b[j] == 0) { b[j]--; take = j; break; }
        for (int j = 1; j <= n; j++) if (take >= j + k) b[j]--;
        a[i] = take;
    }
    for (int i = 1; i <= n; i++) {
        if (i > 1) cout << " ";
        cout << a[i];
    }
    cout << endl;
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
    int a[1005],b[1005];
    int n,k;
    while(scanf("%d%d",&n,&k)==2)
    {
        for(int i=1;i<=n;i++) scanf("%d",b+i);

        for(int i=1;i<=n;i++)
		{
            int cur=1;
            while(b[cur]!=0) cur++;  //找最近的0；
            a[i]=cur;
            b[cur]--;  //将放进了a中的数cur，变成b[cur]=-1,这样就标记了。
            for(int j=1;j+k<=cur;j++) b[j]--; //更新b数组。
        }

        for(int i=1;i<=n;i++) printf(i!=n?"%d ":"%d\n",a[i]);
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int res[1010];
int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)scanf("%d",&res[i]);

    for(int i=1,j;i<=n;i++){
        for(j=1;j<=n;j++)if(!res[j])break;
        printf("%d%c",j,i==n?'\n':' ');
        for(int q=1;q<=j-k;q++)res[q]--;
        res[j]--;
    }
}


#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define ll long long
//#define ll unsigned long long
#define inf 0x3f3f3f3f
#define mod 1000000007
#define eps 1e-6
#define pi acos(-1)
#define mea (memset(a,0,sizeof(a)))
#define myit set<ll>::iterator
#define mysets multiset<ll>
#define myits multiset<ll>::iterator
#define v30 (1<<30)-1
#define all(x) (x).begin(),(x).end()
#define maxs *s.rbegin()
#define fi first
#define se second
#define lowbit(x) (x&(-x))
#define mid ((a[k].r+a[k].l)>>1)
#define lson k<<1,l,mid
#define rson k<<1|1,mid+1,r
#define kl k<<1
#define kr k<<1|1
using namespace std;
inline ll read(){
   ll s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
void put1(){ puts("Yes") ;}
void put2(){ puts("No") ;}
void put3(){ puts("-1"); }
ll gcd(ll a,ll b){ return b==0?a:gcd(b,a%b);}
using namespace std;

const int manx=2e5+10;

ll a[manx],b[manx];

int main()
{
    ll n=read(),k=read();
    for(int i=1;i<=n;i++) b[i]=read();
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(b[j]==0){
                a[i]=j;
                b[j]=-1;
                for(int l=1;l+k<=j;l++)
                    if(b[l])b[l]--;
                break;
            }
        }
    }
    for(int i=1;i<=n;i++)
        printf("%lld ",a[i]);
    return 0;
}


// g++ -std=c++14

/*

Today might be the chance to grasp the chance to let your talent bloom.
May be tomorrow, the day after, or next year...
May be even when you are 30. I'm not sure if physique has anything to do with it
but if you think that it will never come, it probably never will.

- Tooru Oikawa.

*/

#include<bits/stdc++.h>

typedef long long ll;
typedef long double lld;
using namespace std;

#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define endl "\n"
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define LET(x, a)  __typeof(a) x(a)
#define foreach(it, v) for(LET(it, v.begin()); it != v.end(); it++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define all(c) c.begin(),c.end()
#define inf 1000000000000000001

#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)

template<typename S, typename T>
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.fi<<", "<<p.se<<')';return out;}

template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
ll l=v.size();for(ll i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}

template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

#define int ll

const int N = 2e4;

int arr[N], brr[N], n, k;

void insrt(int no, int pos){
    int temp1 = no;
    int temp2 = arr[pos];
    for(int i = pos; i <= n; i++){
        arr[i] = temp1;
        temp1 = temp2;
        temp2 = arr[i+1];
    }
}

int32_t main(){ _
    cin >> n >> k;
    for(int i = 1; i <= n; i++){
        cin >> brr[i];
    }
    arr[1] = n;
    for(int i = n-1; i >= 1; i--){
        int req = brr[i];
        int curp = 1;
        while(req > 0){
            if(arr[curp] >= i + k){
                req--;
            }
            curp++;
        }
        insrt(i, curp);
    }
    for(int i = 1; i <= n; i++){
        cout << arr[i] << " ";
    }cout << endl;
}


#include <iostream>
#include <vector>
using namespace std;

int ar[200000];
int n, k;
bool used[200000];
vector <int> answer;

int find_zero() {
    for (int i = 0; i < n; ++i) {
        if ((!used[i]) && (ar[i] == 0)) return i;
    }
}

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> ar[i];
    }
    for (int i = 0; i < n; ++i) {
        int index = find_zero();
        answer.push_back(index + 1);
        used[index] = true;
        for (int j = 0; j <= index - k; ++j) {
            --ar[j];
        }
//        cout << "(" << index + 1 << ")\n";
//        for (int j = 0; j < n; ++j) {
//            cout << ar[j] << " ";
//        }
//        cout << endl;
    }
    for (int i = 0; i < n; ++i) {
        cout << answer[i] << " ";
    }
}


/*
  GOOD is not Enough
  You've got to be GREAT.
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
// #include<boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define mod 1000000007
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n) for(int i=0;i<n;i++)
#define fp(i,k,n) for(int i=k;i<=n;i++)
#define fr(i,k,n) for(int i=k;i>=n;i--)
#define pb push_back
#define pii pair<int,int>
#define dbg(x) cout << (#x) << " is " << (x) << '\n'
#define F first
#define S second
#define sz(x) (int)(x).size()
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

void solve()
{
  int n,k;
  cin >> n >> k;
  int a[n];
  f(i,n)
    cin >> a[i];
  f(i,n)
  {
      f(j,n)
      {
          if(a[j]==0)
          {
              a[j]=-1;
              f(l,j-k+1)
                a[l]--;
              cout << j+1 << " ";break;
          }
      }
  }
  cout << '\n';
  return;
}

signed main()
{
  FAST
  int T=1;
  // cin >> T;
  while(T--)
  {
    solve();
  }
  return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int main()
{
    cin.sync_with_stdio(false);
    cin.tie(0);

    int n, k;
    cin>>n>>k;

    vector<int> v(n);
    for(int i = 0; i < n; i++)
        cin>>v[i];

    for(int i = 0; i < n; i++)
    {
        int ind = -1;
        for(int j = 0; j < n && ind == -1; j++)
            if(v[j] == 0)
                ind = j;

        cout<<ind+1<<" ";

        v[ind] = -1;
        for(int j = 0; j < ind-k+1; j++)
            v[j]--;
    }
    cout<<"\n";

    return 0;
}


// g++ -std=c++14
#include<bits/stdc++.h>
typedef long long int lli;
typedef long double lld;
using namespace std;

#define sd(x) scanf("%d",&x);
#define sd2(x,y) scanf("%d%d",&x,&y);
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z);

#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

#define LET(x, a)  __typeof(a) x(a)
#define foreach(it, v) for(LET(it, v.begin()); it != v.end(); it++)
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

int main(){
  _
  int n,k;
  cin >> n >> k;
  int B[n+1];
  vector<int>used(n+1,0);
  vector<int>some(n+1,0);
  vector<int>ans(n+1,0);
  for(int i=1;i<=n;i++){
    cin >> B[i];
  }
  for(int ind=1;ind<=n;ind++){
    for(int i=1;i<=n;i++){
      if(used[i]==0){
        if(some[i]==B[i]){
          ans[ind] = i;
          used[i] = 1;
          for(int j=1;j<=i-k;j++){
            some[j]++;
          }
          break;
        }
      }
    }
  }
  for(int i=1;i<=n;i++){
    cout << ans[i] << " ";
  }
  cout << "\n";
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define AMR std::ios::sync_with_stdio(false);cin.tie(NULL);
int main()
{
    AMR;
    int n,p;
    cin>>n>>p;
    vector<int>v(n+1);
    for(int i=1 ; i<=n; i++)
        cin>>v[i];
    vector<set<int > >vs(n+2);
    set<int>st;
    // deque<int>dq;
    vector<int >v1,v2;
    for(int k=n; k>=1; k--)
    {

        if(v[k]==0)
        {
            v2.push_back(k);
            for(int i=0; i<v1.size(); i++)
                v2.push_back(v1[i]);
            v1.clear();
            v1=v2;
            v2.clear();
//
        }

        else
        {
            int x=k+p;
//cout<<x<<endl;
int f=1;
            for(int i=0; i<v1.size(); i++)
            {

                if(v[k]>0 && v1[i]>=x)
                {
                    v2.push_back(v1[i]);
                    //v2.push_back(k);
                    v[k]--;
                }
                else
                {
                    v2.push_back(v1[i]);
                }
                if(v[k]==0 && f) {v2.push_back(k);
                f=0;}
            }
            v1.clear();
            v1=v2;
            v2.clear();
           // if(k==2)for( auto x:v1)cout<<x<<" ";
            //cout<<endl;
        }

    }
    for(int i=0; i<v1.size(); i++ )
        cout<<v1[i]<<" ";

}


#include<bits/stdc++.h>

using namespace std;

#define x first
#define y second
#define y0 hi1
#define y1 hi2
#define ll long long
#define mp make_pair
#define pb push_back
#define sqr(a) (a)*(a)
#define ld long double
#define all(a) (a).begin(), (a).end()

using namespace std;

const int inf=2e9;
const int N=1001;

int n, k, b[N], a[N], s;

main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin>>n>>k;
    for(int i=0; i<n; i++)
        cin>>b[i];
    for(int i=0; i<n; i++)
    {
        int s=0;
        for(int j=0; j<n; j++)
            if(b[j]==0)
            {
                s=j+1;
                break;
            }
        if(!s)return 1;
        b[s-1]=inf;
        cout<<s<<" ";
        for(int j=1; j<=n; j++)
            if(j+k<=s)b[j-1]=max(b[j-1]-1, 0);
    }
}


#include <iostream>
#include <vector>

using namespace std;

int b[1000]={0};
vector<int> a;

int main() {
    int n, k; cin >> n >> k;
    for (int i=0; i<n; i++) cin >> b[i];

    //Eloszor aminel mindegy:
    for (int i=n-1; i>=n-k; i--) a.insert(a.begin(), i);
    for (int i=n-k-1; i>=0; i--) {
        if (b[i]==0) {
            a.insert(a.begin(), i);
            continue;
        }
        int howmany=0;
        for (int j=0; j<a.size(); j++) {
            if (a[j]>=(i+k)) {
                howmany++;
                if (howmany==b[i]) {
                    a.insert(a.begin()+j+1, i);
                    break;
                }
            }
        }
    }

    for (int j=0; j<n; j++) cout << a[j]+1 << ' '; //converting indexes
    cout << endl;

    return 0;
}


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

int cnt[1005], ans[1005];
int N, K;

int main() {
//  freopen("inp", "r", stdin);
  scanf("%d %d", &N, &K);
  for(int i = 1; i <= N; i++) {
    scanf("%d", &cnt[i]);
  }
  for(int i = 1; i <= N; i++) {
    for(int j = 1; j <= N; j++) {
      if(!ans[i] && cnt[j] == 0) {
        ans[i] = j;
        cnt[j]--;
        for(int k = 1; k <= j - K; k++)cnt[k]--;
        break;
      }
    }
  }
  for(int i = 1; i <= N; i++)
    printf("%d " , ans[i]);
}


#include <bits/stdc++.h>

#define INF_MAX 2147483647
#define INF_MIN -2147483647
#define INF_LL 9223372036854775807LL
#define INF 1000000000
#define PI acos(-1)
#define EPS 1e-8
#define LL long long
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define setzero(a) memset(a,0,sizeof(a))
#define setdp(a) memset(a,-1,sizeof(a))
#define bits(a) __builtin_popcount(a)

using namespace std;

int arr[1005];

int main()
{
  int n, k;
  cin >> n >> k;
  for(int i=0;i<n;i++)
    scanf("%d", &arr[i]);
  vector<int> v1, v2;
  for(int i=0;i<k;i++)
    v1.pb(n - i);
  reverse(v1.begin(), v1.end());
  for(int i=k;i<n;i++)
  {
    int cnt = 0;
    bool done = false;
    for(int j=0;j<v1.size();j++)
    {
      if(!done && cnt == arr[n - i - 1])
        v2.pb(n - i), done = true;
      if(n - i + k <= v1[j])
        cnt++;
      v2.pb(v1[j]);
    }
    if(!done) v2.pb(n - i);
    v1 = v2;
    v2.clear();
  }
  for(int i=0;i<n;i++)
    printf("%d ", v1[i]);
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1010;
const int BS = 5;

int n, k, a[N];
bool f[N];
int b[N];
int u[N];

void modify(int x, int v) {
  for (x += BS; x < N; x += x & -x)
    u[x] += v;
}

int getsum(int x) {
  int s = 0;
  for (x += BS; x; x -= x & -x)
    s += u[x];
  return s;
}

int check(int i) {
  if (i + k > n) return b[i] == 0;
  return getsum(n) - getsum(i + k - 1) == b[i];
}

int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", b + i);
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (f[j]) continue;
      if (check(j)) {
        a[i] = j;
        f[j] = 1;
        modify(j, 1);
        break;
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    printf("%d%c", a[i], " \n"[i == n - 1]);
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1010;
const int BS = 5;

int n, k, a[N];
bool f[N];
int b[N];
int u[N];

void modify(int x, int v) {
  for (x += BS; x < N; x += x & -x)
    u[x] += v;
}

int getsum(int x) {
  int s = 0;
  for (x += BS; x; x -= x & -x)
    s += u[x];
  return s;
}

int check(int i) {
  return getsum(n) - getsum(i + k - 1) == b[i];
}

int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", b + i);
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (f[j]) continue;
      if (check(j)) {
        a[i] = j;
        f[j] = 1;
        modify(j, 1);
        break;
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    printf("%d%c", a[i], " \n"[i == n - 1]);
  }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[1009],n,k;
int main()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<=n;i++)
    {
        int j;
    	for(j=1;j<=n;j++) if(!a[j])break;
    	cout<<j<<' ';
    	for(int q=1;q<=j-k;q++) a[q]--;
	    a[j]--;
    }
}


#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>

using namespace std;

const int MAXN = 1e3 + 30;

int n, k;
int b[MAXN], a[MAXN];
bool mark[MAXN];

int main(){
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> b[i];
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			if (!mark[j] && b[j] == 0){
				a[i] = j;
				mark[j] = 1;
				for (int w = 0; w < j; w++)
					if (w + k <= j)
						b[w]--;
				break;
			}
	for (int i = 0; i < n; i++)
		cout << a[i] + 1 << " ";
	cout << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[1001],b[1001];
int main()
{
    int n,k;
    while (scanf("%d%d",&n,&k)==2)
    {
        for (int i=1;i<=n;i++)
        {
            cin>>b[i];
        }
        for (int i=1;i<=n;i++)
        {
            int cur=1;
            while (b[cur]!=0)
            {
                cur++;
            }
            a[i]=cur;
            b[cur]--;
            for (int j=1;j+k<=cur;j++)
            {
                b[j]--;
            }
        }
        for (int i=1;i<=n-1;i++)
        {
            cout<<a[i]<<" ";
        }
        cout<<a[n]<<endl;
    }
    return 0;
}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <cassert>

using namespace std;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int n, k;
int b[1000];
vector<int> ans;

int main() {
    scanf("%d%d", &n, &k);
    REP(i, n) scanf("%d", b + i);
    for (int i = n - 1; i >= 0; --i) {
        int pos = 0, x = b[i];
        while (x) {
            if (ans[pos] >= i + k) --x;
            ++pos;
        }
        ans.insert(ans.begin() + pos, i);
    }
    REP(i, n) printf("%d ", ans[i] + 1);
    printf("\n");
    return 0;
}


#include<bits/stdc++.h>
#define M 1000
using namespace std;
int b[M + 5] , used[M + 5] , n , k;
vector < int > all;
main(){
    scanf("%d %d",&n,&k);
    for(int i = 1 ; i <= n ; i++)   scanf("%d",&b[i]);
    for(int i = 1 ; i <= n ; i++){
        int id = 1e9;
        for(int j = 1 ; j <= n ; j++)   if(!used[j] && b[j] == 0 && j < id) id = j;
        used[id] = true;    all.push_back(id);
        for(int j = 1 ; j <= n ; j++)   if(!used[j] && id >= j + k) b[j]--;
    }
    for(int i = 0 ; i < all.size() ; i++)   printf("%d ",all[i]);
}


#include<bits/stdc++.h>
using namespace std;
int n,minn,a[2000005];
void read(){scanf("%d\n",&n);}
void work(){
	minn=a[1];
	for(int i=2;i<=n;i++){
		char ch;
		ch=getchar();
		if(ch=='L') a[i]=a[i-1]-1;
		else if(ch=='R') a[i]=a[i-1]+1;
		else a[i]=a[i-1];
		minn=min(minn,a[i]);
	}
}
void print(){
	for(int i=1;i<=n;i++)
		printf("%d ",a[i]-(minn)+1);
}
int main(){
	read();
	work();
	print();
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>

using namespace std;

int main()
{
    int n,k;
    int i,j,t;
    int a[1010],b[1010];
    while(cin>>n>>k)
    {
        for(i=1;i<=n;i++)
        {
            cin>>a[i];
        }
        for(i=1;i<=n;i++)
        {
            j=1;
            while(a[j]!=0)
            {
                j++;
            }
            b[i]=j;
            a[j]--;
            for(t=1;t+k<=j;t++)
            {
                a[t]--;
            }
        }
        for(i=1;i<n;i++)
        {
            cout<<b[i]<<' ';
        }
        cout<<b[n]<<endl;
    }
    return 0;
}


#include <iostream>
#include <vector>
using namespace std;

const int nmax = 1e3 + 10;
const int infi = 1e9;
int main() {
    int n, k, b[nmax];
    scanf("%d%d", &n, &k);
    for(int i = 1; i <= n; ++i) {
        scanf("%d", b + i);
    }
    vector<int> a (1, infi);
    for(int i = n; i >= 1; --i) {
        int rem = b[i];
        int lim = i + k;
        for(auto it = a.begin(); it != a.end(); ++it) {
            if(rem == 0) {
                a.insert(it, i);
                break;
            }
            else if(*it >= lim) --rem;
        }
    }
    for(int i = 0; i < n; ++i) {
        printf("%d ", a[i]);
    }
    printf("\n");
}


#include <bits/stdc++.h>
#define P(x,y) make_pair(x,y)
using namespace std;
const int MX=(1009) , INF=(1<<29);
int n , K ;
vector < int > sol;
void insert_(vector < int >&v , int key ,  int pos){
    vector < int > nv;
    for(int j=0;j<pos;j++) nv.push_back(v[j]);
    nv.push_back(key);
    for(int j=pos;j<v.size();j++) nv.push_back(v[j]);
    v.clear();
    for(auto oo : nv) v.push_back(oo);
}
int arr[MX];
int main(){
    #ifndef ONLINE_JUDGE
    freopen("in.in","r",stdin);
    #endif // ONLINE_JUDGE
    cin>>n>>K;
    for(int j=1;j<=n;j++) cin>>arr[j];
    for(int j = n-K+1; j<=n; j++) sol.push_back(j);
    for(int cur = n-K; cur ; cur--){
        int cnt=0;
        if(arr[cur] == 0){
            insert_(sol , cur , 0);
            continue;
        }
        for(int j=0;j<sol.size();j++){
            if(sol[j] - K >= cur)
                cnt++;
            if(cnt == arr[cur]){
                insert_(sol , cur , j+1);
                break;
            }
        }
    }
    for(auto pp : sol) cout<<pp<<' ';
}


#include <iostream>
#include <assert.h>
#include <math.h>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <sstream>

using namespace std;
#define int long long
#define endl "\n"
#define ull unsigned long long
#define mp make_pair
inline int in() {int32_t x ; scanf("%d",&x) ; return x ; }
inline string getStr() {char ch[1000000] ; scanf("%s",ch) ; return ch ; }
inline char getCh() {char ch ; scanf(" %c",&ch) ; return ch;}
template<class P, class Q> inline P smin(P &a, Q b) { if (b < a) a = b; return a; }
template<class P, class Q> inline P smax(P &a, Q b) { if (a < b) a = b; return a; }
const int MOD = 1e9 + 7;
const int MAX_N = 1e6 + 10;
const int MAX_LG = 21;
const int base = 29;
const int MAX_DIF = 2001;
typedef pair<int , int > pii;
bool mark[MAX_N] ; int  a[MAX_N];
priority_queue<int> pq;
int32_t main()
{
    int n = in() , k = in();
    for (int i = 0 ; i < n ; i ++){

        a[i] = in();
        if (!a[i]){
            pq.push(-i);
        }
    }
    while (!pq.empty())
    {
        int v = -pq.top();
        pq.pop();
        cout  << v + 1 << " ";
        mark[v] = true;
        for (int i = v - k ; i >= 0 ; i --){
            if (!mark[i]){
                a[i]--;
                if (a[i] == false){
                    pq.push(-i);
                }
            }
        }
    } cout << "\n";
}


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<math.h>
#include<algorithm>
using namespace std;

typedef long long ll;
#define mem(s,v) memset(s,v,sizeof(s))
#define inf 0x3f3f3f3f
#define maxn 1010

int a[maxn],b[maxn];
int vis[maxn];

int main()
{
	int n,m;
	int i,j,k,l;
	while(~scanf("%d%d",&n,&m)){
		mem(vis,0);
		int p=0,q=0;
		for(i=1;i<=n;++i){
			scanf("%d",&b[i]);
			if(b[i]==0 && p==0) p=i;
			if(b[i]!=0 && q==0) q=i;
		}
		int t=1;
		for(i=q;i<=n;++i){
			if(b[i]==0) continue;
			j=b[i];
			for(k=p;k<=n;++k){
				if(b[k]==0 && vis[k]==0){
					vis[k]=1;
					a[t]=k;
					t++;
					if(k>=m+i) j--;
					//cout<<t-1<<" "<<a[t-1]<<endl;
					if(j==0) break;
				}
				else continue;
			}
			vis[i]=1;
			a[t]=i;
			t++;
			//cout<<t-1<<" "<<a[t-1]<<endl;
		}
		if(t-1<n){
			for(i=1;i<=n;++i)
				if(vis[i]==0){
					vis[i]=1;
					a[t]=i;
					t++;
				}
		}
		for(i=1;i<n;++i) printf("%d ",a[i]);
		printf("%d\n",a[n]);
	}
	return 0;
}

/*
5 2
1 2 1 0 0
4 2
1 0 0 0
*/


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<math.h>
#include<algorithm>
using namespace std;

typedef long long ll;
#define mem(s,v) memset(s,v,sizeof(s))
#define inf 0x3f3f3f3f
#define maxn 1010

int a[maxn],n,k;

int main()
{
    while(cin>>n>>k){
	    for(int i=1;i<=n;i++) cin>>a[i];
	    for(int i=1;i<=n;i++){
	        int j;
	    	for(j=1;j<=n;j++) if(!a[j]) break;
	    	cout<<j<<' ';
	    	for(int q=1;q<=j-k;q++) a[q]--;
		    a[j]--;
	    }
	    cout<<endl;
	}
    return 0;
}

/*
5 2
1 2 1 0 0
4 2
1 0 0 0
10 3
4 2 4 2 1 0 1 0 0 0
*/


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define size(x) (int) x.size()

const int maxn = 1005;
const int logn = 10;
const int inf = (int) 1e9;
const long long mod = (int) 1e9+7;
const long long base = 2204234849;
const long long l_inf = (long long) 4e18;
const long double pi = acos(-1.0);
const long double eps = 1e-12;

int n, k;
int a[maxn], b[maxn];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	srand(566);

	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> b[i];

	for (int i = n - 1; i >= 0; i--) {
		a[i] = i;
		int j = i;
		while (b[i] > 0) {
			swap(a[j], a[j + 1]);
			b[i] -= a[j] - a[j + 1] >= k;
			j++;
		}
	}

	for (int i = 0; i < n; i++)
		cout << a[i] + 1 << ' ';

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define maxn 1010
int a[maxn],b[maxn];
int n,k;
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;++i) scanf("%d",&b[i]);
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=n;++j)
        {
            if(b[j]==0)
            {
                a[i]=j;
                b[j]=-1;
                for(int p=1;p+k<=j;++p)
                    b[p]--;
                break;
            }
        }
    }
    for(int i=1;i<=n;++i)
        printf("%d ",a[i]);
    return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ll Mod = 1000000007LL;
const int N = 2e5 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;

ll b[N];

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n, k;
	cin >> n >> k;
	for(int i = 1; i <= n; i++) cin >> b[i];
	for(int i = 1; i <= n; i++){
		ll idx = -1;
		for(int j = n; j >= 1; j--) if(b[j] == 0) idx = j;
		cout << idx << ' ';
		b[idx] --;
		for(int i = 1; i <= idx - k; i++) b[i] --;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[1001],b[1001];
int main()
{
    int n,k;
    while (scanf("%d%d",&n,&k)==2)
    {
        for (int i=1;i<=n;i++)
        {
            cin>>b+i;
        }
        for (int i=1;i<=n;i++)
        {
            int cur=1;
            while (b[cur]!=0)
            {
                cur++;
            }
            a[i]=cur;
            b[cur]--;
            for (int j=1;j+k<=cur;j++)
            {
                b[j]--;
            }
        }
        for (int i=1;i<=n-1;i++)
        {
            cout<<a[i]<<" ";
        }
        cout<<a[n]<<endl;
    }
    return 0;
}


#include <cstdio>

const int MAXN = 1024;
int a[MAXN], b[MAXN];

int main() {
  int n, m;

  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    a[i] = -1;
    scanf("%d", &b[i]);
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (b[j] == 0) {
        a[i] = j;
        b[j] = -1;
        for (int k = 0; k + m <= j; ++k) {
          if (b[k] > 0) {
            --b[k];
          }
        }
        break;
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    printf("%d ", a[i] + 1);
  }

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;

int main() {
	int N, K, i, j;
	cin >> N >> K;
	vector<int>A(N + 1, 0), out, B(N+1, 0), C(N+1, 0);

	for (i = 1; i <= N; ++i) {
		cin >> A[i];
	}

	for (i = 0; i < N; ++i) {
		for (j = 1; j <= N && !(!C[j] && !A[j]); ++j);
		C[j] = 1;
		out.push_back(j);
		for (int k = 1; k <= j - K; ++k) {
			if (!C[k])
				--A[k];
		}
	}
	for (int x: out) {
		cout << x << " ";
	}

	return 0;
}


#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define ll long long
//#define ll unsigned long long
#define R register int
#define inf 0x3f3f3f3f
#define mod 1000000007
#define eps 1e-6
#define pi acos(-1)
#define mea (memset(a,0,sizeof(a)))
#define myit set<ll>::iterator
#define myits  multiset<ll>::iterator
#define v30 (1<<30)-1
#define all(x) (x).begin(),(x).end()
#define maxs *s.rbegin()
#define fi first
#define se second
#define lowbit(x) (x&(-x))
using namespace std;
inline ll read(){
   ll s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
void put1(){ puts("Yes") ;}
void put2(){ puts("No") ;}
void put3(){ puts("-1"); }
ll gcd(ll a,ll b){ return b==0?a:gcd(b,a%b);}
using namespace std;

const int manx=2e5+10;

ll a[manx],b[manx];

int main()
{
    ll n=read(),k=read();
    for(int i=1;i<=n;i++) b[i]=read();
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(b[j]==0){
                a[i]=j;
                b[j]=-1;
                for(int l=1;l+k<=j;l++)
                    if(b[l])b[l]--;
                break;
            }
        }
    }
    for(int i=1;i<=n;i++)
        printf("%lld ",a[i]);
    return 0;
}


#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define ll long long
//#define ll unsigned long long
#define R register int
#define inf 0x3f3f3f3f
#define mod 1000000007
#define eps 1e-6
#define pi acos(-1)
#define mea (memset(a,0,sizeof(a)))
#define myit set<ll>::iterator
#define myits  multiset<ll>::iterator
#define v30 (1<<30)-1
#define all(x) (x).begin(),(x).end()
#define maxs *s.rbegin()
#define fi first
#define se second
#define lowbit(x) (x&(-x))
using namespace std;
inline ll read(){
   ll s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
void put1(){ puts("Yes") ;}
void put2(){ puts("No") ;}
void put3(){ puts("-1"); }
ll gcd(ll a,ll b){ return b==0?a:gcd(b,a%b);}
using namespace std;

const int manx=2e5+10;

ll a[manx],b[manx];

int main()
{
    ll n=read(),k=read();
    for(int i=1;i<=n;i++) a[i]=i,b[i]=read();
    ll flag=1;
    while(1){
        ll tmp=1;
        for(int i=1;i<=n;i++){
            ll cnt=0;
            for(int j=1;j<=n;j++){
                if(a[j]==i) break;
                if(a[j]>=i+k) cnt++;
            }
            if(cnt!=b[i]){
                tmp=0;
                break;
            }
        }
        if(tmp) break;
        next_permutation(a+1,a+1+n);
    }
    for(int i=1;i<=n;i++)
        printf("%lld ",a[i]);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int a[N];
int main() {
    int n,k;
    scanf("%d %d",&n,&k);
    for(int i=1;i<=n;i++) {
        scanf("%d",&a[i]);
    }
    vector <int> v;
    int p = n;
    int i=n;
    for(i=n;i>=1;i--) {
        if(a[i]==0) {
            v.push_back(i);
        } else break;
    }
    reverse(v.begin(),v.end());
    while(i>0) {

        int c = a[i];
        vector<int> :: iterator j;
        for(j =v.begin();j!=v.end();j++) {
            if(c==0) break;
            if((*j)>=i+k) c--;
        }
        v.insert(j,i);
        i--;
    }
    for(int x:v) printf("%d ",x);

}


//lxrtxdy!
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define ll long long
//#define ll unsigned long long
#define R register int
#define inf 0x3f3f3f3f
#define mod 1000000007
#define eps 1e-6
#define pi acos(-1)
#define mea (memset(a,0,sizeof(a)))
#define myit set<ll>::iterator
#define myits  multiset<ll>::iterator
#define v30 (1<<30)-1
#define all(x) (x).begin(),(x).end()
#define maxs *s.rbegin()
#define fi first
#define se second
#define lowbit(x) (x&(-x))
using namespace std;
inline ll read(){
   ll s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
void put1(){ puts("Yes") ;}
void put2(){ puts("No") ;}
void put3(){ puts("-1"); }
ll gcd(ll a,ll b){ return b==0?a:gcd(b,a%b);}
using namespace std;

const int manx=2e5+10;

ll a[manx],b[manx];

int main()
{
    ll n=read(),k=read();
    for(int i=1;i<=n;i++) b[i]=read();
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(b[j]==0){
                a[i]=j;
                b[j]=-1;
                for(int l=1;l+k<=j;l++)
                    if(b[l])b[l]--;
                break;
            }
        }
    }
    for(int i=1;i<=n;i++)
        printf("%lld ",a[i]);
    return 0;
}

//orzlxr!


#include<bits/stdc++.h>
using namespace std;
int a[1001],b[1001];
int main()
{
    int n,k;
    while (scanf("%d%d",&n,&k)==2)
    {
        for (int i=1;i<=n;i++)
        {
            cin>>b[i];
        }
        for (int i=1;i<=n;i++)
        {
            int cur=1;
            while (b[cur]!=0)
            {
                cur++;
            }
            a[i]=cur;
            b[cur]--;
            for (int j=1;j+k<=cur;j++)
            {
                b[j]--;
            }
        }
        for (int i=1;i<=n-1;i++)
        {
            cout<<a[i]<<" ";
        }
        cout<<a[n]<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=2e5+10;
#define fi first
#define se second
#define pb push_back
int n,k,a[N];
vector<int>ans;
int main() {
    ios::sync_with_stdio(false);
    cin>>n>>k;
    int l=n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(!a[i])l=min(l,i);
    }
    ans.pb(l);
    a[l]=1e9;
    for(int i=2;i<=n;i++){
        int x=ans.back();
//        [1,l-k]
        for(int j=1;j<=x-k;j++){
            a[j]--;
        }
        int now=1e9;
        for(int j=1;j<=n;j++){
            if(!a[j])now=min(now,j);
        }
        ans.pb(now);
        a[now]=1e9;
    }
    for(auto k:ans)cout<<k<<' ';
    return 0;
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int, int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define sws ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
#define teto(a, b) ((a+b-1)/(b))
using namespace std;

const int MAX = 1000010;
const int MOD = 1000000007;
const int INF = 1e8;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const ld EPS = 1e-7;

// Extra
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define forne(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
//

int main() {
    sws;
    int n, k;
    cin >> n >> k;

    vector<bool> foi(n, false);
    vi res(n, -1), b(n);
    forn(i, n)
        cin >> b[i];

    forn(i, n) {
        int val = n;
        forn(j, n) {
            if(b[j] == 0 and !foi[j]) {
                val = j;
                break;
            }
        }
        foi[val] = true;
        res[i] = val;
        for(int j = 0; j <= val-k; j++) {
            b[j]--;
        }
    }

    for(auto r : res)
        cout << r+1 << " ";
    cout << endl;

    return 0;
}


#include <vector>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <assert.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <array>
#include <iomanip>
#include <bitset>
using namespace std;

#define ll long long
const ll mod = 998244353;
bitset<1005> vis;
int main(){
	int n, k; cin >> n >> k;
	vector<int> v(n);
	for(int i = 0; i < n; i ++) cin >> v[i];

	vector<int> ans(n), pref(n);
	for(int i = 0; i < n; i ++){
		for(int j = 0; j < n; j ++){
			if(!vis[j] && v[j] == 0){
				ans[i] = j;
				vis[j] = 1;
				for(int l = 0; l < j; l ++) if(l + k <= j)
					v[l] --;
				break;
			}
		}
	}

	for(int i = 0; i < n; i ++)
		cout << ans[i] + 1 << " ";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,k,a[1001],b[1001],qwq;
int main()
{
    scanf("%d%d",&n,&k);//一些输入
    for(int i=1;i<=n;i++)
    	scanf("%d",&b[i]);
    for(int i=1;i<=n;i++)//注意 qwq 初始化为 1
    {
    	qwq=1;//初始化为 1
        while(b[qwq]!=0)//循环判断
            qwq++;
        a[i]=qwq;//记录集合 A
        b[qwq]--;
        for(int j=1;j+k<=qwq;b[j]--,j++);
    }
    for(int i=1;i<=n;i++)
    	printf("%d ",a[i]);
    return 0;
}


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

int cnt[1005], ans[1005];
int N, K;

int main() {
//  freopen("inp", "r", stdin);
  scanf("%d %d", &N, &K);
  for(int i = 1; i <= N; i++) {
    scanf("%d", &cnt[i]);
  }
  for(int i = 1; i <= N; i++) {
    for(int j = 1; j <= N; j++) {
      if(!ans[i] && cnt[j] == 0) {
        ans[i] = j;
        cnt[j]--;
        for(int k = 1; k <= j - K; k++)cnt[k]--;
        break;
      }
    }
  }
  for(int i = 1; i <= N; i++)
    printf("%d " , ans[i]);
}//hellobig_tq


#include<iostream>
#include<stdio.h>
#include<memory.h>

using namespace std;

int a[1010],
    res[1010];

int main() {
    memset(a, 0, sizeof(a));
    memset(res, 0, sizeof(res));

    int n = 0,
        k = 0;
    scanf("%d%d", &n, &k);
    for(int i = 1; i<=n; ++i) {
        scanf("%d", &a[i]);
    }

    for(int i = 1; i<=n; ++i) {
        int cur = 1;
        while(a[cur]) {
            ++cur;
        }

        res[i] = cur;
        --a[cur];
        for(int j = 1; j+k<=cur; ++j) {
            --a[j];
        }
    }

    for(int i = 1; i<=n; ++i) {
        printf("%d ", res[i]);
    }

    return 0;
}


#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <memory.h>
#include <sstream>
#include <stack>
#include <fstream>
#include <cstdio>
#include <unordered_map>
#include <map>
#include <list>
#include <stdlib.h>
#include <queue>
#include <set>
using namespace std;

/*
*/

bool tk[1005] = {0};
int main()
{
	int n, k;
	int B[1005];
	int a[1005];
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++)
		scanf("%d", B+i);
	for (int i = 0; i < n; i++)
	{
		int sel = -1;
		for (int j = 0; j < n; j++)
		{
			if (B[j] == 0 && !tk[j])
			{
				sel = j;
				break;
			}
		}
		a[i] = sel+1;
		tk[sel] = true;
		for (int j = 0; j+k <= sel && j < n; j++)
		{
			B[j]--;
		}
	}
	for (int i = 0; i < n; i++)
	{
		printf("%d ", a[i]);
	}
	printf("\n");
}


// khodaya khodet komak kon
#include <bits/stdc++.h>
#define pb push_back
#define ers erase
#define ins insert
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)  cerr << #x << " = " << x << endl
#define kill(x) return cout << x, 0;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#pragma GCC optimize ("Ofast")
using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pll> vpl;

const ld Pi = 3.14159265359;
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll N = 4e3 + 10;
const ll INF = 1e18;
const ll LOG = 20;
ll dp[N][N], lasta[N][26], lastb[N][26], t1, t2, t3, t4;
str a, b;

int main(){
	IOS;
	cin >> t1 >> t2 >> t3 >> t4;
	cin >> a >> b;
	a = "." + a;
	b = "." + b;
	memset(dp, 63, sizeof dp);

	for (int i = 1; i < a.size(); i++){
		for (int j = 0; j < 26; j++){
			lasta[i][j] = lasta[i - 1][j];
		}
		lasta[i][a[i] - 'a'] = i;
	}
	for (int i = 1; i < b.size(); i++){
		for (int j = 0; j < 26; j++){
			lastb[i][j] = lastb[i - 1][j];
		}
		lastb[i][b[i] - 'a'] = i;
	}
	for (int i = 0; i < a.size(); i++){
		dp[i][0] = t2 * i;
	}
	for (int j = 0; j < b.size(); j++){
		dp[0][j] = t1 * j;
	}
	for (int i = 1; i < a.size(); i++){
		for (int j = 1; j < b.size(); j++){
			dp[i][j] = min(dp[i - 1][j] + t2, dp[i][j - 1] + t1);
			dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + t3);
			if (a[i] == b[j]) dp[i][j] = min(dp[i][j], dp[i - 1][j - 1]);
			ll koj = lasta[i - 1][b[j] - 'a'];
			ll koj1 = lastb[j - 1][a[i] - 'a'];
			if (koj != 0 && koj1 != 0){
				dp[i][j] = min(dp[i][j], dp[koj - 1][koj1 - 1] + (i - koj - 1) * t2 + t4 + (j - koj1 - 1) * t2);
			}

		}
	}
	cout << dp[a.size() - 1][b.size() - 1];

	return 0;
}

/*
     ,---,           ___                 ,--,
    '  .' \        ,--.'|_             ,--.'|                             ,--,
   /  ;    '.      |  | :,'            |  | :                           ,--.'|    ,---.        ,---,
  :  :       \     :  : ' :            :  : '                 .--.--.   |  |,    '   ,'\   ,-+-. /  |
  :  |   /\   \  .;__,'  /    ,--.--.  |  ' |     ,--.--.    /  /    '  `--'_   /   /   | ,--.'|'   |
  |  :  ' ;.   : |  |   |    /       \ '  | |    /       \  |  :  /`./  ,' ,'| .   ; ,. :|   |  ,"' |
  |  |  ;/  \   \:__,'| :   .--.  .-. ||  | :   .--.  .-. | |  :  ;_    '  | | '   | |: :|   | /  | |
  '  :  | \  \ ,'  '  : |__  \__\/: . .'  : |__  \__\/: . .  \  \    `. |  | : '   | .; :|   | |  | |
  |  |  '  '--'    |  | '.'| ," .--.; ||  | '.'| ," .--.; |   `----.   \'  : |_|   :    ||   | |  |/
  |  :  :          ;  :    ;/  /  ,.  |;  :    ;/  /  ,.  |  /  /`--'  /|  | '.'\   \  / |   | |--'
  |  | ,'          |  ,   /;  :   .'   \  ,   /;  :   .'   \'--'.     / ;  :    ;`----'  |   |/
  `--''             ---`-' |  ,     .-./---`-' |  ,     .-./  `--'---'  |  ,   /         '---'
                            `--`---'            `--`---'                 ---`-'
*/


// khodaya khodet komak kon
#include <bits/stdc++.h>
#define pb push_back
#define ers erase
#define ins insert
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)  cerr << #x << " = " << x << endl
#define kill(x) return cout << x, 0;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#pragma GCC optimize ("Ofast")
using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pll> vpl;

const ld Pi = 3.14159265359;
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll N = 4e3 + 10;
const ll INF = 1e18;
const ll LOG = 20;
ll dp[N][N], lasta[N][26], lastb[N][26], t1, t2, t3, t4;
str a, b;

int main(){
	IOS;
	cin >> t1 >> t2 >> t3 >> t4;
	cin >> a >> b;
	a = "." + a;
	b = "." + b;
	memset(dp, 63, sizeof dp);

	for (int i = 1; i < a.size(); i++){
		for (int j = 0; j < 26; j++){
			lasta[i][j] = lasta[i - 1][j];
		}
		lasta[i][a[i] - 'a'] = i;
	}
	for (int i = 1; i < b.size(); i++){
		for (int j = 0; j < 26; j++){
			lastb[i][j] = lastb[i - 1][j];
		}
		lastb[i][b[i] - 'a'] = i;
	}
	for (int i = 0; i < a.size(); i++){
		dp[i][0] = t2 * i;
	}
	for (int j = 0; j < b.size(); j++){
		dp[0][j] = t1 * j;
	}
	for (int i = 1; i < a.size(); i++){
		for (int j = 1; j < b.size(); j++){
			dp[i][j] = min(dp[i - 1][j] + t2, dp[i][j - 1] + t1);
			dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + t3);
			if (a[i] == b[j]) dp[i][j] = min(dp[i][j], dp[i - 1][j - 1]);
			ll koj = lasta[i - 1][b[j] - 'a'];
			ll koj1 = lastb[j - 1][a[i] - 'a'];
			if (koj != 0 && koj1 != 0){
				dp[i][j] = min(dp[i][j], dp[koj - 1][koj1 - 1] + (i - koj - 1) * t2 + t4 + (j - koj1 - 1) * t1);
			}

		}
	}
	cout << dp[a.size() - 1][b.size() - 1];

	return 0;
}

/*
     ,---,           ___                 ,--,
    '  .' \        ,--.'|_             ,--.'|                             ,--,
   /  ;    '.      |  | :,'            |  | :                           ,--.'|    ,---.        ,---,
  :  :       \     :  : ' :            :  : '                 .--.--.   |  |,    '   ,'\   ,-+-. /  |
  :  |   /\   \  .;__,'  /    ,--.--.  |  ' |     ,--.--.    /  /    '  `--'_   /   /   | ,--.'|'   |
  |  :  ' ;.   : |  |   |    /       \ '  | |    /       \  |  :  /`./  ,' ,'| .   ; ,. :|   |  ,"' |
  |  |  ;/  \   \:__,'| :   .--.  .-. ||  | :   .--.  .-. | |  :  ;_    '  | | '   | |: :|   | /  | |
  '  :  | \  \ ,'  '  : |__  \__\/: . .'  : |__  \__\/: . .  \  \    `. |  | : '   | .; :|   | |  | |
  |  |  '  '--'    |  | '.'| ," .--.; ||  | '.'| ," .--.; |   `----.   \'  : |_|   :    ||   | |  |/
  |  :  :          ;  :    ;/  /  ,.  |;  :    ;/  /  ,.  |  /  /`--'  /|  | '.'\   \  / |   | |--'
  |  | ,'          |  ,   /;  :   .'   \  ,   /;  :   .'   \'--'.     / ;  :    ;`----'  |   |/
  `--''             ---`-' |  ,     .-./---`-' |  ,     .-./  `--'---'  |  ,   /         '---'
                            `--`---'            `--`---'                 ---`-'
*/


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <cstdio>
#include <stdlib.h>
#include <stack>
#include <numeric>
#include <bitset>
typedef long long ll;
#define MAX 4005
using namespace std;
int n,m,k;
#define INF 2147483647
#define MOD 1000000007
#define G 9.8
bool debug = false;

int a[16],b[26], dp[MAX][MAX];
char sa[MAX], sb[MAX];
int main()
{
    int ti,td,tr,te;
    scanf("%d%d%d%d", &ti, &td,&tr,&te);
    scanf("%s%s", sa+1, sb+1);
    for(n=1;sa[n];n++) dp[n][0]=td*n;
    for(m=1;sb[m];m++) dp[0][m]=ti*m;
    for (int i=1;i<n;i++) {
        memset(b, 0, sizeof b);
        for (int j=1;j<m;j++) {
            dp[i][j]=dp[i-1][j-1] + (sa[i]!=sb[j]) * tr;
            dp[i][j]=min(dp[i][j], dp[i-1][j] + td);
            dp[i][j]=min(dp[i][j], dp[i][j-1] + ti);
            int x = a[sb[j]-'a'], y = b[sa[i]-'a'];
            if (x&&y) {
                dp[i][j]=min(dp[i][j], dp[x-1][y-1] + td*(i-x-1) + ti*(j-y-1) + te );
            }
            b[sb[j]-'a']=j;
        }
        a[sa[i]-'a']=i;
    }
    printf("%d\n",dp[n-1][m-1]);
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <cstdio>
#include <stdlib.h>
#include <stack>
#include <numeric>
#include <bitset>
typedef long long ll;
#define MAX 4005
using namespace std;
int n,m,k;
#define INF 2147483647
#define MOD 1000000007
#define G 9.8
bool debug = false;

int a[26],b[26], dp[MAX][MAX];
char sa[MAX], sb[MAX];
int main()
{
    int ti,td,tr,te;
    scanf("%d%d%d%d", &ti, &td,&tr,&te);
    scanf("%s%s", sa+1, sb+1);
    for(n=1;sa[n];n++) dp[n][0]=td*n;
    for(m=1;sb[m];m++) dp[0][m]=ti*m;
    for (int i=1;i<n;i++) {
        memset(b, 0, sizeof b);
        for (int j=1;j<m;j++) {
            dp[i][j]=dp[i-1][j-1] + (sa[i]!=sb[j]) * tr;
            dp[i][j]=min(dp[i][j], dp[i-1][j] + td);
            dp[i][j]=min(dp[i][j], dp[i][j-1] + ti);
            int x = a[sb[j]-'a'], y = b[sa[i]-'a'];
            if (x&&y) {
                dp[i][j]=min(dp[i][j], dp[x-1][y-1] + td*(i-x-1) + ti*(j-y-1) + te );
            }
            b[sb[j]-'a']=j;
        }
        a[sa[i]-'a']=i;
    }
    printf("%d\n",dp[n-1][m-1]);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;

const int INF = 2e9+5;

/*
    filippos
    Contest: Manthan 2011
    Task : sequenceofballs
*/

#ifdef EVAL
#define cin fin
#define cout fout
#include <fstream>
ifstream fin("input.txt");
ofstream fout("output.txt");
#endif

vvi memo;
string a, b;
int n, m;
array<int, 4> c;
vvi next_a;
vvi next_b;

int calls = 0;
int dp(int i, int j){
	// base case
	if(i == n && j == m) return 0;

	// memoization
	int &ans = memo[i][j];
	if(ans != -1) return ans;

	calls++;
	assert(calls < n * m * 2);

	ans = INF;
	// add to a to match b[j]
	if(j < m) ans = min(ans, c[0] + dp(i, j+1));
	// remove a[i]
	if(i < n) ans = min(ans, c[1] + dp(i+1, j));
	// replace a[i] with b[j]
	if(i < n && j < m) {
		// free if a[i] matches b[j]
		ans = min(ans, (a[i] == b[j] ? 0 : c[2]) + dp(i+1, j+1));
	}
	// swap i to match j
	if(i + 1 < n && j + 1 < m) {
		// we find next occurence of b[j] in a, \
			so to erase everything in between
		int i2 = next_a[i][b[j]];
		// we find next occurence of a[i] in b, \
			so to insert everything in between
		int j2 = next_b[j][a[i]];
		// if both exist (!= -1 && != i or j)
		if(i2 > i && j2 > j) {
			ans = min(ans,
				(i2 - i - 1) * c[1]// pay removals
				+ c[3] // pay swap
				+ (j2 - j - 1) * c[0] // pay insertions
				+ dp(i2 +1, j2 +1)// what's left to match
			);
		}
	}
	return ans;
}

int main(){
    cin.tie(0), cin.sync_with_stdio(0), cout.tie(0), cout.sync_with_stdio(0);

    cin >> c[0] >> c[1] >> c[2] >> c[3];
    assert(2 * c[3] >= c[0] + c[1]);

    cin >> a >> b;
    n = a.size(), m = b.size();

    // edit distance with swaps (Damerau–Levenshtein)

    // compute next char for each index and string
    next_a = vvi(n, vi(256, -1));
    next_b = vvi(m, vi(256, -1));

    for(int i = n - 1; i >= 0; i--) {
    	if(i + 1 < n) next_a[i] = next_a[i+1];
    	next_a[i][a[i]] = i;
    }
    for(int i = m - 1; i >= 0; i--) {
    	if(i + 1 < m) next_b[i] = next_b[i+1];
    	next_b[i][b[i]] = i;
    }

    memo = vvi(n + 1, vi(m + 1, -1));

    cout << dp(0, 0) << '\n';
}


#include <bits/stdc++.h>
#pragma GCC optimize ("O3")

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;

const int INF = 2e9+5;

/*
    filippos
    Contest: Manthan 2011
    Task : sequenceofballs
*/

#ifdef EVAL
#define cin fin
#define cout fout
#include <fstream>
ifstream fin("input.txt");
ofstream fout("output.txt");
#endif

vvi memo;
string a, b;
int n, m;
array<int, 4> c;
vvi next_a;
vvi next_b;

int dp(int i, int j){
	// base case
	if(i == n && j == m) return 0;

	// memoization
	int &ans = memo[i][j];
	if(ans != -1) return ans;

	ans = INF;
	// add to a to match b[j]
	if(j < m) ans = min(ans, c[0] + dp(i, j+1));
	// remove a[i]
	if(i < n) ans = min(ans, c[1] + dp(i+1, j));
	// replace a[i] with b[j]
	if(i < n && j < m) {
		// free if a[i] matches b[j]
		ans = min(ans, (a[i] == b[j] ? 0 : c[2]) + dp(i+1, j+1));
	}
	// swap i to match j
	if(i + 1 < n && j + 1 < m) {
		// we find next occurence of b[j] in a, \
			so to erase everything in between
		int i2 = next_a[i][b[j]];
		// we find next occurence of a[i] in b, \
			so to insert everything in between
		int j2 = next_b[j][a[i]];
		// if both exist (!= -1 && != i or j)
		if(i2 > i && j2 > j) {
			ans = min(ans,
				(i2 - i - 1) * c[1]// pay removals
				+ c[3] // pay swap
				+ (j2 - j - 1) * c[0] // pay insertions
				+ dp(i2 +1, j2 +1)// what's left to match
			);
		}
	}
	return ans;
}

int main(){
    cin.tie(0), cin.sync_with_stdio(0), cout.tie(0), cout.sync_with_stdio(0);

    cin >> c[0] >> c[1] >> c[2] >> c[3];
    assert(2 * c[3] >= c[0] + c[1]);

    cin >> a >> b;
    n = a.size(), m = b.size();

    // edit distance with swaps (Damerau–Levenshtein)

    // compute next char for each index and string
    next_a = vvi(n, vi(256, -1));
    next_b = vvi(m, vi(256, -1));

    for(int i = n - 1; i >= 0; i--) {
    	if(i + 1 < n) next_a[i] = next_a[i+1];
    	next_a[i][a[i]] = i;
    }
    for(int i = m - 1; i >= 0; i--) {
    	if(i + 1 < m) next_b[i] = next_b[i+1];
    	next_b[i][b[i]] = i;
    }

    memo = vvi(n + 1, vi(m + 1, -1));

    for(int i = n; i >= 0; i--)
    	for(int j = m; j >= 0; j--)
    		dp(i, j);

    cout << dp(0, 0) << '\n';
}


#include <bits/stdc++.h>
#pragma GCC optimize ("O3")

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;

const int INF = 2e9+5;

/*
    filippos
    Contest: Manthan 2011
    Task : sequenceofballs
*/

#ifdef EVAL
#define cin fin
#define cout fout
#include <fstream>
ifstream fin("input.txt");
ofstream fout("output.txt");
#endif

vvi memo;
string a, b;
int n, m;
array<int, 4> c;
vvi next_a;
vvi next_b;

// fake top down
int dp(int i, int j){
	int &ans = memo[i][j];
	// add to a to match b[j]
	if(j < m) ans = min(ans, c[0] + memo[i][j+1]);
	// remove a[i]
	if(i < n) ans = min(ans, c[1] + memo[i+1][j]);
	// replace a[i] with b[j]
	if(i < n && j < m) {
		// free if a[i] matches b[j]
		ans = min(ans, (a[i] == b[j] ? 0 : c[2]) + memo[i+1][j+1]);
	}
	// swap i to match j
	if(i + 1 < n && j + 1 < m) {
		// we find next occurence of b[j] in a, \
			so to erase everything in between
		int i2 = next_a[i][b[j]];
		// we find next occurence of a[i] in b, \
			so to insert everything in between
		int j2 = next_b[j][a[i]];
		// if both exist (!= -1 && != i or j)
		if(i2 > i && j2 > j) {
			ans = min(ans,
				(i2 - i - 1) * c[1]// pay removals
				+ c[3] // pay swap
				+ (j2 - j - 1) * c[0] // pay insertions
				+ memo[i2 + 1][j2 + 1]// what's left to match
			);
		}
	}
	return ans;
}

int main(){
    cin.tie(0), cin.sync_with_stdio(0), cout.tie(0), cout.sync_with_stdio(0);

    cin >> c[0] >> c[1] >> c[2] >> c[3];
    assert(2 * c[3] >= c[0] + c[1]);

    cin >> a >> b;
    n = a.size(), m = b.size();

    // edit distance with swaps (Damerau–Levenshtein)

    // compute next char for each index and string
    next_a = vvi(n, vi(256, -1));
    next_b = vvi(m, vi(256, -1));

    for(int i = n - 1; i >= 0; i--) {
    	if(i + 1 < n) next_a[i] = next_a[i+1];
    	next_a[i][a[i]] = i;
    }
    for(int i = m - 1; i >= 0; i--) {
    	if(i + 1 < m) next_b[i] = next_b[i+1];
    	next_b[i][b[i]] = i;
    }

    memo = vvi(n + 1, vi(m + 1, INF));
    memo[n][m] = 0;

    for(int i = n; i >= 0; i--)
    	for(int j = m; j >= 0; j--)
    		dp(i, j);

    cout << memo[0][0];
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;

const int INF = 2e9+5;

/*
    filippos
    Contest: Manthan 2011
    Task : sequenceofballs
*/

#ifdef EVAL
#define cin fin
#define cout fout
#include <fstream>
ifstream fin("input.txt");
ofstream fout("output.txt");
#endif

vvi memo;
string a, b;
int n, m;
array<int, 4> c;
vvi next_a;
vvi next_b;

int calls = 0;
int dp(int i, int j){
	// base case
	if(i == n && j == m) return 0;

	// memoization
	int &ans = memo[i][j];
	if(ans != -1) return ans;

	calls++;
	assert(calls <= (n+1) * (m+1));

	ans = INF;
	// add to a to match b[j]
	if(j < m) ans = min(ans, c[0] + dp(i, j+1));
	// remove a[i]
	if(i < n) ans = min(ans, c[1] + dp(i+1, j));
	// replace a[i] with b[j]
	if(i < n && j < m) {
		// free if a[i] matches b[j]
		ans = min(ans, (a[i] == b[j] ? 0 : c[2]) + dp(i+1, j+1));
	}
	// swap i to match j
	if(i + 1 < n && j + 1 < m) {
		// we find next occurence of b[j] in a, \
			so to erase everything in between
		int i2 = next_a[i][b[j]];
		// we find next occurence of a[i] in b, \
			so to insert everything in between
		int j2 = next_b[j][a[i]];
		// if both exist (!= -1 && != i or j)
		if(i2 > i && j2 > j) {
			ans = min(ans,
				(i2 - i - 1) * c[1]// pay removals
				+ c[3] // pay swap
				+ (j2 - j - 1) * c[0] // pay insertions
				+ dp(i2 +1, j2 +1)// what's left to match
			);
		}
	}
	return ans;
}

int main(){
    cin.tie(0), cin.sync_with_stdio(0), cout.tie(0), cout.sync_with_stdio(0);

    cin >> c[0] >> c[1] >> c[2] >> c[3];
    assert(2 * c[3] >= c[0] + c[1]);

    cin >> a >> b;
    n = a.size(), m = b.size();

    // edit distance with swaps (Damerau–Levenshtein)

    // compute next char for each index and string
    next_a = vvi(n, vi(256, -1));
    next_b = vvi(m, vi(256, -1));

    for(int i = n - 1; i >= 0; i--) {
    	if(i + 1 < n) next_a[i] = next_a[i+1];
    	next_a[i][a[i]] = i;
    }
    for(int i = m - 1; i >= 0; i--) {
    	if(i + 1 < m) next_b[i] = next_b[i+1];
    	next_b[i][b[i]] = i;
    }

    memo = vvi(n + 1, vi(m + 1, -1));

    cout << dp(0, 0) << '\n';
}


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

int ti, td, tr, te;
int dp[MAXN][MAXN];
string s1, s2;
int n, m;
int arr1[MAXN], arr2[MAXN];

int main(){
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> ti >> td >> tr >> te;
    cin >> s1 >> s2;
    n = s1.length();
    m = s2.length();
    for(int i = 0; i<n; i++) arr1[i+1] = s1[i]-'a';
    for(int i = 0; i<m; i++) arr2[i+1] = s2[i]-'a';
    for(int i = 0; i<=n; i++) dp[i][0] = i*td;
    for(int i = 0; i<=m; i++) dp[0][i] = i*ti;
    for(int i = 1; i<=n; i++){
        for(int j = 1; j<=m; j++){
            dp[i][j] = min(dp[i-1][j]+td, dp[i][j-1]+ti);
            if(arr1[i] == arr2[j]) dp[i][j] = min(dp[i][j], dp[i-1][j-1]);
            dp[i][j] = min(dp[i][j], dp[i-1][j-1]+min(tr, ti+td));
            if(i == 1 || j == 1) continue;
            bool aa = arr1[i] == arr2[j-1];
            bool bb = arr1[i-1] == arr2[j];
            if(aa && bb) dp[i][j] = min(dp[i][j], dp[i-2][j-2]+min(ti+td, te));
            if(aa && !bb) dp[i][j] = min(dp[i][j], dp[i-2][j-2]+min(ti+td, te+tr));
            if(!aa && bb) dp[i][j] = min(dp[i][j], dp[i-2][j-2]+min(ti+td, te+tr));
            if(!aa && !bb) dp[i][j] = min(dp[i][j], dp[i-2][j-2]+min(2*(ti+td), 2*tr));
        }
    }
    cout << dp[n][m] << endl;
}


#include <bits/stdc++.h>

using namespace std;
long long dp[4005][4005];
long long lasta[4005][26];
long long lastb[4005][26];

signed main()
{
    long long INSERT,DELETE,REPLACE,SWAP;
    string a,b;
    cin>>INSERT>>DELETE>>REPLACE>>SWAP;
    cin>>a;
    cin>>b;
    long long n = a.length();
    long long m = b.length();
    memset(lasta,-1,sizeof(lasta));
    memset(lastb,-1,sizeof(lastb));

    a = '*' + a;
    b = '*' + b;

    for(long long i=1;i<=n;i++)
    {
        for(long long j=0;j<26;j++)
        {
            lasta[i][j] = lasta[i-1][j];
        }
        lasta[i][a[i]-'a'] = i;
    }

    for(long long i=1;i<=m;i++)
    {
        for(long long j=0;j<26;j++)
        {
            lastb[i][j] = lastb[i-1][j];
        }
        lastb[i][b[i]-'a'] = i;
    }

    dp[0][0] = 0;
    for(long long i=1;i<=n;i++)
        dp[i][0] = DELETE*i;
    for(long long i=1;i<=m;i++)
        dp[0][i] = INSERT*i;

    for(long long i=1;i<=n;i++)
    {
        for(long long j=1;j<=m;j++)
        {
            if(a[i]==b[j])
            {
                dp[i][j] = dp[i-1][j-1];
                continue;
            }
            dp[i][j] = min(dp[i][j-1]+INSERT,dp[i-1][j]+DELETE);
            dp[i][j] = min(dp[i][j],dp[i-1][j-1]+REPLACE);
            long long la = lasta[i][b[j]-'a'];
            long long lb = lastb[j][a[i]-'a'];
            if(la!=-1&&lb!=-1)
                dp[i][j] = min(dp[i][j],dp[la-1][lb-1] + (i-la-1)*DELETE + (j-lb-1)*INSERT + SWAP);
            // ta se xoa khoang giua cua la va i cua day a
            // sau do swap vi tri cua la va i cua day a
            // roi ta them doan tu lb den j vao phan giua 2 thang vua swap o day a
            // thi ta se duoc phan tu la->i o day a = lb->j o day b
            // va ta dp[la][lb];
        }
    }

    cout<<dp[n][m];
}


#include <bits/stdc++.h>

using namespace std;
long long dp[4005][4005];
long long lasta[4005][26];
long long lastb[4005][26];

signed main()
{
    long long INSERT,DELETE,REPLACE,SWAP;
    string a,b;
    cin>>INSERT>>DELETE>>REPLACE>>SWAP;
    cin>>a;
    cin>>b;
    long long n = a.length();
    long long m = b.length();
    memset(lasta,-1,sizeof(lasta));
    memset(lastb,-1,sizeof(lastb));

    a = '*' + a;
    b = '*' + b;

    for(long long i=1;i<=n;i++)
    {
        for(long long j=0;j<26;j++)
        {
            lasta[i][j] = lasta[i-1][j];
        }
        lasta[i][a[i]-'a'] = i;
    }

    for(long long i=1;i<=m;i++)
    {
        for(long long j=0;j<26;j++)
        {
            lastb[i][j] = lastb[i-1][j];
        }
        lastb[i][b[i]-'a'] = i;
    }

    dp[0][0] = 0;
    for(long long i=1;i<=n;i++)
        dp[i][0] = DELETE*i;
    for(long long i=1;i<=m;i++)
        dp[0][i] = INSERT*i;

    for(long long i=1;i<=n;i++)
    {
        for(long long j=1;j<=m;j++)
        {
            if(a[i]==b[j])
            {
                dp[i][j] = dp[i-1][j-1];
                continue;
            }
            dp[i][j] = min(dp[i][j-1]+INSERT,dp[i-1][j]+DELETE);
            dp[i][j] = min(dp[i][j],dp[i-1][j-1]+REPLACE);
            long long la = lasta[i][b[j]-'a'];
            long long lb = lastb[j][a[i]-'a'];
            //ta se swap vi tri la voi la+1
            if(la!=-1&&lb!=-1)
                dp[i][j] = min(dp[i][j],dp[la][lb] + (i-la-1)*DELETE + (j-lb-1)*INSERT + SWAP);
        }
    }

    cout<<dp[n][m];
}


#include <bits/stdc++.h>

using namespace std;
long long dp[4005][4005];
long long lasta[4005][26];
long long lastb[4005][26];

signed main()
{
    long long INSERT,DELETE,REPLACE,SWAP;
    string a,b;
    cin>>INSERT>>DELETE>>REPLACE>>SWAP;
    cin>>a;
    cin>>b;
    long long n = a.length();
    long long m = b.length();
    memset(lasta,-1,sizeof(lasta));
    memset(lastb,-1,sizeof(lastb));

    a = '*' + a;
    b = '*' + b;

    for(long long i=1;i<=n;i++)
    {
        for(long long j=0;j<26;j++)
        {
            lasta[i][j] = lasta[i-1][j];
        }
        lasta[i][a[i]-'a'] = i;
    }

    for(long long i=1;i<=m;i++)
    {
        for(long long j=0;j<26;j++)
        {
            lastb[i][j] = lastb[i-1][j];
        }
        lastb[i][b[i]-'a'] = i;
    }

    dp[0][0] = 0;
    for(long long i=1;i<=n;i++)
        dp[i][0] = DELETE*i;
    for(long long i=1;i<=m;i++)
        dp[0][i] = INSERT*i;

    for(long long i=1;i<=n;i++)
    {
        for(long long j=1;j<=m;j++)
        {
            if(a[i]==b[j])
            {
                dp[i][j] = dp[i-1][j-1];
                continue;
            }
            dp[i][j] = min(dp[i][j-1]+INSERT,dp[i-1][j]+DELETE);
            dp[i][j] = min(dp[i][j],dp[i-1][j-1]+REPLACE);
            long long la = lasta[i][b[j]-'a'];
            long long lb = lastb[j][a[i]-'a'];
            //ta se swap vi tri la voi la+1
            if(la!=-1&&lb!=-1)
                dp[i][j] = min(dp[i][j],dp[la-1][lb-1] + (i-la-1)*DELETE + (j-lb-1)*INSERT + SWAP);
        }
    }

    cout<<dp[n][m];
}