#include<bits/stdc++.h>
using namespace std;
const int maxn=5000+5;
template<int N,int M>
struct Graph
{
    int top;
    struct Vertex{
        int head;
    }V[N];
    struct Edge{
        int v,next,t;
    }E[M];
    void init(){
        memset(V,-1,sizeof(V));
        top = 0;
    }
    void add_edge(int u,int v,int t){
        E[top].v = v;
        E[top].t=t;
        E[top].next = V[u].head;
        V[u].head = top++;
    }
};
Graph<maxn,maxn> g;

int n,m,T,dp[maxn][maxn],pre[maxn][maxn],vis[maxn];

void dfs(int cur){
   if(vis[cur]!=0) return; vis[cur]=1;
   if(cur==1) dp[cur][1]=0;
   for(int i=g.V[cur].head;i!=-1;i=g.E[i].next){
       int f=g.E[i].v;dfs(f);
       for(int j=1;j<=n;j++){
          if(dp[f][j-1]+g.E[i].t<dp[cur][j]){
             dp[cur][j]=dp[f][j-1]+g.E[i].t;
             pre[cur][j]=f;
          }
       }
   }
}

void print(int t,int x){
   if(t>1) print(t-1,pre[x][t]); printf("%d ",x);
}

int main(){
   while(~scanf("%d%d%d",&n,&m,&T)){
       g.init();
       for(int i=1;i<=n;i++) vis[i]=0;
       memset(dp,0x3ff,sizeof(dp));
       for(int i=0;i<m;i++){
          int a,b;
          int c;scanf("%d%d%d",&a,&b,&c);
          g.add_edge(b,a,c);
       }
       dfs(n);
       int ans=0;
       for(int i=n;i>=0;i--){
         if(dp[n][i]<=T){
            ans=i;break;
         }
       }
       printf("%d\n",ans);
       print(ans,n);
       printf("\n");
   }
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=5000+5;
template<int N,int M>
struct Graph
{
    int top;
    struct Vertex{
        int head;
    }V[N];
    struct Edge{
        int v,next,t;
    }E[M];
    void init(){
        memset(V,-1,sizeof(V));
        top = 0;
    }
    void add_edge(int u,int v,int t){
        E[top].v = v;
        E[top].t=t;
        E[top].next = V[u].head;
        V[u].head = top++;
    }
};
Graph<maxn,maxn> g;

int n,m,T,dp[maxn][maxn],pre[maxn][maxn],vis[maxn];

void dfs(int cur){
   if(vis[cur]!=0) return; vis[cur]=1;
   if(cur==1) dp[cur][1]=0;
   for(int i=g.V[cur].head;i!=-1;i=g.E[i].next){
       int f=g.E[i].v;dfs(f);
       for(int j=1;j<=n;j++){
          if(dp[f][j-1]+g.E[i].t<dp[cur][j]){
             dp[cur][j]=dp[f][j-1]+g.E[i].t;
             pre[cur][j]=f;
          }
       }
   }
}

void print(int t,int x){
   if(t>1) print(t-1,pre[x][t]); printf("%d ",x);
}

int main(){
   while(~scanf("%d%d%d",&n,&m,&T)){
       g.init();
       memset(vis,0,sizeof(vis));
       memset(dp,0x3f,sizeof(dp));
       for(int i=0;i<m;i++){
          int a,b;
          int c;scanf("%d%d%d",&a,&b,&c);
          g.add_edge(b,a,c);
       }
       dfs(n);
       int ans=0;
       for(int i=n;i>=0;i--){
         if(dp[n][i]<=T){
            ans=i;break;
         }
       }
       printf("%d\n",ans);
       print(ans,n);
       printf("\n");
   }
}


#include <fstream>
#include <iostream>
#include <string>
#include <cstring>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <ctime>
#include <assert.h>

#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define eps 1e-8
#define M_PI 3.141592653589793

typedef long long ll;
const ll mod=9973;
const int inf=0x7fffffff;
template<int N,int M>
struct Graph
{
    int top;
    struct Vertex{
        int head;
    }V[N];
    struct Edge{
        int v,t,next;
    }E[M];
    void init(){
        memset(V,-1,sizeof(V));
        top = 0;
    }
    void add_edge(int u,int v,int t){
        E[top].v = v;
        E[top].t=t;
        E[top].next = V[u].head;
        V[u].head = top++;
    }
};

ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll extgcd(ll a,ll b,ll &x,ll &y) { ll d=a; if(b!=0){ d=extgcd(b,a%b,y,x); y-=(a/b)*x;} else x=1,y=0; return d;}
ll mod_reverse(ll a,ll n) {ll x,y; ll d=extgcd(a,n,x,y); if(d==1) return (x%n+n)%n; else return -1;}
ll inv(ll a,ll m) {return powmod(a,m-2);}
using namespace std;
Graph<5000+10,5000+10>g;
int n,m,T,ans[5000+10],tem[5000+10],cnt;
void dfs(int cur,int curt,int r){
   tem[r]=cur;
   if(cur==n){
      if(curt<=T&&r>cnt){
         for(int i=0;i<=r;i++) ans[i]=tem[i];
         cnt=r;
      }
      return;
   }
   for(int i=g.V[cur].head;i!=-1;i=g.E[i].next){
       int son=g.E[i].v;
       if(curt+g.E[i].t<=T) dfs(son,curt+g.E[i].t,r+1);
   }
}

int main(){
   while(~scanf("%d%d%d",&n,&m,&T)){
       g.init();
       for(int i=0;i<m;i++){
          int a,b,c;scanf("%d%d%d",&a,&b,&c);
          g.add_edge(a,b,c);
       }
       cnt=0;
       dfs(1,0,0);
       printf("%d\n",cnt+1);
       for(int i=0;i<cnt;i++){
          printf("%d ",ans[i]);
       }
       printf("%d\n",ans[cnt]);
   }
}


/*
#include <fstream>
#include <iostream>
#include <string>
#include <cstring>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <ctime>
#include <assert.h>

#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define eps 1e-8
#define M_PI 3.141592653589793

typedef long long ll;
const ll mod=9973;
const ll inf=0x7fffffff;
template<int N,int M>
struct Graph
{
    int top;
    struct Vertex{
        int head;
    }V[N];
    struct Edge{
        int v,next;
        ll t;
    }E[M];
    void init(){
        memset(V,-1,sizeof(V));
        top = 0;
    }
    void add_edge(int u,int v,ll t){
        E[top].v = v;
        E[top].t=t;
        E[top].next = V[u].head;
        V[u].head = top++;
    }
};

ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll extgcd(ll a,ll b,ll &x,ll &y) { ll d=a; if(b!=0){ d=extgcd(b,a%b,y,x); y-=(a/b)*x;} else x=1,y=0; return d;}
ll mod_reverse(ll a,ll n) {ll x,y; ll d=extgcd(a,n,x,y); if(d==1) return (x%n+n)%n; else return -1;}
ll inv(ll a,ll m) {return powmod(a,m-2);}
using namespace std;
Graph<5000+10,5000+10>g;
ll T;
int n,m,ans[5000+10],tem[5000+10],cnt;
ll limit[5005];

void dfs(int cur,ll curt,int r){
   tem[r]=cur;
   if(limit[cur]==-1) limit[cur]=curt;
   if(num[cur]==-1) num[cur]=r;
   if(curt>limit[cur]&&num[cur]>=r) return;
   if(cur==n){
      if(curt<=T&&r>cnt){
         for(int i=0;i<=r;i++) ans[i]=tem[i];
         cnt=r;
      }
      return;
   }
   for(int i=g.V[cur].head;i!=-1;i=g.E[i].next){
       int son=g.E[i].v;
       if(curt+g.E[i].t<=T){
            dfs(son,curt+g.E[i].t,r+1);
       }
   }
}

int main(){
   while(~scanf("%d%d%I64d",&n,&m,&T)){
       g.init();
       for(int i=1;i<=n;i++) limit[i]=-1,num[i]=-1;
       for(int i=0;i<m;i++){
          int a,b;
          ll c;scanf("%d%d%I64d",&a,&b,&c);
          g.add_edge(a,b,c);
       }
       cnt=0;
       dfs(1,0,0);
       printf("%d\n",cnt+1);
       for(int i=0;i<cnt;i++){
          printf("%d ",ans[i]);
       }
       printf("%d\n",ans[cnt]);
   }
}
*/
#include<bits/stdc++.h>
using namespace std;
const int maxn=5000+5;
template<int N,int M>
struct Graph
{
    int top;
    struct Vertex{
        int head;
    }V[N];
    struct Edge{
        int v,next,t;
    }E[M];
    void init(){
        memset(V,-1,sizeof(V));
        top = 0;
    }
    void add_edge(int u,int v,int t){
        E[top].v = v;
        E[top].t=t;
        E[top].next = V[u].head;
        V[u].head = top++;
    }
};
Graph<maxn,maxn> g;

int n,m,T,dp[maxn][maxn],pre[maxn][maxn],vis[maxn];

void dfs(int cur){
   if(vis[cur]!=0) return; vis[cur]=1;
   if(cur==1) dp[cur][1]=0;
   for(int i=g.V[cur].head;i!=-1;i=g.E[i].next){
       int f=g.E[i].v;dfs(f);
       for(int j=1;j<=n;j++){
          if(dp[f][j-1]+g.E[i].t<dp[cur][j]){
             dp[cur][j]=dp[f][j-1]+g.E[i].t;
             pre[cur][j]=f;
          }
       }
   }
}

void print(int t,int x){
   if(t>1) print(t-1,pre[x][t]); printf("%d ",x);
}

int main(){
   while(~scanf("%d%d%d",&n,&m,&T)){
       g.init();
       for(int i=1;i<=n;i++) vis[i]=0;
       memset(dp,0x3fff,sizeof(dp));
       for(int i=0;i<m;i++){
          int a,b;
          int c;scanf("%d%d%d",&a,&b,&c);
          g.add_edge(b,a,c);
       }
       dfs(n);
       int ans=0;
       for(int i=n;i>=0;i--){
         if(dp[n][i]<=T){
            ans=i;break;
         }
       }
       printf("%d\n",ans);
       print(ans,n);
       printf("\n");
   }
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=5000+10;
typedef long long ll;
template<int N,int M>
struct Graph
{
    int top;
    struct Vertex{
        int head;
    }V[N];
    struct Edge{
        int v,next;
        ll t;
    }E[M];
    void init(){
        memset(V,-1,sizeof(V));
        top = 0;
    }
    void add_edge(int u,int v,ll t){
        E[top].v = v;
        E[top].t=t;
        E[top].next = V[u].head;
        V[u].head = top++;
    }
};
Graph<maxn,maxn> g;

int n,m;
ll T,dp[maxn][maxn];
int pre[maxn][maxn],vis[maxn];

void dfs(int cur){
   if(vis[cur]!=0) return; vis[cur]=1;
   if(cur==1) dp[cur][1]=0;
   for(int i=g.V[cur].head;i!=-1;i=g.E[i].next){
       int f=g.E[i].v;dfs(f);
       for(int j=1;j<=n;j++){
          if(dp[f][j-1]+g.E[i].t<dp[cur][j]){
             dp[cur][j]=dp[f][j-1]+g.E[i].t;
             pre[cur][j]=f;
          }
       }
   }
}

void print(int t,int x){
   if(t>1) print(t-1,pre[x][t]); printf("%d ",x);
}

int main(){
   while(~scanf("%d%d%I64d",&n,&m,&T)){
       g.init();
       for(int i=1;i<=n;i++){
          vis[i]=0;
          for(int j=0;j<=n;j++){
            dp[i][j]=0x7ffffff;
          }
       }
       for(int i=0;i<m;i++){
          int a,b;
          ll c;scanf("%d%d%I64d",&a,&b,&c);
          g.add_edge(b,a,c);
       }
       dfs(n);
       int ans=0;
       for(int i=n;i>=1;i--){
         if(dp[n][i]<=T){
            ans=i;break;
         }
       }
       printf("%d\n",ans);
       print(ans,n);
       printf("\n");
   }
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=5000+5;
template<int N,int M>
struct Graph
{
    int top;
    struct Vertex{
        int head;
    }V[N];
    struct Edge{
        int v,next,t;
    }E[M];
    void init(){
        memset(V,-1,sizeof(V));
        top = 0;
    }
    void add_edge(int u,int v,int t){
        E[top].v = v;
        E[top].t=t;
        E[top].next = V[u].head;
        V[u].head = top++;
    }
};
Graph<maxn,maxn> g;

int n,m,T,dp[maxn][maxn],pre[maxn][maxn],vis[maxn];

void dfs(int cur){
   if(vis[cur]!=0) return; vis[cur]=1;
   if(cur==1) dp[cur][1]=0;
   for(int i=g.V[cur].head;i!=-1;i=g.E[i].next){
       int f=g.E[i].v;dfs(f);
       for(int j=1;j<=n;j++){
          if(dp[f][j-1]+g.E[i].t<dp[cur][j]){
             dp[cur][j]=dp[f][j-1]+g.E[i].t;
             pre[cur][j]=f;
          }
       }
   }
}

void print(int t,int x){
   if(t>1) print(t-1,pre[x][t]); printf("%d ",x);
}

int main(){
   while(~scanf("%d%d%d",&n,&m,&T)){
       g.init();
       for(int i=1;i<=n;i++){
         vis[i]=0;
         for(int j=0;j<=n;j++) dp[i][j]=0x7ffffff;
       }
       for(int i=0;i<m;i++){
          int a,b;
          int c;scanf("%d%d%d",&a,&b,&c);
          g.add_edge(b,a,c);
       }
       dfs(n);
       int ans=0;
       for(int i=n;i>=0;i--){
         if(dp[n][i]<=T){
            ans=i;break;
         }
       }
       printf("%d\n",ans);
       print(ans,n);
       printf("\n");
   }
}


/*
#include <fstream>
#include <iostream>
#include <string>
#include <cstring>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <ctime>
#include <assert.h>

#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define eps 1e-8
#define M_PI 3.141592653589793

typedef long long ll;
const ll mod=9973;
const ll inf=0x7fffffff;
template<int N,int M>
struct Graph
{
    int top;
    struct Vertex{
        int head;
    }V[N];
    struct Edge{
        int v,next;
        ll t;
    }E[M];
    void init(){
        memset(V,-1,sizeof(V));
        top = 0;
    }
    void add_edge(int u,int v,ll t){
        E[top].v = v;
        E[top].t=t;
        E[top].next = V[u].head;
        V[u].head = top++;
    }
};

ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll extgcd(ll a,ll b,ll &x,ll &y) { ll d=a; if(b!=0){ d=extgcd(b,a%b,y,x); y-=(a/b)*x;} else x=1,y=0; return d;}
ll mod_reverse(ll a,ll n) {ll x,y; ll d=extgcd(a,n,x,y); if(d==1) return (x%n+n)%n; else return -1;}
ll inv(ll a,ll m) {return powmod(a,m-2);}
using namespace std;
Graph<5000+10,5000+10>g;
ll T;
int n,m,ans[5000+10],tem[5000+10],cnt;
ll limit[5005];

void dfs(int cur,ll curt,int r){
   tem[r]=cur;
   if(limit[cur]==-1) limit[cur]=curt;
   if(num[cur]==-1) num[cur]=r;
   if(curt>limit[cur]&&num[cur]>=r) return;
   if(cur==n){
      if(curt<=T&&r>cnt){
         for(int i=0;i<=r;i++) ans[i]=tem[i];
         cnt=r;
      }
      return;
   }
   for(int i=g.V[cur].head;i!=-1;i=g.E[i].next){
       int son=g.E[i].v;
       if(curt+g.E[i].t<=T){
            dfs(son,curt+g.E[i].t,r+1);
       }
   }
}

int main(){
   while(~scanf("%d%d%I64d",&n,&m,&T)){
       g.init();
       for(int i=1;i<=n;i++) limit[i]=-1,num[i]=-1;
       for(int i=0;i<m;i++){
          int a,b;
          ll c;scanf("%d%d%I64d",&a,&b,&c);
          g.add_edge(a,b,c);
       }
       cnt=0;
       dfs(1,0,0);
       printf("%d\n",cnt+1);
       for(int i=0;i<cnt;i++){
          printf("%d ",ans[i]);
       }
       printf("%d\n",ans[cnt]);
   }
}
*/
#include<bits/stdc++.h>
using namespace std;
const int maxn=5000+5;
template<int N,int M>
struct Graph
{
    int top;
    struct Vertex{
        int head;
    }V[N];
    struct Edge{
        int v,next,t;
    }E[M];
    void init(){
        memset(V,-1,sizeof(V));
        top = 0;
    }
    void add_edge(int u,int v,int t){
        E[top].v = v;
        E[top].t=t;
        E[top].next = V[u].head;
        V[u].head = top++;
    }
};
Graph<maxn,maxn> g;

int n,m,T,dp[maxn][maxn],pre[maxn][maxn],vis[maxn];

void dfs(int cur){
   if(vis[cur]!=0) return; vis[cur]=1;
   if(cur==1) dp[cur][1]=0;
   for(int i=g.V[cur].head;i!=-1;i=g.E[i].next){
       int f=g.E[i].v;dfs(f);
       for(int j=1;j<=n;j++){
          if(dp[f][j-1]+g.E[i].t<dp[cur][j]){
             dp[cur][j]=dp[f][j-1]+g.E[i].t;
             pre[cur][j]=f;
          }
       }
   }
}

void print(int t,int x){
   if(t>1) print(t-1,pre[x][t]); printf("%d ",x);
}

int main(){
   while(~scanf("%d%d%d",&n,&m,&T)){
       g.init();
       for(int i=1;i<=n;i++) vis[i]=0;
       memset(dp,0x3f,sizeof(dp));
       for(int i=0;i<m;i++){
          int a,b;
          int c;scanf("%d%d%d",&a,&b,&c);
          g.add_edge(b,a,c);
       }
       dfs(n);
       int ans=0;
       for(int i=n;i>=0;i--){
         if(dp[n][i]<=T){
            ans=i;break;
         }
       }
       printf("%d\n",ans);
       print(ans,n);
       printf("\n");
   }
}


#include <fstream>
#include <iostream>
#include <string>
#include <cstring>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <ctime>
#include <assert.h>

#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define eps 1e-8
#define M_PI 3.141592653589793

typedef long long ll;
const ll mod=9973;
const ll inf=0x7fffffff;
template<int N,int M>
struct Graph
{
    int top;
    struct Vertex{
        int head;
    }V[N];
    struct Edge{
        int v,next;
        ll t;
    }E[M];
    void init(){
        memset(V,-1,sizeof(V));
        top = 0;
    }
    void add_edge(int u,int v,ll t){
        E[top].v = v;
        E[top].t=t;
        E[top].next = V[u].head;
        V[u].head = top++;
    }
};

ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll extgcd(ll a,ll b,ll &x,ll &y) { ll d=a; if(b!=0){ d=extgcd(b,a%b,y,x); y-=(a/b)*x;} else x=1,y=0; return d;}
ll mod_reverse(ll a,ll n) {ll x,y; ll d=extgcd(a,n,x,y); if(d==1) return (x%n+n)%n; else return -1;}
ll inv(ll a,ll m) {return powmod(a,m-2);}
using namespace std;
Graph<5000+10,5000+10>g;
ll T;
int n,m,ans[5000+10],tem[5000+10],cnt;
ll limit[5005];

void dfs(int cur,ll curt,int r){
   tem[r]=cur;
   if(limit[cur]==inf) limit[cur]=curt;
   if(curt>limit[cur]) return;
   if(cur==n){
      if(curt<=T&&r>cnt){
         for(int i=0;i<=r;i++) ans[i]=tem[i];
         cnt=r;
      }
      return;
   }
   for(int i=g.V[cur].head;i!=-1;i=g.E[i].next){
       int son=g.E[i].v;
       if(curt+g.E[i].t<=T) dfs(son,curt+g.E[i].t,r+1);
   }
}

int main(){
   while(~scanf("%d%d%I64d",&n,&m,&T)){
       g.init();
       for(int i=1;i<=n;i++) limit[i]=inf;
       for(int i=0;i<m;i++){
          int a,b;
          ll c;scanf("%d%d%I64d",&a,&b,&c);
          g.add_edge(a,b,c);
       }
       cnt=0;
       dfs(1,0,0);
       printf("%d\n",cnt+1);
       for(int i=0;i<cnt;i++){
          printf("%d ",ans[i]);
       }
       printf("%d\n",ans[cnt]);
   }
}


/*
#include <fstream>
#include <iostream>
#include <string>
#include <cstring>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <ctime>
#include <assert.h>

#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define eps 1e-8
#define M_PI 3.141592653589793

typedef long long ll;
const ll mod=9973;
const ll inf=0x7fffffff;
template<int N,int M>
struct Graph
{
    int top;
    struct Vertex{
        int head;
    }V[N];
    struct Edge{
        int v,next;
        ll t;
    }E[M];
    void init(){
        memset(V,-1,sizeof(V));
        top = 0;
    }
    void add_edge(int u,int v,ll t){
        E[top].v = v;
        E[top].t=t;
        E[top].next = V[u].head;
        V[u].head = top++;
    }
};

ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll extgcd(ll a,ll b,ll &x,ll &y) { ll d=a; if(b!=0){ d=extgcd(b,a%b,y,x); y-=(a/b)*x;} else x=1,y=0; return d;}
ll mod_reverse(ll a,ll n) {ll x,y; ll d=extgcd(a,n,x,y); if(d==1) return (x%n+n)%n; else return -1;}
ll inv(ll a,ll m) {return powmod(a,m-2);}
using namespace std;
Graph<5000+10,5000+10>g;
ll T;
int n,m,ans[5000+10],tem[5000+10],cnt;
ll limit[5005];

void dfs(int cur,ll curt,int r){
   tem[r]=cur;
   if(limit[cur]==-1) limit[cur]=curt;
   if(num[cur]==-1) num[cur]=r;
   if(curt>limit[cur]&&num[cur]>=r) return;
   if(cur==n){
      if(curt<=T&&r>cnt){
         for(int i=0;i<=r;i++) ans[i]=tem[i];
         cnt=r;
      }
      return;
   }
   for(int i=g.V[cur].head;i!=-1;i=g.E[i].next){
       int son=g.E[i].v;
       if(curt+g.E[i].t<=T){
            dfs(son,curt+g.E[i].t,r+1);
       }
   }
}

int main(){
   while(~scanf("%d%d%I64d",&n,&m,&T)){
       g.init();
       for(int i=1;i<=n;i++) limit[i]=-1,num[i]=-1;
       for(int i=0;i<m;i++){
          int a,b;
          ll c;scanf("%d%d%I64d",&a,&b,&c);
          g.add_edge(a,b,c);
       }
       cnt=0;
       dfs(1,0,0);
       printf("%d\n",cnt+1);
       for(int i=0;i<cnt;i++){
          printf("%d ",ans[i]);
       }
       printf("%d\n",ans[cnt]);
   }
}
*/
#include<bits/stdc++.h>
using namespace std;
const int maxn=5000+5;
template<int N,int M>
struct Graph
{
    int top;
    struct Vertex{
        int head;
    }V[N];
    struct Edge{
        int v,next,t;
    }E[M];
    void init(){
        memset(V,-1,sizeof(V));
        top = 0;
    }
    void add_edge(int u,int v,int t){
        E[top].v = v;
        E[top].t=t;
        E[top].next = V[u].head;
        V[u].head = top++;
    }
};
Graph<maxn,maxn> g;

int n,m,T,dp[maxn][maxn],pre[maxn][maxn],vis[maxn];

void dfs(int cur){
   if(vis[cur]!=0) return; vis[cur]=1;
   if(cur==1) dp[cur][1]=0;
   for(int i=g.V[cur].head;i!=-1;i=g.E[i].next){
       int f=g.E[i].v;dfs(f);
       for(int j=1;j<=n;j++){
          if(dp[f][j-1]+g.E[i].t<dp[cur][j]){
             dp[cur][j]=dp[f][j-1]+g.E[i].t;
             pre[cur][j]=f;
          }
       }
   }
}

void print(int t,int x){
   if(t>1) print(t-1,pre[x][t]); printf("%d ",x);
}

int main(){
   while(~scanf("%d%d%d",&n,&m,&T)){
       g.init();
       for(int i=1;i<=n;i++){
         vis[i]=0;
         for(int j=0;j<=n;j++){
            dp[i][j]=0x3fffffff;
         }
       }
       //memset(dp,0x3f,sizeof(dp));
       for(int i=0;i<m;i++){
          int a,b;
          int c;scanf("%d%d%d",&a,&b,&c);
          g.add_edge(b,a,c);
       }
       dfs(n);
       int ans=0;
       for(int i=n;i>=0;i--){
         if(dp[n][i]<=T){
            ans=i;break;
         }
       }
       printf("%d\n",ans);
       print(ans,n);
       printf("\n");
   }
}


#include<bits/stdc++.h>
#define UI unsigned int
#define R register int
#define I inline
using namespace std;
const UI N=5005,inf=2e9;
UI n,cnt,m,h[N],nx[N],to[N],dg[N],pre[N][N],out[N],tot,ans,va[N],dis[N][N],t,dfn[N],ti,srt[N];
queue<int> q;
bool vs[N];
I int read()
{
	int s=0,w=1;char c=getchar();
	while(c<'0'||c>'9')  w=(c=='-')?-1:w,c=getchar();
	while(c>='0'&&c<='9')  s=(s<<3)+(s<<1)+(c^48),c=getchar();
	return s*w;
}
void dfs(int x)
{
	vs[x]=1;
	for(R i=h[x];i;i=nx[i])  dfs(to[i]);
}
bool cmp(int x,int y) {return dfn[x]<dfn[y];}
int main()
{
	n=read();m=read();t=read();
	for(R i=1;i<=n;i++)
		for(R j=1;j<=n;j++)  dis[i][j]=inf;
	dis[1][1]=0;
	for(R i=1;i<=m;i++)  {int x=read();to[++cnt]=read();nx[cnt]=h[x];va[cnt]=read();h[x]=cnt;}
	dfs(1);
	for(R x=1;x<=n;x++)
	{
		if(!vs[x])  continue;
		for(R i=h[x];i;i=nx[i])
			if(vs[to[i]])  dg[to[i]]++;
	}
	dfn[1]=++ti;
	q.push(1);
	while(q.size())
	{
		int x=q.front();q.pop();
		for(R i=h[x];i;i=nx[i])
			if(--dg[to[i]]==0&&vs[to[i]])  q.push(to[i]),dfn[to[i]]=++ti;
	}
	for(R i=1;i<=n;i++)  srt[i]=i;
	sort(srt+1,srt+1+n,cmp);
	for(R k=1;k<=n;k++)
	{
		int x=srt[k];
		if(!vs[x])  continue;
		for(R i=1;i<n;i++)
			{
				if(dis[x][i]==inf)  continue;
				for(R j=h[x];j;j=nx[j])
					if(dis[to[j]][i+1]>dis[x][i]+va[j])  dis[to[j]][i+1]=dis[x][i]+va[j],pre[to[j]][i+1]=x;
			}
	}
	for(ans=n;ans;ans--)
		if(dis[n][ans]<=t)  break;
	for(R j=ans,i=n;j;out[j]=i,i=pre[i][j--]);
	printf("%d\n",ans);
	for(R i=1;i<=ans;i++)  printf("%d ",out[i]);
	return 0;
}


#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
const int maxn=5005;
int n,m,lzy;
vector<int> shu1[maxn],len1[maxn];
vector<int> shu2[maxn],len2[maxn];
int dp[maxn][maxn];
int du[maxn];
queue<int> dui;
bool ex[maxn];
void getans(int now,int num)
{
	int zong=shu2[now].size();
	for(int i=0;i<zong;i++)
	{
		int xia=shu2[now][i],ju=len2[now][i];
		if(num-ju>=0&&dp[xia][num-ju]+1==dp[now][num])
		{
			getans(xia,num-ju);
			break;
		}
	}
	cout<<now<<" ";
	return;
}
int main()
{
	#ifndef DEBUG
	ios::sync_with_stdio(false);
	#endif
	cin>>n>>m>>lzy;
	int u,v,w;
	while(m--)
	{
		cin>>u>>v>>w;
		shu1[u].push_back(v),shu2[v].push_back(u);
		len1[u].push_back(w),len2[v].push_back(w);
		du[v]++;
	}
	for(int i=1;i<=n;i++)
	if(!du[i])
	dui.push(i);
	ex[1]=true;
	memset(dp,-0x3f,sizeof(dp));
	for(int i=0;i<=lzy;i++)
	dp[1][i]=1;
	while(!dui.empty())
	{
		int now=dui.front();dui.pop();
		int zong=shu1[now].size();
		for(int i=0;i<zong;i++)
		{
			int xia=shu1[now][i],ju=len1[now][i];
			if(ex[now])
			{
				ex[xia]=true;
				for(int j=ju;j<=lzy;j++)
				dp[xia][j]=max(dp[xia][j],dp[now][j-ju]+1);
			}
			du[xia]--;
			if(!du[xia])
			dui.push(xia);
		}
	}
	cout<<dp[n][lzy]<<"\n";
	getans(n,lzy);
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
using namespace std;
const int inf=0x3f3f3f3f;
int n,t,m,u[5005],v[5005],d[5005],last[5005][5005];
int f[5005][5005],sizes[5005],maxx[5005],mean[5005];
struct node{
	int v,len;
};
vector<node>a[5005];
vector<int>son[5005];
int num[5005],father[5005];
void top(){
	for(int i=1;i<=n;i++){
	    for(int j=1;j<=n;j++){
	    	if(father[j]==0){
	    		father[j]=-1;
	    		mean[i]=j;num[j]=i;
	    		for(int k=0;k<son[j].size();k++){
	    			father[son[j][k]]--;
				}
				break;
			}
		}
	}
}
int main(){
	scanf("%d%d%d",&n,&m,&t);
	for(int i=1;i<=m;i++){
		scanf("%d%d%d",&u[i],&v[i],&d[i]);
		son[u[i]].push_back(v[i]);father[v[i]]++;
	}
	top();
	for(int i=1;i<=m;i++){
		u[i]=num[u[i]];
		v[i]=num[v[i]];
	    a[u[i]].push_back((node){v[i],d[i]});
	    sizes[u[i]]++;
	}
	memset(f,inf,sizeof(f));
	for(int i=1;i<=n;i++){
		f[i][0]=0;
	}
	for(int i=1;i<=n;i++){
		for(int j=0;j<sizes[i];j++){
			for(int k=1;k<n;k++){
				if(k==1&&i!=num[1])continue;
				if(f[a[i][j].v][k]>(f[i][k-1]+a[i][j].len)){
					f[a[i][j].v][k]=(f[i][k-1]+a[i][j].len);
					last[a[i][j].v][k]=i;
				}
			}
		}
	}
	int ans=0,tmp=0,s;
	stack<int>h;
	for(int j=0;j<n;j++){
		if(f[num[n]][j]<=t)ans=max(ans,j);
	}
	s=ans;
	tmp=num[n];
	while(tmp){
		h.push(tmp);
		tmp=last[tmp][s--];
	}
	printf("%d\n",ans+1);
	while(h.size()!=1){
		printf("%d ",mean[h.top()]);
		h.pop();
	}
	printf("%d",mean[h.top()]);
    return 0;
}


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

vector<pair<int,int>>g[6000];
int n,m,t,dp[6000][6000],path[6000][6000],pre[6000],in[6000];
bool vis[6000];
queue<int>q;

void out(int x,int now)
{
    if(x<=1)
    {
        if(x)
			printf("%d",x);
        return;
    }
    out(path[x][now],now-1);
    printf(" %d",x);
}

void Print()
{
    int res=0;
    for(int i=n;i>=1;i--)
    {
        if(dp[n][i]<=t)
        {
            res=i;
            break;
        }
    }
    printf("%d\n",res);
    if(res)
        out(n,res);
}

int main()
{
    scanf("%d%d%d",&n,&m,&t);
    for(int i=1;i<=m;i++)
    {
        int a,b,c;
        scanf("%d%d%d",&a,&b,&c);
        g[a].push_back(make_pair(c,b));
        in[b]++;
    }
    memset(dp,0x3f,sizeof(dp));
    dp[1][1]=0;
    for(int i=1;i<=n;i++)
    {
        if(!in[i])
        {
            vis[i]=true;
            q.push(i);
        }
    }
    while(!q.empty())
    {
        int t=q.front();
        q.pop();
        vis[t]=true;
        for(int i=0;i<g[t].size();i++)
        {
            int to=g[t][i].second;
            int cost=g[t][i].first;
            if(in[to])
            {
                in[to]--;
                for(int j=2;j<=n;j++)
                {
                    if(dp[to][j]>dp[t][j-1]+cost)
                    {
                        dp[to][j]=dp[t][j-1]+cost;
                        path[to][j]=t;
                    }
                }
            }
            if(!in[to])q.push(to);
        }
    }
    Print();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const long long INF=1e17;
struct e{
	long long nxt,to,v;
}a[50005],b[50005];

struct o{
	long long v,prt,i;
};

long long n,m,h[50050],hb[50005],tt,tot,rd[50005],T;
long long d[50005],vv[50005];

map<int,o>ans[50005];

void add(long long x,long long y,long long v){
	a[++tot]=(e){h[x],y,v};
	rd[y]++;
	h[x]=tot;
}

void add2(long long x,long long y,long long v){
	b[++tt]=(e){hb[x],y,v};
	hb[x]=tt;
}

void spfa(){
	long long i,j,k,x,y;
	queue<long long>q;
	q.push(n);
	for(i=1;i<=n;i++){
		d[i]=INF;
	}
	d[n]=0;
	while(!q.empty()){
		x=q.front();
		q.pop();
		for(i=hb[x];i;i=b[i].nxt){
			y=b[i].to;
			if(d[y]>d[x]+b[i].v){
				d[y]=d[x]+b[i].v;
				q.push(y);
			}
		}
	}
}

int main(){
	ios::sync_with_stdio(false);
	long long i,k,x,y,v;
	cin>>n>>m>>T;
	for(i=1;i<=m;i++){
		cin>>x>>y>>v;
		add(x,y,v);
		add2(y,x,v);
	}
	spfa();

	queue<long long>q;
	q.push(1);

	ans[1][1]=(o){0,0,0};

	while(!q.empty()){
		x=q.front();
		q.pop();

		for(i=h[x];i;i=a[i].nxt){
			y=a[i].to;

			for(auto &j : ans[x]){

				if(j.second.v+a[i].v+d[y]>T)continue;
				if(ans[y].count(j.first+1)&&ans[y][j.first+1].v>j.second.v+a[i].v)continue;

				ans[y][j.first+1]=(o){j.second.v+a[i].v,x,j.first};

			}

			rd[y]--;
			if(!rd[y])q.push(y);

		}
		//cout<<q.size()<<endl;
	}

	//for(i=1;i<=n;i++)cout<<d[i]<<" ";cout<<endl;

	for(auto &j : ans[n])k=j.first;

	cout<<k<<endl;
	x=n;y=ans[n][k].prt;tot=0;k=ans[n][k].i;
	while(x!=0){
		//cout<<x<<endl;
		vv[++tot]=x;
		x=y;
		if(!x)break;
		y=ans[x][k].prt;
		k=ans[x][k].i;
	}
	for(i=tot;i>=1;i--){
		cout<<vv[i]<<" ";
	}
	return 0;
}


#include<cstdio>
#include<iostream>
#include<vector>
using namespace std;
vector<int> a[5005],b[5005];
int n,m,k,dis[5005][5005],pre[5005][5005],h,t;
int q[10005],vis[5005],uu,vv,s,mmin,sum,ans[5005];
void add(int x,int y,int v)
{
	a[x].push_back(y);
	b[x].push_back(v);
}
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	if (n==1)
	{
		printf("1\n1\n");
		return 0;
	}
	for (int i=1;i<=n;i++) a[i].push_back(0),b[i].push_back(0);
	for (int i=1;i<=m;i++)
	{
		int x,y,v;
		scanf("%d%d%d",&x,&y,&v);
		add(x,y,v);
	}
	for (int i=0;i<=n;i++)
	    for (int j=0;j<=n;j++)
	        dis[i][j]=1000005000,pre[i][j]=-1;
	dis[1][1]=0,pre[1][1]=-1;
	h=0,t=0;
    t++;
    q[t]=1;
    vis[1]=1;
	while (h<t)
	{
		h++;
		vv=q[h];
		vis[vv]=false;
		for (int i=0;i<=n;i++)
		    if (dis[vv][i]>k) dis[vv][i]=1000005000,pre[vv][i]=-1;
		for (int i=1;i<a[vv].size();i++)
		{
			uu=a[vv][i],s=b[vv][i];
			for (int j=1;j<=n;j++)
			    if (dis[uu][j]>dis[vv][j-1]+s)
			    {
					dis[uu][j]=dis[vv][j-1]+s;
			    	pre[uu][j]=vv;
				}
			if (!vis[uu])
			{
				t++;
				q[t]=uu;
				vis[uu]=1;
			}
		}
	}
	mmin=0;
	for (int i=1;i<=n;i++)
	    if (dis[n][i]!=1000005000) mmin=i;
	printf("%d\n",mmin);
    mmin++;
	for (int i=n,k=1;i>1&&k<10005;i=pre[i][mmin],k++)
	{
		sum++;
		ans[sum]=i;
        mmin--;
	}
	sum++;
	ans[sum]=1;
	for (int i=sum;i>=1;i--)
	    printf("%d ",ans[i]);
	printf("\n");
	return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;
const int MAXN=5001;
const long long INF=1e15;
int n,m,T,du[MAXN],pre[MAXN][MAXN],siz[MAXN];
long long f[MAXN][MAXN];
int tot,front[MAXN],to[MAXN],nxt[MAXN],di[MAXN];
void init(int u,int v,int d)
{
	to[++tot]=v;
	di[tot]=d;
	nxt[tot]=front[u];
	front[u]=tot;
}
int q[MAXN];
int main()
{
//	freopen("test.in","r",stdin);
//	freopen("test.out","w",stdout);
	scanf("%d%d%d",&n,&m,&T);
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)f[i][j]=INF;
	for(int i=1,x,y,d;i<=m;i++)
	{
		scanf("%d%d%d",&x,&y,&d);
		init(x,y,d);
		du[y]++;
	}
	int head=0,tail=0;
	for(int i=1;i<=n;i++)
		if(du[i]==0)
			q[++tail]=i;
	f[1][1]=0;
	siz[1]=1;
	while(head<tail)
	{
		int u=q[++head];
		for(int i=front[u];i;i=nxt[i])
		{
			int v=to[i],d=di[i];
			du[v]--;
			if(du[v]==0)q[++tail]=v;
			for(int j=2;j<=siz[u]+1;j++)
				if(f[v][j]>f[u][j-1]+d)
					f[v][j]=f[u][j-1]+d,pre[v][j]=u;
			siz[v]=max(siz[u]+1,siz[v]);
		}
	}
	int ans=0;
	for(int i=1;i<=siz[n];i++)
		if(f[n][i]<=T)
			ans=max(ans,i);
	printf("%d\n",ans);
	for(int i=ans,u=n;i>=1;i--)
	{
		q[i]=u;
		u=pre[u][i];
	}
	for(int i=1;i<=ans;i++)
		printf("%d ",q[i]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int INF=1e9+1;
struct Point
{
	int cost,to;
	Point(){}
	Point(int to,int cost)
	{
		this->cost=cost;
		this->to=to;
	}
};
int n,m,T;
int cnt=0;
queue<int> que;
vector<Point> vec[5010];
bool vis[5010];
int in_degree[5010];
int dp[5010][5010];
int prev[5010][5010];
stack<int> sta;
void dfs()
{
	while(cnt<n)
		for(int i=0;i<n;i++)
			if(in_degree[i]==0&&!vis[i])
			{
				que.push(i);
				vis[i]=true;
				cnt++;
				for(int j=0;j<vec[i].size();j++)
				{
					int to=vec[i][j].to;
					in_degree[to]--;
				}
			}
	while(!que.empty())
	{
		int now=que.front();
		que.pop();
		for(int i=0;i<vec[now].size();i++)
		{
			int to=vec[now][i].to;
			int cost=vec[now][i].cost;
			for(int j=1;j<n;j++)
			{
				if(dp[now][j-1]+cost<dp[to][j])
				{
					dp[to][j]=dp[now][j-1]+cost;
					prev[to][j]=now;
				}
			}
		}
	}
}
void out()
{
	int max_num=0;
	for(int i=0;i<n;i++)
	{
		if(dp[n-1][i]<=T)
		{
			max_num=max(max_num,i);
		}
	}
	cout<<max_num+1<<endl;
	int now=n-1;
	sta.push(now);
	while(now)
	{
		sta.push(prev[now][max_num]);
		now=prev[now][max_num];
		max_num--;
	}
	while(!sta.empty())
	{
		cout<<sta.top()+1;
		sta.pop();
		if(sta.empty())
			cout<<endl;
		else cout<<" ";
	}
}
int main()
{
	memset(vis,0,sizeof(vis));
	memset(in_degree,0,sizeof(in_degree));
	cin>>n>>m>>T;
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			dp[i][j]=INF;
    dp[0][0]=0;
	while(m--)
	{
		int a,b,c;
		cin>>a>>b>>c;
		a--;
		b--;
		vec[a].push_back(Point(b,c));
		in_degree[b]++;
	}
	dfs();
	out();
}


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

#define fi first
#define se second
int n, m, T;
vector <pair <int, int> > E[5005];
int ans;
int path[5005];
vector <int> fpath;

void dfs (int id, int num, int t)
{
	if (t > T)
		return;

	path[num] = id;
	if (id == n){
		if (num > ans){
			ans = num;
			fpath.clear();
			for (int i=1; i<=num; i++)  fpath.push_back (path[i]);
		}
	}

	for (int i=0; i<E[id].size(); i++){
		dfs (E[id][i].fi, num+1, t+E[id][i].se);
	}
}

int main()
{
	cin >> n >> m >> T;
	for (int i=1; i<=m; i++){
		int u, v, w;
		cin >> u >> v >> w;
		E[u].push_back ({v, w});
	}

	dfs (1, 1, 0);
	printf ("%d\n", ans);
	for (int i=0; i<fpath.size(); i++)  printf ("%d ", fpath[i]);
	puts ("");
	return 0;
}


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

vector <pair <int, int> > G[5050], d[5050];
struct node {
    int u, c;
};

int pre[5005][5005], dm[5005][5005];

int main() {
    int n, m, T;
    scanf("%d %d %d", &n, &m, &T);
    while (m --) {
        int u, v, w;
        scanf("%d %d %d", &u, &v, &w);
        G[u].emplace_back(v, w);
    }
    queue <node> q;
    q.push({1, 1});
    int ans = 0, st;
    while (q.size()) {
        auto d = q.front();
        q.pop();
        int u = d.u;
        if (u == n && d.c > ans) ans = d.c;
        for (auto e : G[u]) {
            int v = e.first, w = e.second;
            if (w + dm[u][d.c] > T) continue;
            if (! dm[v][d.c + 1]) {
                dm[v][d.c + 1] = dm[u][d.c] + w;
                pre[v][d.c + 1] = u;
                q.push({v, d.c + 1});
            } else if (dm[v][d.c + 1] > dm[u][d.c] + w) {
                dm[v][d.c + 1] = dm[u][d.c] + w;
                pre[v][d.c + 1] = u;
            }
        }
    }
    cout << ans << "\n1 ";
    stack <int> stk;
    while (1) {
        stk.push(n);
        n = pre[n][ans --];
        if (ans == 1) break;
    }
    while (stk.size()) {
        cout << stk.top() << " ";
        stk.pop();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
struct edge{
	int v,len;
	edge(){

	}
	edge(int vv,int llen){
		v = vv;
		len = llen;
	}
};
vector<edge> vec[5010];
int n,m,k;
int dp[5010][5010];
int pre[5010][5010];
int dfs(int u,int cnt){
	if(cnt <= 0){
		return 0x3f3f3f3f;
	}
	if(dp[u][cnt] != 0x3f3f3f3f){
		return dp[u][cnt];
	}
	for(int i = 0;i < vec[u].size();i++){
		if(dfs(vec[u][i].v,cnt-1)+vec[u][i].len < dp[u][cnt]){
			dp[u][cnt] = dfs(vec[u][i].v,cnt-1)+vec[u][i].len;
			pre[u][cnt] = vec[u][i].v;
		}
	}
	return dp[u][cnt];
}
int main(){
	scanf("%d%d%d",&n,&m,&k);
	memset(dp,0x3f3f3f3f,sizeof(dp));
	for(int i = 1;i <= m;i++){
		int u,v,len;
		scanf("%d%d%d",&u,&v,&len);
		vec[v].push_back(edge(u,len));
	}
	dp[1][1] = 0;
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= n;j++){
			dfs(i,j);
		}
	}
	for(int i = n;i >= 1;i--){
		if(dp[n][i] <= k){
			printf("%d\n",i);
			int ans[5010];
			for(int j = i-1;j >= 0;j--){
				ans[j] = n;
				n = pre[n][j+1];
			}
			for(int j = 0;j < i;j++){
				if(j == i-1){
					printf("%d\n",ans[j]);
				}else{
					printf("%d ",ans[j]);
				}
			}
			break;
		}
	}
	return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
using namespace std;
#define debug(x) cerr << #x << "=" << x << endl;
typedef long long ll;
const int MAXN = 5000 + 10;
int n,m,k,ans,edge_tot,tot;
int ind[MAXN],last[MAXN],pre[MAXN][MAXN],pla[MAXN];
ll dp[MAXN][MAXN];
queue<int> q;
struct Edge{
	int u, v, w, to;
	Edge(){}
	Edge(int u, int v, int w, int to) : u(u), v(v), w(w), to(to) {}
}e[MAXN];
inline void add(int u, int v, int w) {
	e[++edge_tot] = Edge(u, v, w, last[u]);
	last[u] = edge_tot;
}
void topo() {
	for(int i=1; i<=n; i++)
		if(!ind[i]) q.push(i);
	while(!q.empty()) {
		int x = q.front();
		q.pop();
		for(int i=last[x]; i; i=e[i].to) {
			int v = e[i].v, w = e[i].w;
			ind[v]--;
			if(!ind[v]) q.push(v);
			for(int j=1; j<=n; j++) {
				if(dp[x][j-1] + w <= k) {
					if(dp[v][j] > dp[x][j-1] + w) {
						dp[v][j] = dp[x][j-1] + w;
						pre[v][j] = x;
					}
				}
			}
		}
	}
}
int main() {
	scanf("%d%d%d", &n, &m, &k);
	for(int i=1; i<=m; i++) {
		int u, v, w;
		scanf("%d%d%d", &u, &v, &w);
		ind[v]++;
		add(u, v, w);
	}
	ll temp_inf = 1ll << 62;
	for(int i=0; i<=n; i++) {
		for(int j=0; j<=n; j++) {
			dp[i][j] = temp_inf;
		}
	}
	dp[1][1] = 0;
	pre[1][1] = 1;
	topo();
	for(int i=1; i<=n; i++) {
		if(dp[n][i] != temp_inf) ans = i;
	}
	printf("%d\n", ans);
	pla[++tot] = n;
	for(int i=ans; i>1; i--) {
		pla[++tot] = pre[pla[tot-1]][i];
	}
	for(int i=tot; i; i--) {
		printf("%d ", pla[i]);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn=5111;
struct node{
	int point,cost;
}ans[maxn];
int dp[maxn][maxn];
vector<node>ts[maxn];
queue<node>q;
int pre[maxn][maxn],n,t;
bool used[maxn][maxn]={0};
void BFS(){
	int i,j;
	for(i=0;i<=n;i++)
	   for(j=0;j<=n;j++){
	      dp[i][j]=t+1;
	      pre[i][j]=0;
	   }
	node start;
	start.point=1;
	start.cost=1;
	q.push(start);
	used[1][1]=1;
	dp[1][1]=0;
	while(!q.empty()){
		node now=q.front();
		q.pop();
		int u=now.point,v=now.cost;
		used[u][v]=0;
		for(i=0;i<ts[u].size();i++){
			int x=ts[u][i].point;
			int y=ts[u][i].cost;
			if(dp[u][v]+y>t)continue;
			if(dp[x][v+1]>dp[u][v]+y){
				 dp[x][v+1]=dp[u][v]+y;
				 pre[x][v+1]=u;
				 if(used[x][v+1])continue;
				 used[x][v+1]=1;
				 node nexts;
				 nexts.point=x;
				 nexts.cost=v+1;
				 q.push(nexts);
			}
		}
	}
}
void init(int x,int y){
	if(pre[x][y]!=0)
	  init(pre[x][y],y-1);
	if(x==n)printf("%d\n",x);
	else  printf("%d ",x);
}
int  main(){
	int x,y,z,m;
	scanf("%d%d%d",&n,&m,&t);
	for(int i=1;i<=m;i++){
		scanf("%d%d%d",&x,&y,&z);
		node t1;
		t1.point=y;
		t1.cost=z;
		ts[x].push_back(t1);
	}
	BFS();
	int ans=0;
	for(int i=1;i<=n;i++)
	  if(dp[n][i]<=t)
	     ans=i;
	printf("%d\n",ans);
	init(n,ans);
}


#include <bits/stdc++.h>

using namespace std;
const int maxn=5010;
int n,m,t,rudu[maxn],result[maxn];

int inf=2e9+10;
vector<int >g[maxn],len[maxn],dp[maxn],save[maxn];
void add(int u,int v,int k)
{
    g[u].push_back(v);
    len[u].push_back(k);
    rudu[v]++;
    return;
}
int main()
{
    scanf("%d%d%d",&n,&m,&t);
    int u,v,k;
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d%d",&u,&v,&k);
        add(u,v,k);
    }
    stack<int> s;
    s.push(1);
    dp[1].push_back(inf);
    dp[1].push_back(0);

    while(!s.empty())
    {
        int now=s.top();
        s.pop();
        int l=g[now].size();
        int ldp=dp[now].size();
        for(int i=0;i<l;i++)
        {
            int next=g[now][i];
            int ldpnext=dp[next].size();
            if(!ldpnext)
            {
                dp[next].push_back(inf);
                save[next].push_back(inf);
            }
            int j=1;
            for(;j<=min(ldp,ldpnext);j++)
            {
                long long fare=dp[now][j-1]+len[now][i];
                if(dp[next][j]>fare&&t>=fare)
                {
                    dp[next][j]=fare;
                    save[next][j]=now;
                }
            }
            for(;j<=ldp;j++)
            {
                long long fare=dp[now][j-1]+len[now][i];
                dp[next].push_back(fare);
                save[next].push_back(now);
            }
            rudu[next]--;
            if(rudu[next]==0)s.push(next);
        }
        if(now!=n)dp[now].clear();
        g[now].clear();
        len[now].clear();
    }
    int ans=0,ldp=dp[n].size();
    for(int i=1;i<ldp;i++)if(dp[n][i]<=t)ans=i;
    int now=n;
    for(int i=ans;i;i--)
    {
        result[i]=now;
        if(now!=1)now=save[now][i];
    }
    printf("%d\n",ans);
    for(int i=1;i<=ans;i++)
    {
        printf("%d ",result[i]);
    }
    return 0;
}


#ifdef MY_IDE
#include "stdc++.h"
#else
#include <bits/stdc++.h>
#endif
using namespace std;
#define ll long long
#define N 10010
ll n,m,t ,ans,fa[N],tag;
int aa[N],top=0;
vector <int> way[N];
vector <ll> cost[N];
bool book[N];
bool dfs(int x)
{
	if(x==n)
	{
		book[x]=true;
		return true;
	}
	bool ok=false;
	for(int i=0;i<way[x].size();i++)
		if(dfs(way[x][i]))
			ok=true;
	if(ok) book[x]=true;
	return ok;
}
bool BFS(int x,int f,ll dis,ll num)
{
	if(!book[x]) return false;
	if(dis>t) return false;
	bool flag= false;
	if(ans<num)
	{
		ans=num;
		fa[x]=f;
		tag=x;
		flag=true;
	}
	for(int i=0;i<way[x].size();i++)
		if(BFS(way[x][i],x,dis+cost[x][i],num+1))
			fa[x]=f;
	return flag;
}
int main()
{
#ifdef MY_IDE
	ifstream cin;
	cin.open("in.txt");
#endif
	int a,b;
	ll c;
	cin>>n>>m>>t;
	for(int i=1;i<=m;i++)
	{
		cin >> a >> b >> c;
		way[a].push_back(b);
		cost[a].push_back(c);
	}
	dfs(1);
	BFS(1,0,0,1);
	cout << ans << endl;
	for(int i=tag;i;i=fa[i])
		aa[++top]=i;
	for(int i=top;i>0;i--)
		cout << aa[i] << " ";
	return 0;
}


#include<bits/stdc++.h>
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
#define pb push_back
using namespace std;
const int N=5005;
vector<vector<pii> >g(N);
int n,m,t,dp[N][N],path[N][N];
void out(int now,int i)
{
	if(now==-1)return;
	out(path[now][i],i-1);
	cout<<now+1<<' ';
}
int main()
{
	cin>>n>>m>>t;
	while(m--)
	{
		int a,b,c;
		cin>>a>>b>>c;
		a--,b--;
		g[a].pb(mp(b,c));
	}
	for(int i=0;i<N;i++)for(int j=0;j<N;j++)dp[i][j]=2e9;
	dp[0][0]=0;
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(dp[j][i]==2e9)continue;
			for(int k=0;k<g[j].size();k++)
			{
				int a=g[j][k].F;
				int b=g[j][k].S;
				int Time=dp[j][i]+b;
				if(dp[a][i+1]>Time)
				{
					dp[a][i+1]=Time;
					path[a][i+1]=j;
				}
			}
		}
	}
	for(int i=n;i>=0;i--)
	{
		if(dp[n-1][i]<=t)
		{
			cout<<i+1<<endl;
			out(n-1,i);
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,m;
long long T;
struct edge {
	int to;
	long long len;
};
vector<edge>ed[5010];
long long dp[5010][5010];
inline void ade(int l,int r,int val) {
	ed[l].push_back({r,val});
}

inline void dfs(int nw) {
//	printf("nowdfs : %d\n",nw);
	for(int i=0;i<ed[nw].size();++i) {
		int tar = ed[nw][i].to;
		long long nlen = ed[nw][i].len;
		dfs(tar);
		for(int j=1;j<=n;++j) {
//			printf("DFS : %d %d %d %lld %lld\n",nw,tar,j,dp[nw][j],dp[tar][j-1] + nlen);
			dp[nw][j] = min(dp[nw][j], dp[tar][j-1] + nlen);
		}
	}
}

void pritdfs(int nw,int val) {
	printf("%d ",nw);
	for(int i=0;i<ed[nw].size();++i) {
		int tar = ed[nw][i].to;
		long long nlen = ed[nw][i].len;
		if(dp[nw][val] == dp[tar][val-1] + nlen) {
			pritdfs(tar,val-1);
			break;
		}
	}
}

int main() {
	memset(dp,0x3f,sizeof(dp));
	long long lim,val;
	int l,r; long long len;
	scanf("%d%d",&n,&m);
	cin>>lim;
	for(int i=1;i<=m;++i)
		scanf("%d%d%lld",&l,&r,&val),ade(l,r,val);
	dp[n][0] = 0;
	dfs(1);
	int ans = 0;
	for(int i = n;i>=1;--i) {
		if(dp[1][i] <= lim) {
			printf("%lld\n",i+1);
			ans = i;
			break;
		}
	}
	pritdfs(1,ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<ctime>
#define rg register
#define il inline
#define INF 2147483647
#define min(x,y) ((x<y)?(x):(y))
using namespace std;
int n,m,e,head[5005],K,top[5005],dp[5005][5005],zhan[5005],tail,ans,Ans[5005],cnt,rec[5005][5005];
struct Cwen
{
    int to,next;
    int w;
    bool b;
}edge[20005];
il void link(int u,int v,int w,bool b)
{
//    cout<<"cao"<<b<<endl;
//cout<<u<<"->"<<v<<endl;
    edge[++e].to=v;
    edge[e].next=head[u];
    edge[e].w=w;
    edge[e].b=b;
    head[u]=e;
}
il int read()
{
    rg int save=0, w=1; rg char q=getchar();
    while(q<'0'||q>'9'){if(q=='-')w=-1;q=getchar();}
    while(q>='0'&&q<='9') save=(save<<3)+(save<<1)+q-'0', q=getchar();
    return save*w;
}
void getans(int i,int now)
{
    Ans[++cnt]=i;// cout<<'!'<<i<<' ';
    if(i==1) return;
    int j; bool flag=0;
    for(j=head[i];j;j=edge[j].next)
    {
        if(edge[j].b) continue;
        int to=edge[j].to, w=edge[j].w;
        if(flag) break;
        if(dp[to][now-1]==dp[i][now]-w)
        {
//            cout<<"?"<<to<<' ';
            flag=1;
            getans(to,now-1);
        }
    }

}
void Run()
{
    int i,j,k;
    zhan[++tail]=1;
    for(j=1;j<=n;++j)
        for(k=0;k<=n;++k)
            dp[j][k]=INF;
    dp[1][1]=0;
    for(i=1;i<=tail;++i)
    {
        int temp=i; i=zhan[i];
        for(j=head[i];j;j=edge[j].next)
        {
            if(!edge[j].b) continue;
            int to=edge[j].to, w=edge[j].w;

            top[to]--;
            if(!top[to]) zhan[++tail]=to;

            for(k=1;k<=n-1;++k)
            {
                if(dp[i][k]!=INF)
                {
                    if(dp[i][k]+w<dp[to][k+1])
                    {
                        dp[to][k+1]=dp[i][k]+w;
                        rec[to][k+1]=i;
                    }
                }
            }
        }
        i=temp;
    }
/*    for(i=1;i<=n;++i)
    {
        for(j=1;j<=n;++j)
            cout<<"dp["<<i<<"]["<<j<<"]"<<dp[i][j]<<' ';
        puts("");
    }
*/  for(i=n;i>=1;--i)
        if(dp[n][i]<=K){ ans=i; break; }
    printf("%d\n",ans);
    i=n;
    while(ans)
    {
        Ans[++cnt]=i;
        i=rec[i][ans];
        ans--;
    }

//    getans(n,ans);
    for(i=cnt;i>=1;--i) printf("%d ",Ans[i]);
}
il void doit()
{
    n=read(), m=read(), K=read();
    int i;
    for(i=1;i<=m;++i)
    {
        int u=read(), v=read(), w=read();  //u->v有边
        link(u,v,w,1);  //建正边
        link(v,u,w,0);  //建反边
//        cout<<"!!!"<<u<<' '<<v<<' '<<w<<endl;
        top[v]++;
    }
//    for(i=1;i<=n;++i) cout<<top[i]<<endl;
    top[1]=0;
    Run();  //跑拓扑
}
int main()
{
    doit();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN=5000+10;
int n,m,k;
struct Node
{
    int to,next;
    int w;
}edge[MAXN];
int head[MAXN],cnt;
int d[MAXN][MAXN];
bool inq[MAXN][MAXN];
typedef pair<int,int>p;
inline int read()
{
    int tot=0;char c=getchar();
    while(c<'0'||c>'9')c=getchar();
    while(c>='0'&&c<='9'){tot=(tot<<1)+(tot<<3)+c-'0';c=getchar();}
    return tot;
}
inline void add(int x,int y,int z)
{
    edge[++cnt].to=y;
    edge[cnt].next=head[x];
    edge[cnt].w=z;
    head[x]=cnt;
}
inline int SPFA()
{
    memset(d,0x3f,sizeof(d));
    queue<p>q;
    q.push(p(1,0));
    d[1][0]=0;inq[1][0]=1;
    while(q.size())
    {
        p now=q.front();
        q.pop();
        int x=now.first,y=now.second;
        inq[x][y]=0;
        for(int i=head[x];i;i=edge[i].next)
        {
            int v=edge[i].to;
            if(d[x][y]+edge[i].w<d[v][y+1]&&d[x][y]+edge[i].w<=k)
            {
                d[v][y+1]=d[x][y]+edge[i].w;
                if(!inq[v][y+1])
                {
                    inq[v][y+1]=1;
                    q.push(p(v,y+1));
                }
            }
        }
    }
}
int main()
{
    n=read();m=read();k=read();
    for(int i=1;i<=m;i++)
    {
        int x=read(),y=read(),z=read();
        add(x,y,z);
    }
    SPFA();
    int i;
    for(i=n;i>=1;i--)
        if(d[n][i]<=k)break;
    printf("%d\n",i+1);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
struct edge{
	int v,len;
	edge(){

	}
	edge(int vv,int llen){
		v = vv;
		len = llen;
	}
};
vector<edge> vec[5010];
int n,m,k;
int dp[5010][5010];
int pre[5010][5010];
int dfs(int u,int cnt){
	if(cnt <= 0){
		return 0x3f3f3f3f;
	}
	if(dp[u][cnt] != 0x3f3f3f3f){
		return dp[u][cnt];
	}
	for(int i = 0;i < vec[u].size();i++){
		if(dfs(vec[u][i].v,cnt-1)+vec[u][i].len < dp[u][cnt]){
			dp[u][cnt] = dfs(vec[u][i].v,cnt-1)+vec[u][i].len;
			pre[u][cnt] = vec[u][i].v;
		}
	}
	return dp[u][cnt];
}
int main(){
	cin >> n >> m >> k;
	memset(dp,0x3f3f3f3f,sizeof(dp));
	for(int i = 1;i <= m;i++){
		int u,v,len;
		cin >> u >> v >> len;
		vec[v].push_back(edge(u,len));
	}
	dp[1][1] = 0;
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= n;j++){
			dfs(i,j);
		}
	}
	for(int i = n;i >= 1;i--){
		if(dp[n][i] <= k){
			cout << i << endl;
			int ans[5010];
			for(int j = i-1;j >= 0;j--){
				ans[j] = n;
				n = pre[n][j+1];
			}
			for(int j = 0;j < i;j++){
				if(j == i-1){
					cout << ans[j] << endl;
				}else{
					cout << ans[j] << " " ;
				}
			}
		}
	}
	return 0;
}


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

#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define trace1(x)                cout<<#x<<": "<<x<<endl;
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl;
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl;
#define trace6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);

typedef long long int lli;
typedef lli ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<lli, lli> plli;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pair<int, int> > vpii;
typedef vector<pair<lli, lli> > vplli;
typedef vector<lli> vlli;
typedef vector<vlli> vvlli;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;

#define PI 3.141592653589793
#define mod (lli)(1000*1000*1000+7)

template<typename T> T gcd(T a, T b) { if (a == 0) return b; return gcd(b % a, a); }
template<typename T> T pow(T a, T b, lli m) {T ans = 1; while (b > 0) { if (b % 2 == 1) ans = ((ans % m) * (a % m)) % m; b /= 2; a = ((a % m) * (a % m)) % m; } return ans % m; }
template<typename T> void tracev(vector<T> &a) { for(auto &i:a) { cout<<i<<' '; } cout<<'\n'; }
template<typename T> void tracevv(vector<T> &a) { for(auto &i:a) { tracev(i); } }
template<typename T> void tracevp(vector<T> &a) { for(auto &i:a) { trace2(i.ff, i.ss); } cout<<'\n'; }

unordered_map<int, char> ch;
void dfs(int ii, int jj, int gv, int ex, vector<vb> &vs, vector<string> &a, int taken, int val){
	if(vs[ii][jj]) return;
	vs[ii][jj] = true;
	if(a[ii][jj] == 'R'){
		taken++;
	}
	a[ii][jj] = ch[val];
		// trace5(ii, jj, val, taken, ex);

	if(taken == gv + int(bool(ex))){
		val++;
		if(ex > 0) ex--;
		taken = 0;
	}
	// trace3(val, taken, ex);
	if(ii+1 < a.size()) dfs(ii+1, jj, gv, ex, vs, a, taken, val);
	if(ii-1 >= 0) dfs(ii-1, jj, gv, ex, vs, a, taken, val);
	if(jj+1 < a[0].size()) dfs(ii, jj+1, gv, ex, vs, a, taken, val);
	if(jj-1 >= 0) dfs(ii, jj-1, gv, ex, vs, a, taken, val);
}
int main(){
fio;
	for(int i = 0 ; i < 26 ; i ++){
		ch[10+i] = 'a'+i;
		ch[36+i] = 'A'+i;
	}
	for(int i = 0 ; i < 10 ; i++){
		ch[i] = '0'+i;
	}

	int t;
	cin>>t;
	while(t--){
		int r,c,k;
		cin>>r>>c>>k;
		vector<string> a(r);
		for(int i = 0 ; i < r ; i++) cin>>a[i];
		int rice = 0;
		for(int i = 0 ; i < r ; i++){
			for(int j = 0 ; j < c ; j++){
				if(a[i][j] == 'R'){
					rice++;
				}
			}
		}
		vector<vector<bool>> vs(r, vector<bool> (c, false));
		int gv = rice/k;
		int ex = rice%k;
		dfs(0, 0, gv, ex, vs, a, 0, 0);
		for(auto &i:a){
			cout<<i<<'\n';
		}
	}

	return 0;
}


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

#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define trace1(x)                cout<<#x<<": "<<x<<endl;
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl;
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl;
#define trace6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);

typedef long long int lli;
typedef lli ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<lli, lli> plli;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pair<int, int> > vpii;
typedef vector<pair<lli, lli> > vplli;
typedef vector<lli> vlli;
typedef vector<vlli> vvlli;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;

#define PI 3.141592653589793
#define mod (lli)(1000*1000*1000+7)

template<typename T> T gcd(T a, T b) { if (a == 0) return b; return gcd(b % a, a); }
template<typename T> T pow(T a, T b, lli m) {T ans = 1; while (b > 0) { if (b % 2 == 1) ans = ((ans % m) * (a % m)) % m; b /= 2; a = ((a % m) * (a % m)) % m; } return ans % m; }
template<typename T> void tracev(vector<T> &a) { for(auto &i:a) { cout<<i<<' '; } cout<<'\n'; }
template<typename T> void tracevv(vector<T> &a) { for(auto &i:a) { tracev(i); } }
template<typename T> void tracevp(T &a) { for(auto &i:a) { trace2(i.ff, i.ss); } cout<<'\n'; }

unordered_map<int, char> ch;
void dfs(int ii, int jj, int gv, int ex, vector<vb> &vs, vector<string> &a, int taken, int val){
	if(vs[ii][jj]) return;
	vs[ii][jj] = true;
	if(a[ii][jj] == 'R'){
		taken++;
	}
	a[ii][jj] = ch[val];
		// trace5(ii, jj, val, taken, ex);

	if(taken == gv + int(bool(ex))){
		if(val < 61) val++;
		if(ex > 0) ex--;
		taken = 0;
	}
	// trace3(val, taken, ex);
	if(ii+1 < a.size()) dfs(ii+1, jj, gv, ex, vs, a, taken, val);
	if(ii-1 >= 0) dfs(ii-1, jj, gv, ex, vs, a, taken, val);
	if(jj+1 < a[0].size()) dfs(ii, jj+1, gv, ex, vs, a, taken, val);
	if(jj-1 >= 0) dfs(ii, jj-1, gv, ex, vs, a, taken, val);
}
int main(){
fio;
	for(int i = 0 ; i < 26 ; i ++){
		ch[i] = 'a'+i;
		ch[26+i] = 'A'+i;
	}
	for(int i = 0 ; i < 10 ; i++){
		ch[52+i] = '0'+i;
	}
	int t;
	cin>>t;
	while(t--){
		int r,c,k;
		cin>>r>>c>>k;
		vector<string> a(r);
		for(int i = 0 ; i < r ; i++) cin>>a[i];
		int rice = 0;
		for(int i = 0 ; i < r ; i++){
			for(int j = 0 ; j < c ; j++){
				if(a[i][j] == 'R'){
					rice++;
				}
			}
		}
		vector<vector<bool>> vs(r, vector<bool> (c, false));
		int gv = rice/k;
		int ex = rice%k;
		dfs(0, 0, gv, ex, vs, a, 0, 0);
		for(auto &i:a){
			cout<<i<<'\n';
		}
	}

	return 0;
}


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

#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define trace1(x)                cout<<#x<<": "<<x<<endl;
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl;
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl;
#define trace6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);

typedef long long int lli;
typedef lli ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<lli, lli> plli;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pair<int, int> > vpii;
typedef vector<pair<lli, lli> > vplli;
typedef vector<lli> vlli;
typedef vector<vlli> vvlli;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;

#define PI 3.141592653589793
#define mod (lli)(1000*1000*1000+7)

template<typename T> T gcd(T a, T b) { if (a == 0) return b; return gcd(b % a, a); }
template<typename T> T pow(T a, T b, lli m) {T ans = 1; while (b > 0) { if (b % 2 == 1) ans = ((ans % m) * (a % m)) % m; b /= 2; a = ((a % m) * (a % m)) % m; } return ans % m; }
template<typename T> void tracev(vector<T> &a) { for(auto &i:a) { cout<<i<<' '; } cout<<'\n'; }
template<typename T> void tracevv(vector<T> &a) { for(auto &i:a) { tracev(i); } }
template<typename T> void tracevp(vector<T> &a) { for(auto &i:a) { trace2(i.ff, i.ss); } cout<<'\n'; }

unordered_map<int, char> ch;
int main(){
fio;
	for(int i = 0 ; i < 26 ; i ++){
		ch[i] = 'a'+i;
		ch[26+i] = 'A'+i;
	}
	for(int i = 0 ; i < 10 ; i++){
		ch[52+i] = '0'+i;
	}
	int t;
	cin>>t;
	while(t--){
		int r,c,k;
		cin>>r>>c>>k;
		vector<string> a(r);
		for(int i = 0 ; i < r ; i++){
			cin>>a[i];
		}
		lli rice = 0;
		for(int i = 0 ; i < r ; i++){
			for(int j = 0 ; j < c ; j++){
				if(a[i][j] == 'R'){
					rice++;
				}
			}
		}
		lli gv = rice/k;
		lli ex = rice%k;
		bool f = true;
		lli taken = 0;
		int nx = 0;
		for(int i = 0 ; i < r ; i++){
			if(f){
				for(int j = 0 ; j < c ; j++){
					char p = a[i][j];
					a[i][j] = ch[nx];
					if(p == 'R'){
						taken++;
						int tk = gv;
						if(ex > 0) tk++;
						if(taken == tk){
							nx++;
							taken = 0;
							ex--;
						}
					}
				}
			}
			else{
				for(int j = c-1 ; j >= 0 ; j--){
					char p = a[i][j];
					a[i][j] = ch[nx];
					if(p == 'R'){
						taken++;
						int tk = gv;
						if(ex > 0) tk++;
						if(taken == tk){
							nx++;
							taken = 0;
							ex--;
						}
					}
				}
			}
			f = !f;
		}
		for(auto &i:a){
			cout<<i<<'\n';
		}

	}

	return 0;
}


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

#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define trace1(x)                cout<<#x<<": "<<x<<endl;
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl;
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl;
#define trace6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);

typedef long long int lli;
typedef lli ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<lli, lli> plli;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pair<int, int> > vpii;
typedef vector<pair<lli, lli> > vplli;
typedef vector<lli> vlli;
typedef vector<vlli> vvlli;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;

#define PI 3.141592653589793
#define mod (lli)(1000*1000*1000+7)

template<typename T> T gcd(T a, T b) { if (a == 0) return b; return gcd(b % a, a); }
template<typename T> T pow(T a, T b, lli m) {T ans = 1; while (b > 0) { if (b % 2 == 1) ans = ((ans % m) * (a % m)) % m; b /= 2; a = ((a % m) * (a % m)) % m; } return ans % m; }
template<typename T> void tracev(vector<T> &a) { for(auto &i:a) { cout<<i<<' '; } cout<<'\n'; }
template<typename T> void tracevv(vector<T> &a) { for(auto &i:a) { tracev(i); } }
template<typename T> void tracevp(vector<T> &a) { for(auto &i:a) { trace2(i.ff, i.ss); } cout<<'\n'; }

unordered_map<int, char> ch;
int main(){
fio;
	for(int i = 0 ; i < 26 ; i ++){
		ch[i] = 'a'+i;
		ch[26+i] = 'A'+i;
	}
	for(int i = 0 ; i < 10 ; i++){
		ch[52+i] = '0'+i;
	}
	int t;
	cin>>t;
	while(t--){
		int r,c,k;
		cin>>r>>c>>k;
		vector<string> a(r);
		for(int i = 0 ; i < r ; i++){
			cin>>a[i];
		}
		lli rice = 0;
		for(int i = 0 ; i < r ; i++){
			for(int j = 0 ; j < c ; j++){
				if(a[i][j] == 'R'){
					rice++;
				}
			}
		}
		lli gv = rice/k;
		lli ex = rice%k;
		bool f = true;
		lli taken = 0;
		int nx = 0;
		for(int i = 0 ; i < r ; i++){
			if(f){
				for(int j = 0 ; j < c ; j++){
					char p = a[i][j];
					a[i][j] = ch[nx];
					if(p == 'R'){
						taken++;
						int tk = gv;
						if(ex > 0) tk++;
						if(taken == tk){
							if(nx < k) nx++;
							taken = 0;
							ex--;
						}
					}
				}
			}
			else{
				for(int j = c-1 ; j >= 0 ; j--){
					char p = a[i][j];
					a[i][j] = ch[nx];
					if(p == 'R'){
						taken++;
						int tk = gv;
						if(ex > 0) tk++;
						if(taken == tk){
							if(nx < k) nx++;
							taken = 0;
							ex--;
						}
					}
				}
			}
			f = !f;
		}
		for(auto &i:a){
			cout<<i<<'\n';
		}

	}

	return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <bitset>
#include <array>

using namespace std;

const int maxn=105;
const int xp[]={1, 0, -1, 0};
const int yp[]={0, 1, 0, -1};
const string red="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

int n, m, k, br, pos;
bitset < maxn > bio[maxn], l[maxn];
char sol[maxn][maxn];

void dfs(int x, int y, int br, int col, int smjer){
//	cout << x << " " << y << endl;
	bio[x][y]=1;
	sol[x][y]=red[col];
	if(l[x][y]){
		br--;
		if(!br){
			return;
		}
	}
	int xs, ys;
	if(smjer==-1){
		for(int i=0; i<4; i++){
			xs=x+xp[i];
			ys=y+yp[i];
			if(xs>-1 && ys>-1 && xs<n && ys<m && !bio[xs][ys]){
				dfs(xs, ys, br, col, i);
				return;
			}
		}
	}
	else{
		xs=x+xp[smjer];
		ys=y+yp[smjer];
		if(xs>-1 && ys>-1 && xs<n && ys<m && !bio[xs][ys]){
			dfs(xs, ys, br, col, smjer);
		}
		else{
			xs=x+xp[(smjer+1)%4];
			ys=y+yp[(smjer+1)%4];
			dfs(xs, ys, br, col, smjer+1);
		}
	}
}

void puz(){
	int xl=0, xd=n-1, yl=0, yd=m-1;
	int x=0, y=0;
	int kor=0;
	for(int i=0; i<n*m; i++){
//		cout << x << " " << y << '\n';
		if(!bio[x][y]){
//			cout << "usao" << '\n';
			dfs(x, y, br/k, pos, -1);
			br-=br/k;
			k--;
			if(!k){
				break;
			}
			pos++;
		}
		if(kor==0 && x==xd){
			kor=1;
			yl++;
		}
		else if(kor==1 && y==yd){
			kor=2;
			xd--;
		}
		else if(kor==2 && x==xl){
			kor=3;
			yd--;
		}
		else if(kor==3 && y==yl){
			kor=0;
			xl++;
		}
		x+=xp[kor];
		y+=yp[kor];
	}
}

void solve(){
	cin >> n >> m >> k;
	string s;
	for(int i=0; i<n; i++){
		cin >> s;
		for(int j=0; j<m; j++){
			if(s[j]=='R'){
				l[i][j]=1;
				br++;
			}
			else{
				l[i][j]=0;
			}
		}
	}
	puz();
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			if(!bio[i][j]){
				sol[i][j]=red[pos];
			}
		}
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			cout << sol[i][j];
		}
		cout << '\n';
	}
	for(int i=0; i<n; i++){
		bio[i].reset();
		l[i].reset();
	}
	pos=0;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	for(int i=0; i<t; i++){
		solve();
	}
	return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <bitset>
#include <array>

using namespace std;

const int maxn=105;
const int xp[]={1, 0, -1, 0};
const int yp[]={0, 1, 0, -1};
const string red="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

int n, m, k, br, pos;
bitset < maxn > bio[maxn], l[maxn];
char sol[maxn][maxn];

void dfs(int x, int y, int br, int col, int smjer){
//	cout << x << " " << y << endl;
	bio[x][y]=1;
	sol[x][y]=red[col];
	if(l[x][y]){
		br--;
		if(!br){
			return;
		}
	}
	int xs, ys;
	if(smjer==-1){
		for(int i=0; i<4; i++){
			xs=x+xp[i];
			ys=y+yp[i];
			if(xs>-1 && ys>-1 && xs<n && ys<m && !bio[xs][ys]){
				dfs(xs, ys, br, col, i);
				return;
			}
		}
	}
	else{
		xs=x+xp[smjer];
		ys=y+yp[smjer];
		if(xs>-1 && ys>-1 && xs<n && ys<m && !bio[xs][ys]){
			dfs(xs, ys, br, col, smjer);
		}
		else{
			xs=x+xp[(smjer+1)%4];
			ys=y+yp[(smjer+1)%4];
			dfs(xs, ys, br, col, (smjer+1)%4);
		}
	}
}

void puz(){
	int xl=0, xd=n-1, yl=0, yd=m-1;
	int x=0, y=0;
	int kor=0;
	for(int i=0; i<n*m; i++){
//		cout << x << " " << y << '\n';
		if(!bio[x][y]){
//			cout << "usao" << '\n';
			dfs(x, y, br/k, pos, -1);
			br-=br/k;
			k--;
			if(!k){
				break;
			}
			pos++;
		}
		if(kor==0 && x==xd){
			kor=1;
			yl++;
		}
		else if(kor==1 && y==yd){
			kor=2;
			xd--;
		}
		else if(kor==2 && x==xl){
			kor=3;
			yd--;
		}
		else if(kor==3 && y==yl){
			kor=0;
			xl++;
		}
		x+=xp[kor];
		y+=yp[kor];
	}
}

void solve(){
	cin >> n >> m >> k;
	string s;
	for(int i=0; i<n; i++){
		cin >> s;
		for(int j=0; j<m; j++){
			if(s[j]=='R'){
				l[i][j]=1;
				br++;
			}
			else{
				l[i][j]=0;
			}
		}
	}
	puz();
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			if(!bio[i][j]){
				sol[i][j]=red[pos];
			}
		}
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			cout << sol[i][j];
		}
		cout << '\n';
	}
	for(int i=0; i<n; i++){
		bio[i].reset();
		l[i].reset();
	}
	pos=0;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	for(int i=0; i<t; i++){
		solve();
	}
	return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <bitset>
#include <array>

using namespace std;

const int maxn=105;
const int xp[]={0, -1, 0, 1};
const int yp[]={-1, 0, 1, 0};
const string red="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

int n, m, k;
bitset < maxn > bio[maxn], l[maxn];
char sol[maxn][maxn];

void bfs(int x, int y, int br, int col){
	queue < pair < int, int > > q;
	q.push(make_pair(x, y));
	bio[x][y]=1;
	sol[x][y]=red[col];
	if(l[x][y]){
		br--;
		if(!br){
			return;
		}
	}
	pair < int, int > p;
	int xs, ys;
	while(!q.empty()){
		p=q.front();
		q.pop();
		for(int i=0; i<4; i++){
			xs=p.first+xp[i];
			ys=p.second+yp[i];
			if(xs>-1 && ys>-1 && xs<n && ys<m && !bio[xs][ys]){
				bio[xs][ys]=1;
				sol[xs][ys]=red[col];
				q.push(make_pair(xs, ys));
				if(l[xs][ys]){
					br--;
					if(!br){
						return;
					}
				}
			}
		}
	}
}

void solve(){
	cin >> n >> m >> k;
	string s;
	int br=0;
	for(int i=0; i<n; i++){
		cin >> s;
		for(int j=0; j<m; j++){
			if(s[j]=='R'){
				l[i][j]=1;
				br++;
			}
			else{
				l[i][j]=0;
			}
		}
	}
	int pos=0;
	int y;
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			if(!bio[i][j]){
				bfs(i, j, br/k, pos);
				br-=br/k;
				k--;
				if(!k){
					break;
				}
				pos++;
			}
		}
		if(!k){
			break;
		}
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			if(!bio[i][j]){
				if(i){
					for(int o=0; o<62; o++){
						if(sol[i-1][j]==red[o]){
							y=o;
							break;
						}
					}
				}
				else{
					for(int o=0; o<62; o++){
						if(sol[i][j-1]==red[o]){
							y=o;
							break;
						}
					}
				}
				bfs(i, j, 1, y);
			}
		}
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			cout << sol[i][j];
		}
		cout << '\n';
	}
	for(int i=0; i<n; i++){
		bio[i].reset();
		l[i].reset();
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	for(int i=0; i<t; i++){
		solve();
	}
	return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <bitset>
#include <array>

using namespace std;

const int maxn=105;
const int xp[]={-1, 0, 1, 0};
const int yp[]={0, -1, 0, 1};
const string red="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

int n, m, k;
bitset < maxn > bio[maxn], l[maxn];
char sol[maxn][maxn];

void bfs(int x, int y, int br, int col){
	queue < pair < int, int > > q;
	q.push(make_pair(x, y));
	bio[x][y]=1;
	sol[x][y]=red[col];
	if(l[x][y]){
		br--;
		if(!br){
			return;
		}
	}
	pair < int, int > p;
	int xs, ys;
	while(!q.empty()){
		p=q.front();
		q.pop();
		for(int i=0; i<4; i++){
			xs=p.first+xp[i];
			ys=p.second+yp[i];
			if(xs>-1 && ys>-1 && xs<n && ys<m && !bio[xs][ys]){
				bio[xs][ys]=1;
				sol[xs][ys]=red[col];
				q.push(make_pair(xs, ys));
				if(l[xs][ys]){
					br--;
					if(!br){
						return;
					}
				}
			}
		}
	}
}

void solve(){
	cin >> n >> m >> k;
	string s;
	int br=0;
	for(int i=0; i<n; i++){
		cin >> s;
		for(int j=0; j<m; j++){
			if(s[j]=='R'){
				l[i][j]=1;
				br++;
			}
			else{
				l[i][j]=0;
			}
		}
	}
	int pos=0;
	int y;
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			if(!bio[i][j]){
				bfs(i, j, br/k, pos);
				br-=br/k;
				k--;
				if(!k){
					break;
				}
				pos++;
			}
		}
		if(!k){
			break;
		}
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			if(!bio[i][j]){
				if(i){
					for(int o=0; o<62; o++){
						if(sol[i-1][j]==red[o]){
							y=o;
							break;
						}
					}
				}
				else{
					for(int o=0; o<62; o++){
						if(sol[i][j-1]==red[o]){
							y=o;
							break;
						}
					}
				}
				bfs(i, j, 1, y);
			}
		}
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			cout << sol[i][j];
		}
		cout << '\n';
	}
	for(int i=0; i<n; i++){
		bio[i].reset();
		l[i].reset();
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	for(int i=0; i<t; i++){
		solve();
	}
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <bitset>

using namespace std;

const int maxn=105;
const int xp[]={1, 0, -1, 0};
const int yp[]={0, 1, 0, -1};
const string red="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

int n, m, k, br, pos;
bitset < maxn > bio[maxn], l[maxn];
char sol[maxn][maxn];

void scan(int &a){
	a=0;
	char c=_getchar_nolock();
	while(c>='0' && c<='9'){
		a*=10;
		a+=c-'0';
		c=_getchar_nolock();
	}
}

void dfs(int x, int y, int br, int col, int smjer){
	bio[x][y]=1;
	sol[x][y]=red[col];
	if(l[x][y]){
		br--;
		if(!br){
			return;
		}
	}
	int xs, ys;
	if(smjer==-1){
		for(int i=0; i<4; i++){
			xs=x+xp[i];
			ys=y+yp[i];
			if(xs>-1 && ys>-1 && xs<n && ys<m && !bio[xs][ys]){
				dfs(xs, ys, br, col, i);
				return;
			}
		}
	}
	else{
		xs=x+xp[smjer];
		ys=y+yp[smjer];
		if(xs>-1 && ys>-1 && xs<n && ys<m && !bio[xs][ys]){
			dfs(xs, ys, br, col, smjer);
		}
		else{
			xs=x+xp[(smjer+1)%4];
			ys=y+yp[(smjer+1)%4];
			dfs(xs, ys, br, col, (smjer+1)%4);
		}
	}
}

void puz(){
	int xl=0, xd=n-1, yl=0, yd=m-1;
	int x=0, y=0;
	int kor=0;
	for(int i=0; i<n*m; i++){
		if(!bio[x][y]){
			dfs(x, y, br/k, pos, -1);
			br-=br/k;
			k--;
			if(!k){
				break;
			}
			pos++;
		}
		if(kor==0 && x==xd){
			kor=1;
			yl++;
		}
		else if(kor==1 && y==yd){
			kor=2;
			xd--;
		}
		else if(kor==2 && x==xl){
			kor=3;
			yd--;
		}
		else if(kor==3 && y==yl){
			kor=0;
			xl++;
		}
		x+=xp[kor];
		y+=yp[kor];
	}
}

void solve(){
	scan(n);
	scan(m);
	scan(k);
	char c;
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			c=_getchar_nolock();
			if(c=='R'){
				l[i][j]=1;
				br++;
			}
			else{
				l[i][j]=0;
			}
		}
		_getchar_nolock();
	}
	puz();
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			if(!bio[i][j]){
				sol[i][j]=red[pos];
			}
		}
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			printf("%c", sol[i][j]);
		}
		printf("\n");
	}
	for(int i=0; i<n; i++){
		bio[i].reset();
		l[i].reset();
	}
	pos=0;
}

int main(){
	int t;
	scan(t);
	for(int i=0; i<t; i++){
		solve();
	}
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <bitset>

using namespace std;

const int maxn=105;
const int xp[]={1, 0, -1, 0};
const int yp[]={0, 1, 0, -1};
const string red="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

int n, m, k, br, pos;
bitset < maxn > bio[maxn], l[maxn];
char sol[maxn][maxn];

void scan(int &a){
	a=0;
	char c=_getchar_nolock();
	while(c>='0' && c<='9'){
		a*=10;
		a+=c-'0';
		c=_getchar_nolock();
	}
}

void dfs(int x, int y, int br, int col, int smjer){
	bio[x][y]=1;
	sol[x][y]=red[col];
	if(l[x][y]){
		br--;
		if(!br){
			return;
		}
	}
	int xs, ys;
	if(smjer==-1){
		for(int i=0; i<4; i++){
			xs=x+xp[i];
			ys=y+yp[i];
			if(xs>-1 && ys>-1 && xs<n && ys<m && !bio[xs][ys]){
				dfs(xs, ys, br, col, i);
				return;
			}
		}
	}
	else{
		xs=x+xp[smjer];
		ys=y+yp[smjer];
		if(xs>-1 && ys>-1 && xs<n && ys<m && !bio[xs][ys]){
			dfs(xs, ys, br, col, smjer);
		}
		else{
			xs=x+xp[(smjer+1)%4];
			ys=y+yp[(smjer+1)%4];
			dfs(xs, ys, br, col, (smjer+1)%4);
		}
	}
}

void puz(){
	int xl=0, xd=n-1, yl=0, yd=m-1;
	int x=0, y=0;
	int kor=0;
	for(int i=0; i<n*m; i++){
		if(!bio[x][y]){
			dfs(x, y, br/k, pos, -1);
			br-=br/k;
			k--;
			if(!k){
				break;
			}
			pos++;
		}
		if(kor==0 && x==xd){
			kor=1;
			yl++;
		}
		else if(kor==1 && y==yd){
			kor=2;
			xd--;
		}
		else if(kor==2 && x==xl){
			kor=3;
			yd--;
		}
		else if(kor==3 && y==yl){
			kor=0;
			xl++;
		}
		x+=xp[kor];
		y+=yp[kor];
	}
}

void solve(){
	scan(n);
	scan(m);
	scan(k);
	char c;
	br=0;
	pos=0;
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			c=_getchar_nolock();
			if(c=='R'){
				l[i][j]=1;
				br++;
			}
			else{
				l[i][j]=0;
			}
		}
		_getchar_nolock();
	}
	puz();
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			if(!bio[i][j]){
				sol[i][j]=red[pos];
			}
		}
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			printf("%c", sol[i][j]);
			bio[i][j]=0;
		}
		printf("\n");
	}
}

int main(){
	int t;
	scan(t);
	for(int i=0; i<t; i++){
		solve();
	}
	return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <bitset>
#include <array>

using namespace std;

const int maxn=105;
const int xp[]={1, 0, -1, 0};
const int yp[]={0, 1, 0, -1};
const string red="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

int n, m, k;
bitset < maxn > bio[maxn], l[maxn];
char sol[maxn][maxn];

void bfs(int x, int y, int br, int col){
	queue < pair < int, int > > q;
	q.push(make_pair(x, y));
	bio[x][y]=1;
	sol[x][y]=red[col];
	if(l[x][y]){
		br--;
		if(!br){
			return;
		}
	}
	pair < int, int > p;
	int xs, ys;
	while(!q.empty()){
		p=q.front();
		q.pop();
		for(int i=0; i<4; i++){
			xs=p.first+xp[i];
			ys=p.second+yp[i];
			if(xs>-1 && ys>-1 && xs<n && ys<m && !bio[xs][ys]){
				bio[xs][ys]=1;
				sol[xs][ys]=red[col];
				q.push(make_pair(xs, ys));
				if(l[xs][ys]){
					br--;
					if(!br){
						return;
					}
				}
			}
		}
	}
}

void solve(){
	cin >> n >> m >> k;
	string s;
	int br=0;
	for(int i=0; i<n; i++){
		cin >> s;
		for(int j=0; j<m; j++){
			if(s[j]=='R'){
				l[i][j]=1;
				br++;
			}
			else{
				l[i][j]=0;
			}
		}
	}
	int pos=0;
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			if(!bio[i][j]){
				bfs(i, j, br/k, pos);
				br-=br/k;
				k--;
				if(!k){
					break;
				}
				pos++;
			}
		}
		if(!k){
			break;
		}
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			if(!bio[i][j]){
				bfs(i, j, 1, pos);
			}
		}
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			cout << sol[i][j];
		}
		cout << '\n';
	}
	for(int i=0; i<n; i++){
		bio[i].reset();
		l[i].reset();
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	for(int i=0; i<t; i++){
		solve();
	}
	return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <bitset>
#include <array>

using namespace std;

const int maxn=105;
const int xp[]={-1, 0, 0, 1};
const int yp[]={0, -1, 1, 0};
const string red="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

int n, m, k;
bitset < maxn > bio[maxn], l[maxn];
char sol[maxn][maxn];

void bfs(int x, int y, int br, int col){
	queue < pair < int, int > > q;
	q.push(make_pair(x, y));
	bio[x][y]=1;
	sol[x][y]=red[col];
	if(l[x][y]){
		br--;
		if(!br){
			return;
		}
	}
	pair < int, int > p;
	int xs, ys;
	while(!q.empty()){
		p=q.front();
		q.pop();
		for(int i=0; i<4; i++){
			xs=p.first+xp[i];
			ys=p.second+yp[i];
			if(xs>-1 && ys>-1 && xs<n && ys<m && !bio[xs][ys]){
				bio[xs][ys]=1;
				sol[xs][ys]=red[col];
				q.push(make_pair(xs, ys));
				if(l[xs][ys]){
					br--;
					if(!br){
						return;
					}
				}
			}
		}
	}
}

void solve(){
	cin >> n >> m >> k;
	string s;
	int br=0;
	for(int i=0; i<n; i++){
		cin >> s;
		for(int j=0; j<m; j++){
			if(s[j]=='R'){
				l[i][j]=1;
				br++;
			}
			else{
				l[i][j]=0;
			}
		}
	}
	int pos=0;
	int y;
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			if(!bio[i][j]){
				bfs(i, j, br/k, pos);
				br-=br/k;
				k--;
				if(!k){
					break;
				}
				pos++;
			}
		}
		if(!k){
			break;
		}
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			if(!bio[i][j]){
				if(i){
					for(int o=0; o<62; o++){
						if(sol[i-1][j]==red[o]){
							y=o;
							break;
						}
					}
				}
				else{
					for(int o=0; o<62; o++){
						if(sol[i][j-1]==red[o]){
							y=o;
							break;
						}
					}
				}
				bfs(i, j, 1, y);
			}
		}
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			cout << sol[i][j];
		}
		cout << '\n';
	}
	for(int i=0; i<n; i++){
		bio[i].reset();
		l[i].reset();
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	for(int i=0; i<t; i++){
		solve();
	}
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <bitset>
#include <array>

using namespace std;

const int maxn=105;
const int xp[]={1, 0, -1, 0};
const int yp[]={0, 1, 0, -1};
const string red="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

int n, m, k, br, pos;
bitset < maxn > bio[maxn], l[maxn];
char sol[maxn][maxn];

void scan(int &a){
	a=0;
	char c=getchar();
	while(c>='0' && c<='9'){
		a*=10;
		a+=c-'0';
		c=getchar();
	}
}

void dfs(int x, int y, int br, int col, int smjer){
//	cout << x << " " << y << endl;
	bio[x][y]=1;
	sol[x][y]=red[col];
	if(l[x][y]){
		br--;
		if(!br){
			return;
		}
	}
	int xs, ys;
	if(smjer==-1){
		for(int i=0; i<4; i++){
			xs=x+xp[i];
			ys=y+yp[i];
			if(xs>-1 && ys>-1 && xs<n && ys<m && !bio[xs][ys]){
				dfs(xs, ys, br, col, i);
				return;
			}
		}
	}
	else{
		xs=x+xp[smjer];
		ys=y+yp[smjer];
		if(xs>-1 && ys>-1 && xs<n && ys<m && !bio[xs][ys]){
			dfs(xs, ys, br, col, smjer);
		}
		else{
			xs=x+xp[(smjer+1)%4];
			ys=y+yp[(smjer+1)%4];
			dfs(xs, ys, br, col, (smjer+1)%4);
		}
	}
}

void puz(){
	int xl=0, xd=n-1, yl=0, yd=m-1;
	int x=0, y=0;
	int kor=0;
	for(int i=0; i<n*m; i++){
//		cout << x << " " << y << '\n';
		if(!bio[x][y]){
//			cout << "usao" << '\n';
			dfs(x, y, br/k, pos, -1);
			br-=br/k;
			k--;
			if(!k){
				break;
			}
			pos++;
		}
		if(kor==0 && x==xd){
			kor=1;
			yl++;
		}
		else if(kor==1 && y==yd){
			kor=2;
			xd--;
		}
		else if(kor==2 && x==xl){
			kor=3;
			yd--;
		}
		else if(kor==3 && y==yl){
			kor=0;
			xl++;
		}
		x+=xp[kor];
		y+=yp[kor];
	}
}

void solve(){
	scan(n);
	scan(m);
	scan(k);
	char c;
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			c=getchar();
			if(c=='R'){
				l[i][j]=1;
				br++;
			}
			else{
				l[i][j]=0;
			}
		}
		getchar();
	}
	puz();
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			if(!bio[i][j]){
				sol[i][j]=red[pos];
			}
		}
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			printf("%c", sol[i][j]);
		}
		printf("\n");
	}
	for(int i=0; i<n; i++){
		bio[i].reset();
		l[i].reset();
	}
	pos=0;
}

int main(){
	int t;
	scan(t);
	for(int i=0; i<t; i++){
		solve();
	}
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <bitset>

using namespace std;

const int maxn=105;
const int xp[]={1, 0, -1, 0};
const int yp[]={0, 1, 0, -1};
const string red="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

int n, m, k, br, pos;
bitset < maxn > bio[maxn], l[maxn];
char sol[maxn][maxn];

void scan(int &a){
	a=0;
	char c=_getchar_nolock();
	while(c>='0' && c<='9'){
		a*=10;
		a+=c-'0';
		c=_getchar_nolock();
	}
}

void dfs(int x, int y, int br, int col, int smjer){
	bio[x][y]=1;
	sol[x][y]=red[col];
	if(l[x][y]){
		br--;
		if(!br){
			return;
		}
	}
	int xs, ys;
	xs=x+xp[smjer];
	ys=y+yp[smjer];
	if(xs>-1 && ys>-1 && xs<n && ys<m && !bio[xs][ys]){
		dfs(xs, ys, br, col, smjer);
	}
	else{
		xs=x+xp[(smjer+1)%4];
		ys=y+yp[(smjer+1)%4];
		dfs(xs, ys, br, col, (smjer+1)%4);
	}
}

void puz(){
	int xl=0, xd=n-1, yl=0, yd=m-1;
	int x=0, y=0;
	int kor=0;
	for(int i=0; i<n*m; i++){
		if(kor==0 && x==xd){
			kor=1;
			yl++;
		}
		else if(kor==1 && y==yd){
			kor=2;
			xd--;
		}
		else if(kor==2 && x==xl){
			kor=3;
			yd--;
		}
		else if(kor==3 && y==yl){
			kor=0;
			xl++;
		}
		if(!bio[x][y]){
			dfs(x, y, br/k, pos, kor);
			br-=br/k;
			k--;
			if(!k){
				break;
			}
			pos++;
		}
		x+=xp[kor];
		y+=yp[kor];
	}
}

void solve(){
	scan(n);
	scan(m);
	scan(k);
	char c;
	br=0;
	pos=0;
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			c=_getchar_nolock();
			if(c=='R'){
				l[i][j]=1;
				br++;
			}
			else{
				l[i][j]=0;
			}
		}
		_getchar_nolock();
	}
	puz();
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			if(!bio[i][j]){
				sol[i][j]=red[pos];
			}
		}
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			printf("%c", sol[i][j]);
			bio[i][j]=0;
		}
		printf("\n");
	}
}

int main(){
	int t;
	scan(t);
	for(int i=0; i<t; i++){
		solve();
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <set>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
int n, m, k, key;
char ini[105][105];
char ans[105][105];
char out[105];
int outcnt;
int now, tempcnt;
void build()
{
    for (int i = 0; i < 10; i++)
        out[outcnt++] = i + '0';
    for (int i = 0; i < 26; i++)
        out[outcnt++] = i + 'a';
    for (int i = 0; i < 26; i++)
        out[outcnt++] = i + 'A';
}
void dfs(int x, int y, int cnt, int dir)
{
    if (cnt > key)
        return;
    if (cnt >= key)
    {
        if (!tempcnt)
            return;
        tempcnt--;
    }
    ans[x][y] = out[now];
    if (ini[x][y] == 'R')
        cnt++;
    if (dir == 0)
    {
        if (y + 1 >= m)
            dfs(x + 1, y, cnt, !dir);
        else
            dfs(x, y + 1, cnt, dir);
    }
    else
    {
        if (y - 1 < 0)
            dfs(x + 1, y, cnt, !dir);
        else
            dfs(x, y - 1, cnt, dir);
    }
}
int dir[4][2] = {1, 0, 0, 1, -1, 0, 0, -1};
void solve()
{
    for (int i = 0; i < n; i++)
    {
        if (i % 2 == 0)
        {
            for (int j = 0; j < m; j++)
            {
                if (!ans[i][j])
                    dfs(i, j, 0, 0), now++;
            }
        }
        else
        {
            for (int j = m - 1; j >= 0; j--)
            {
                if (!ans[i][j])
                    dfs(i, j, 0, 1), now++;
            }
        }
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    build();
    int T;
    cin >> T;
    while (T--)
    {
        memset(ans, 0, sizeof ans);
        now = 0;
        int cnt = 0;
        cin >> n >> m >> k;
        for (int i = 0; i < n; i++)
        {
            cin >> ini[i];
            for (int j = 0; j < m; j++)
            {
                if (ini[i][j] == 'R')
                    cnt++;
            }
        }
        key = cnt / k;
        tempcnt = cnt - key * k;
        printf("tempcnt==%d\n", tempcnt);
        solve();
        for (int i = 0; i < n; i++)
            printf("%s\n", ans[i]);
    }
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <set>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
int n, m, k, key;
char ini[105][105];
char ans[105][105];
char out[105];
int outcnt;
int now, tempcnt;
void build()
{
    for (int i = 0; i < 10; i++)
        out[outcnt++] = i + '0';
    for (int i = 0; i < 26; i++)
        out[outcnt++] = i + 'a';
    for (int i = 0; i < 26; i++)
        out[outcnt++] = i + 'A';
}
void dfs(int x, int y, int cnt, int dir)
{
    if (cnt > key)
        return;
    if (cnt >= key)
    {
        if (!tempcnt)
            return;
        tempcnt--;
    }
    ans[x][y] = out[now];
    if (ini[x][y] == 'R')
        cnt++;
    if (dir == 0)
    {
        if (y + 1 >= m)
            dfs(x + 1, y, cnt, !dir);
        else
            dfs(x, y + 1, cnt, dir);
    }
    else
    {
        if (y - 1 < 0)
            dfs(x + 1, y, cnt, !dir);
        else
            dfs(x, y - 1, cnt, dir);
    }
}
int dir[4][2] = {1, 0, 0, 1, -1, 0, 0, -1};
void solve()
{
    for (int i = 0; i < n; i++)
    {
        if (i % 2 == 0)
        {
            for (int j = 0; j < m; j++)
            {
                if (!ans[i][j])
                    dfs(i, j, 0, 0), now++;
            }
        }
        else
        {
            for (int j = m - 1; j >= 0; j--)
            {
                if (!ans[i][j])
                    dfs(i, j, 0, 1), now++;
            }
        }
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    build();
    int T;
    cin >> T;
    while (T--)
    {
        memset(ans, 0, sizeof ans);
        now = 0;
        int cnt = 0;
        cin >> n >> m >> k;
        for (int i = 0; i < n; i++)
        {
            cin >> ini[i];
            for (int j = 0; j < m; j++)
            {
                if (ini[i][j] == 'R')
                    cnt++;
            }
        }
        key = cnt / k;
        tempcnt = cnt - key * k;
        solve();
        for (int i = 0; i < n; i++)
            printf("%s\n", ans[i]);
    }
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <set>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
int n, m, k, key;
char ini[105][105];
char ans[105][105];
char out[105];
int outcnt;
int now, tempcnt;
void build()
{
    for (int i = 0; i < 10; i++)
        out[outcnt++] = i + '0';
    for (int i = 0; i < 26; i++)
        out[outcnt++] = i + 'a';
    for (int i = 0; i < 26; i++)
        out[outcnt++] = i + 'A';
}
void dfs(int x, int y, int cnt, int dir)
{
    if (x > n)
        return;
    if (cnt > key)
        return;
    if (cnt >= key)
    {
        if (!tempcnt)
            return;
        tempcnt--;
    }
    ans[x][y] = out[now];
    if (ini[x][y] == 'R')
        cnt++;
    if (dir == 0)
    {
        if (y + 1 >= m)
            dfs(x + 1, y, cnt, !dir);
        else
            dfs(x, y + 1, cnt, dir);
    }
    else
    {
        if (y - 1 < 0)
            dfs(x + 1, y, cnt, !dir);
        else
            dfs(x, y - 1, cnt, dir);
    }
}
int dir[4][2] = {1, 0, 0, 1, -1, 0, 0, -1};
void solve()
{
    for (int i = 0; i < n; i++)
    {
        if (i % 2 == 0)
        {
            for (int j = 0; j < m; j++)
            {
                if (!ans[i][j])
                    dfs(i, j, 0, 0), now++;
            }
        }
        else
        {
            for (int j = m - 1; j >= 0; j--)
            {
                if (!ans[i][j])
                    dfs(i, j, 0, 1), now++;
            }
        }
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    build();
    int T;
    cin >> T;
    while (T--)
    {
        memset(ans, 0, sizeof ans);
        now = 0;
        int cnt = 0;
        cin >> n >> m >> k;
        for (int i = 0; i < n; i++)
        {
            cin >> ini[i];
            for (int j = 0; j < m; j++)
            {
                if (ini[i][j] == 'R')
                    cnt++;
            }
        }
        key = cnt / k;
        tempcnt = cnt - key * k;
        solve();
        for (int i = 0; i < n; i++)
            printf("%s\n", ans[i]);
    }
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <set>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
int n, m, k, key;
char ini[105][105];
char ans[105][105];
char out[105];
int outcnt;
int now, tempcnt;
void build()
{
    for (int i = 0; i < 10; i++)
        out[outcnt++] = i + '0';
    for (int i = 0; i < 26; i++)
        out[outcnt++] = i + 'a';
    for (int i = 0; i < 26; i++)
        out[outcnt++] = i + 'A';
}
void dfs(int x, int y, int cnt, int dir)
{
    if (x > n)
        return;
    if (ini[x][y] == 'R')
    {
        if (cnt > key)
            return;
        if (cnt >= key)
        {
            if (!tempcnt)
                return;
            tempcnt--;
        }
        cnt++;
    }
    ans[x][y] = out[now];

    if (dir == 0)
    {
        if (y + 1 >= m)
            dfs(x + 1, y, cnt, !dir);
        else
            dfs(x, y + 1, cnt, dir);
    }
    else
    {
        if (y - 1 < 0)
            dfs(x + 1, y, cnt, !dir);
        else
            dfs(x, y - 1, cnt, dir);
    }
}
int dir[4][2] = {1, 0, 0, 1, -1, 0, 0, -1};
void solve()
{
    for (int i = 0; i < n; i++)
    {
        if (i % 2 == 0)
        {
            for (int j = 0; j < m; j++)
            {
                if (!ans[i][j])
                    dfs(i, j, 0, 0), now++;
            }
        }
        else
        {
            for (int j = m - 1; j >= 0; j--)
            {
                if (!ans[i][j])
                    dfs(i, j, 0, 1), now++;
            }
        }
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    build();
    int T;
    cin >> T;
    while (T--)
    {
        memset(ans, 0, sizeof ans);
        now = 0;
        int cnt = 0;
        cin >> n >> m >> k;
        for (int i = 0; i < n; i++)
        {
            cin >> ini[i];
            for (int j = 0; j < m; j++)
            {
                if (ini[i][j] == 'R')
                    cnt++;
            }
        }
        key = cnt / k;
        tempcnt = cnt - key * k;
        solve();
        for (int i = 0; i < n; i++)
            printf("%s\n", ans[i]);
    }
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <set>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
int n, m, k, key;
char ini[105][105];
char ans[105][105];
char out[105];
int outcnt;
int now, tempcnt;
void build()
{
    for (int i = 0; i < 10; i++)
        out[outcnt++] = i + '0';
    for (int i = 0; i < 26; i++)
        out[outcnt++] = i + 'a';
    for (int i = 0; i < 26; i++)
        out[outcnt++] = i + 'A';
}
void dfs(int x, int y, int cnt, int dir)
{
    if (cnt >= key)
    {
        if (!tempcnt)
            return;
        tempcnt--;
    }
    if (cnt > key)
        return;
    ans[x][y] = out[now];
    if (ini[x][y] == 'R')
        cnt++;
    if (dir == 0)
    {
        if (y + 1 >= m)
            dfs(x + 1, y, cnt, !dir);
        else
            dfs(x, y + 1, cnt, dir);
    }
    else
    {
        if (y - 1 < 0)
            dfs(x + 1, y, cnt, !dir);
        else
            dfs(x, y - 1, cnt, dir);
    }
}
int dir[4][2] = {1, 0, 0, 1, -1, 0, 0, -1};
void solve()
{
    for (int i = 0; i < n; i++)
    {
        if (i % 2 == 0)
        {
            for (int j = 0; j < m; j++)
            {
                if (!ans[i][j])
                    dfs(i, j, 0, 0), now++;
            }
        }
        else
        {
            for (int j = m - 1; j >= 0; j--)
            {
                if (!ans[i][j])
                    dfs(i, j, 0, 1), now++;
            }
        }
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    build();
    int T;
    cin >> T;
    while (T--)
    {
        memset(ans, 0, sizeof ans);
        now = 0;
        int cnt = 0;
        cin >> n >> m >> k;
        for (int i = 0; i < n; i++)
        {
            cin >> ini[i];
            for (int j = 0; j < m; j++)
            {
                if (ini[i][j] == 'R')
                    cnt++;
            }
        }
        key = cnt / k;
        tempcnt = cnt - key * k;
        solve();
        for (int i = 0; i < n; i++)
            printf("%s\n", ans[i]);
    }
}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mod 1000000007
#define endl "\n"
#define inarr(arr,n); for(int i=0;i<n;i++) cin >> arr[i];
#define outarr(arr,n); for(int i=0;i<n;i++) cout<<arr[i]<<' ';
#define ve vector
#define fi first
#define se second
#define pa pair
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ld long double
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define all(c) c.begin(),c.end()
#define pii pair<int, int>
#define pll pair<ll,ll>
#define fr(i, a, b); for (int i = a; i < b; i++)
#define frn(i, a, b); for (int i = a; i > b; i--)
#define mk make_pair
#define setvector(vname,value,size); for(int i=0;i<size;i++)vname[i]=value;
#define sz(a) (int)((a).size())
#define deci fixed<<setprecision(9)
const ll inf = 9e18;
const ld pi = 2*acos(0.0);
ll t,n,r,c,k,a,b,cnt,curr,temp;
ve<string> arr;
ve<ve<bool>> rec;
ve<ve<ll>> brr;
ll power(ll x,ll y)
{
   ll res=1ll;
   while(y>0)
   {
       if(y&1) res=res*x;
       y>>=1;
       x=x*x;
   }
   return res;
}
void dfs(ll x,ll y,ll tar,ll ind)
{
    if(temp==tar)return;
    if(rec[x][y])return;
    rec[x][y]=true;
    brr[x][y]=ind;
    if(arr[x][y]=='R')temp++;
    if(x-1>=0)dfs(x-1,y,tar,ind);
    if(y-1>=0)dfs(x,y-1,tar,ind);
    if(x+1<r)dfs(x+1,y,tar,ind);
    if(y+1<c)dfs(x,y+1,tar,ind);
}
void solve()
{
    arr.clear(),cnt=a=b=curr=0,rec.clear(),brr.clear();
    cin>>r>>c>>k;
    rec.resize(r),brr.resize(r),arr.resize(r);
    fr(i,0,r)rec[i].resize(c,false),brr[i].resize(c,0);
    fr(i,0,r)cin>>arr[i];
    fr(i,0,r)
    {
        fr(j,0,c)
        {
            if(arr[i][j]=='R')cnt++;
        }
    }
    a=k-(cnt%k),b=cnt%k;
    cnt/=k;
    fr(i,0,r)
    {
        fr(j,0,c)
        {
            if(!rec[i][j])
            {
                temp=0;
                if(a>0)
                {
                    a--;
                    dfs(i,j,cnt,curr);
                }
                else
                {
                    dfs(i,j,cnt+1,curr);
                }
                curr++;
                if(curr>k-1)curr=k-1;
            }
        }
    }
    fr(i,0,r)
    {
        fr(j,0,c)
        {
            if(brr[i][j]<10)
            {
                cout<<brr[i][j];
            }
            else if(brr[i][j]<36)
            {
                char x=brr[i][j]-10+'a';
                cout<<x;
            }
            else
            {
                char x=brr[i][j]-36+'A';
                cout<<x;
            }
        }
        cout<<endl;
    }
}
int32_t main(void)
{
    fastio;
    cin>>t;
    while(t--)
    {
        solve();
    }
}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mod 1000000007
#define endl "\n"
#define inarr(arr,n); for(int i=0;i<n;i++) cin >> arr[i];
#define outarr(arr,n); for(int i=0;i<n;i++) cout<<arr[i]<<' ';
#define ve vector
#define fi first
#define se second
#define pa pair
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ld long double
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define all(c) c.begin(),c.end()
#define pii pair<int, int>
#define pll pair<ll,ll>
#define fr(i, a, b); for (int i = a; i < b; i++)
#define frn(i, a, b); for (int i = a; i > b; i--)
#define mk make_pair
#define setvector(vname,value,size); for(int i=0;i<size;i++)vname[i]=value;
#define sz(a) (int)((a).size())
#define deci fixed<<setprecision(9)
const ll inf = 9e18;
const ld pi = 2*acos(0.0);
ll t,n,r,c,k,a,b,cnt,curr,temp;
ve<string> arr;
ve<ve<bool>> rec;
ve<ve<ll>> brr;
ll power(ll x,ll y)
{
   ll res=1ll;
   while(y>0)
   {
       if(y&1) res=res*x;
       y>>=1;
       x=x*x;
   }
   return res;
}
void dfs(ll x,ll y,ll tar,ll ind)
{
    if(temp==tar && arr[x][y]=='R')return;
    if(rec[x][y])return;
    rec[x][y]=true;
    brr[x][y]=ind;
    if(arr[x][y]=='R')temp++;
    if(x-1>=0)dfs(x-1,y,tar,ind);
    if(y-1>=0)dfs(x,y-1,tar,ind);
    if(x+1<r)dfs(x+1,y,tar,ind);
    if(y+1<c)dfs(x,y+1,tar,ind);
}
void solve()
{
    arr.clear(),cnt=a=b=curr=0,rec.clear(),brr.clear();
    cin>>r>>c>>k;
    rec.resize(r),brr.resize(r),arr.resize(r);
    fr(i,0,r)rec[i].resize(c,false),brr[i].resize(c,0);
    fr(i,0,r)cin>>arr[i];
    fr(i,0,r)
    {
        fr(j,0,c)
        {
            if(arr[i][j]=='R')cnt++;
        }
    }
    a=k-(cnt%k),b=cnt%k;
    cnt/=k;
    fr(i,0,r)
    {
        fr(j,0,c)
        {
            if(!rec[i][j])
            {
                temp=0;
                if(a>0)
                {
                    a--;
                    dfs(i,j,cnt,curr);
                }
                else
                {
                    dfs(i,j,cnt+1,curr);
                }
                curr++;
                if(curr>k-1)curr=k-1;
            }
        }
    }
    fr(i,0,r)
    {
        fr(j,0,c)
        {
            if(brr[i][j]<10)
            {
                cout<<brr[i][j];
            }
            else if(brr[i][j]<36)
            {
                char x=brr[i][j]-10+'a';
                cout<<x;
            }
            else
            {
                char x=brr[i][j]-36+'A';
                cout<<x;
            }
        }
        cout<<endl;
    }
}
int32_t main(void)
{
    fastio;
    cin>>t;
    while(t--)
    {
        solve();
    }
}