#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#include <set>
#define ll long long
#define db double
using namespace std;
inline int read(){
    int SUM=0,ff=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
      if(ch=='-')
        ff=-1;
      ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
      SUM=(SUM<<3)+(SUM<<1)+(ch^48);
      ch=getchar();
    }
    return SUM*ff;
}
const int mod=998244353;
int k;
ll l,r;
int num[30],len;
ll pow10[30];
struct node{
    ll tot,sum;
    node(ll _tot=0,ll _sum=0){
	    tot=_tot;
	    sum=_sum;
	}
	inline void clear(){
	    tot=0;
	    sum=0;
	}
	inline bool check(){
	    return tot!=-1&&sum!=-1;
	}
}f[25][1<<10][2][2];
inline node add(node a1,node a2,int x,int w){
    node res;
    res.tot=(a1.tot+a2.tot)%mod;
    res.sum=(a1.sum+x*pow10[w]%mod*a2.tot%mod+a2.sum)%mod;
    return res;
}
inline node dfs(int pos,int s,bool zero,bool limit){
    if(!pos) return node(1,0);
    node& res=f[pos][s][zero][limit];
    if(res.check()) return res;
    res.clear();
    int maxx=limit?num[pos]:9;
    for(int i=0;i<=maxx;i++)
       if(__builtin_popcount(zero&&!i?0:s|(1<<i))<=k)
         res=add(res,dfs(pos-1,zero&&!i?0:s|(1<<i),zero&&!i,limit&&i==num[pos]),i,pos-1);
    return res;
}
inline ll solve(ll x){
    memset(f,-1,sizeof(f));
	len=0;
    while(x){
	  num[++len]=x%10;
	  x/=10;
	}
	return dfs(len,0,1,1).sum;
}
int main(){
    //freopen("CF1073E Segment Sum.in","r",stdin);
    //freopen("CF1073E Segment Sum.out","w",stdout);
    pow10[0]=1;
    for(int i=1;i<=20;i++)
       pow10[i]=pow10[i-1]*10%mod;
	scanf("%lld%lld",&l,&r);
    k=read();
    printf("%lld\n",(solve(r)%mod-solve(l-1)%mod+mod)%mod);
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

#define mod 998244353
#define LL long long

LL k, l, r, pw[25];
int tot, num[25];
struct node {
    LL cnt, sum;
}f[25][1 << 10];

node calc (int x, int lim, int S){
    if (! x)
        return (node){1, 0};
    if (! lim && f[x][S].cnt != -1)
        return f[x][S];
    node F = (node){0, 0};
    for (int i = lim ? num[x] : 9; i >= 0; i --){
        int nxt;
        if (! S && ! i)
            nxt = 0;
        else
            nxt = S | (1 << i);
        if (__builtin_popcount (nxt) > k)
            continue;
        node tmp = calc (x - 1, lim && i == num[x], nxt);
        F.cnt = (F.cnt + tmp.cnt) % mod;
        F.sum = ((tmp.sum + tmp.cnt * pw[x - 1] % mod * i % mod) % mod + F.sum) % mod;
    }
    if (! lim)
        f[x][S] = F;
    return F;
}
LL solve (LL x){
    tot = 0;
    while (x){
        num[++ tot] = x % 10;
        x /= 10;
    }
    return calc (tot, 1, 0).sum;
}
int main (){
    scanf ("%lld %lld %lld", &l, &r, &k);
    memset (f, -1, sizeof f);
    pw[0] = 1;
    for (int i = 1; i < 20; i ++)
        pw[i] = (pw[i - 1] * 10) % mod;
    printf ("%lld\n", (solve (r) - solve (l - 1) + mod) % mod);
    return 0;
}


#include<bits/stdc++.h>
#define int long long
#define pa pair<int,int>
using namespace std;
inline int read(){int x=0,f=1,ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}
inline void write(int x){if (x<0) putchar('-'),x=-x; if (x>=10) write(x/10); putchar(x%10+'0');}
inline void writeln(int x){write(x); puts("");}
const int mod=998244353;
int g[20][1<<10],l,r,k,len,num[20],f[20][1<<10],bin[20],sz[1<<10];
inline void init(){
	l=read(); r=read(); k=read();
}
pa dfs(int now,int st,bool limit){
	if (now==0) return pa(sz[st]<=k,0);
	if (!limit&&~f[now][st]) return pa(f[now][st],g[now][st]);
	int ans1=0,ans2=0,mx=9; bool sta=1;
	if (st==0) sta=0;
	if (limit) mx=num[now];
	for (int i=0;i<=mx;i++){
		pa tmp=dfs(now-1,(!sta&&i==0)?st:st|(1<<i),limit&(i==mx));
		(ans1+=tmp.first)%=mod; (ans2+=tmp.second+tmp.first*i*bin[now-1]%mod)%=mod;
	}
	if (!limit) f[now][st]=ans1,g[now][st]=ans2;
	return pa(ans1,ans2);
}
inline int sol(int x){
	len=0;
	for (;x;x/=10) num[++len]=x%10;
	return dfs(len,0,1).second;
}
inline void solve(){
	for (int i=1;i<(1<<10);i++){
		int cnt=0;
		for (int x=i;x;x-=x&(-x)) cnt++;
		sz[i]=cnt;
	}
	bin[0]=1;
	for (int i=1;i<=18;i++) bin[i]=bin[i-1]*10;
	memset(f,-1,sizeof f);
	writeln((sol(r)-sol(l-1)+mod)%mod);
}
signed main(){
	init(); solve();
	return 0;
}


#include <bits/stdc++.h>
#define forn(i,n) for(int i=1;i<=(n);i++)
#define MP make_pair
#define mod 998244353
using namespace std;
typedef long long ll;

ll l,r,k;
ll d[20],m,dp[20][2000],down[20][2000],dp1[20][2000];
ll qpow(ll a, ll b) {
	ll ans=1;
	while(b) {
		if(b&1) ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans;
}
ll DP1(ll i, ll j) {
	if(dp1[i][j]!= -1) return dp1[i][j];
	if(!i) return __builtin_popcount(j)<=k?dp1[i][j]=1:dp1[i][j]=0;
	ll ans=0;
	for(int dg=0;dg<=9;dg++) {
		ans=(ans+DP1(i-1,j|(1<<dg)))%mod;
	}
	return dp1[i][j]=ans;
}
pair <ll,ll> DP(ll i, ll j){
	if(dp[i][j]!=-1)return MP(dp[i][j],down[i][j]);
	if(!i) {
		if(__builtin_popcount(j) <= k) down[i][j]=1;
		else down[i][j]=-1;
		dp[i][j]=0;
		return MP(dp[i][j],down[i][j]);
	}
	ll ans=0,ok=0,pos=-1;
	for(int dg=0;dg<=9;dg++) {
		pair <ll,ll> dg1 = DP(i-1,j|(1<<dg));
		if(dg1.second==1) pos=1,ans=(ans+dg*qpow(10,i-1)%mod*DP1(i-1,j|(1<<dg))%mod+dg1.first)%mod;
	}
	dp[i][j]=ans;
	down[i][j]=pos;
	return MP(dp[i][j], down[i][j]);
}
ll calc(ll t){
	m=0;
	while(t){
		d[m++]=t%10;
		t/=10;
	}
	ll ans=0;
	for(int i=m-1;i>=1;i--)
		for(int j=1;j<=9;j++) {
			if(DP(i-1,(1<<j)).second)
				ans+=(j*qpow(10,i-1)%mod*DP1(i-1,(1<<j))%mod+DP(i-1,(1<<j)).first)%mod,ans%=mod;
		}
	int pre=0;
	ll previous = 0;
	for(int i=m-1;i>=0;i--) {
		for(int j=(i==m-1)?1:0;j<d[i];j++){
			if(DP(i,pre|(1<<j)).second)
				ans+=((previous * 10 + j)%mod *qpow(10,i)%mod*DP1(i,pre|(1<<j))%mod+DP(i,pre|(1<<j)).first)%mod,ans%=mod;
		}
		pre|=(1<<(d[i]));
		previous = previous * 10 + d[i];
		previous%=mod;
		if(__builtin_popcount(pre)>k) break;
	}
	return ans;
}
int main() {
  /////////////
	memset(down,-1,sizeof(down));
	memset(dp,-1,sizeof(dp));
	memset(dp1,-1,sizeof(dp1));
	cin>>l>>r>>k;
	cout<<(calc(r+1)-calc(l)+mod)%mod<<endl;
	return 0;
}


#include<bits/stdc++.h>
#define int long long
#define pa pair<int,int>
using namespace std;
inline int read(){int x=0,f=1,ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}
inline void write(int x){if (x<0) putchar('-'),x=-x; if (x>=10) write(x/10); putchar(x%10+'0');}
inline void writeln(int x){write(x); puts("");}
const int mod=998244353;
int g[20][1<<10],l,r,k,len,num[20],f[20][1<<10],bin[20],sz[1<<10];
inline void init(){
	l=read(); r=read(); k=read();
}
pa dfs(int now,int st,bool limit){
	if (now==0) return pa(sz[st]<=k,0);
	if (!limit&&~f[now][st]) return pa(f[now][st],g[now][st]);
	int ans1=0,ans2=0,mx=9; bool sta=1;
	if (st==0) sta=0;
	if (limit) mx=num[now];
	for (int i=0;i<=mx;i++){
		pa tmp=dfs(now-1,(!sta&&i==0)?st:st|(1<<i),limit&(i==mx));
		(ans1+=tmp.first)%=mod; (ans2+=tmp.second+tmp.first*i*bin[now-1]%mod)%=mod;
	}
	if (!limit) f[now][st]=ans1,g[now][st]=ans2;
	return pa(ans1,ans2);
}
inline int sol(int x){
	len=0;
	for (;x;x/=10) num[++len]=x%10;
	return dfs(len,0,1).second;
}
inline void solve(){
	for (int i=1;i<(1<<10);i++){
		int cnt=0;
		for (int x=i;x;x-=x&(-x)) cnt++;
		sz[i]=cnt;
	}
	bin[0]=1;
	for (int i=1;i<=18;i++) bin[i]=bin[i-1]*10;
	memset(f,-1,sizeof f);
	writeln(sol(r)-sol(l-1));
}
signed main(){
	init(); solve();
	return 0;
}


#include <bits/stdc++.h>

typedef long long LL;
using namespace std;
const LL Mod=998244353;

inline LL Add(LL a,LL b){
	LL ans=a+b;ans=(ans>=Mod?ans-Mod:ans);
	ans=(ans%Mod+Mod)%Mod;
	return ans;
}

inline LL Mis(LL a,LL b){
	LL ans=a-b;ans=(ans<0?ans+Mod:ans);
	ans=(ans%Mod+Mod)%Mod;
	return ans;
}

inline LL Mul(LL a,LL b){
	return (a%Mod*1ll*b%Mod)%Mod;
}

struct Node{
	LL sum,cnt;
	Node(){}
	Node(LL cnt,LL sum){
		this->cnt=cnt;
		this->sum=sum;
	}
};

Node dp[20][1025];
int bit[20];
LL Pow[25];
int cnt=0;
LL n,m;
int k;

inline int Count(int x){
	int ans=0;while(x)ans++,x-=(x&(-x));
	return ans;
}

inline Node Dfs(int pos,int sta,int lim,int lead){
	if(Count(sta)>k)return Node(0,0);
	if(!pos)return Node(1,0);
	if((!lim)&&(~dp[pos][sta].cnt))return dp[pos][sta];
	Node ans=Node(0,0),tmp;int Maxv=(lim?bit[pos]:9);
	for(int i=0;i<=Maxv;i++){
		if(lead){
			if(!i){
				tmp=Dfs(pos-1,sta,lim&&i==Maxv,lead);
				ans.sum=Add(ans.sum,tmp.sum);
				ans.cnt+=tmp.cnt;
			}
			else {
				tmp=Dfs(pos-1,sta|(1<<i),lim&&i==Maxv,0);
				ans.sum=Add(ans.sum,tmp.sum);
				ans.sum=Add(ans.sum,Mul(Mul(i,Pow[pos-1]),tmp.cnt%Mod));
				ans.cnt+=tmp.cnt;
			}
		}
		else {
			tmp=Dfs(pos-1,sta|(1<<i),lim&&i==Maxv,0);
			ans.sum=Add(ans.sum,tmp.sum);
			ans.sum=Add(ans.sum,Mul(Mul(i,Pow[pos-1]),tmp.cnt%Mod));
			ans.cnt+=tmp.cnt;
		}
	}
	return lim?ans:dp[pos][sta]=ans;
}

inline LL Calc(LL n){
	cnt=0;while(n)bit[++cnt]=n%10,n/=10;
	return Dfs(cnt,0,1,1).sum%Mod;
}

signed main(){
#ifdef Nzy
	freopen("stdin.in","r",stdin);
#endif
	memset(dp,-1,sizeof(dp));
	for(int i=(Pow[0]=1);i<=20;i++)Pow[i]=Pow[i-1]*10ll%Mod;
	cin>>n>>m>>k;
	cout<<Mis(Calc(m),Calc(n-1))<<endl;
	return 0;
}


#include <bits/stdc++.h>

typedef long long LL;
using namespace std;
const LL Mod=998244353;

inline LL Add(LL a,LL b){
	LL ans=a+b;ans=(ans>=Mod?ans-Mod:ans);
	return ans;
}

inline LL Mis(LL a,LL b){
	LL ans=a-b;ans=(ans<0?ans+Mod:ans);
	return ans;
}

inline LL Mul(LL a,LL b){
	return a*1ll*b%Mod;
}

struct Node{
	LL sum,cnt;
	Node(){}
	Node(LL cnt,LL sum){
		this->cnt=cnt;
		this->sum=sum;
	}
};

Node dp[20][1025];
int bit[20];
LL Pow[25];
int cnt=0;
LL n,m;
int k;

inline int Count(int x){
	int ans=0;while(x)ans++,x-=(x&(-x));
	return ans;
}

inline Node Dfs(int pos,int sta,int lim,int lead){
	if(Count(sta)>k)return Node(0,0);
	if(!pos)return Node(1,0);
	if((!lim)&&(~dp[pos][sta].cnt))return dp[pos][sta];
	Node ans=Node(0,0),tmp;int Maxv=(lim?bit[pos]:9);
	for(int i=0;i<=Maxv;i++){
		if(lead){
			if(!i){
				tmp=Dfs(pos-1,sta,lim&&i==Maxv,lead);
				ans.sum=Add(ans.sum,tmp.sum);
				ans.cnt+=tmp.cnt;
			}
			else {
				tmp=Dfs(pos-1,sta|(1<<i),lim&&i==Maxv,0);
				ans.sum=Add(ans.sum,tmp.sum);
				ans.sum=Add(ans.sum,Mul(Mul(i,Pow[pos]),tmp.cnt));
				ans.cnt+=tmp.cnt;
			}
		}
		else {
			tmp=Dfs(pos-1,sta|(1<<i),lim&&i==Maxv,0);
			ans.sum=Add(ans.sum,tmp.sum);
			ans.sum=Add(ans.sum,Mul(Mul(i,Pow[pos]),tmp.cnt));
			ans.cnt+=tmp.cnt;
		}
	}
	return lim?ans:dp[pos][sta]=ans;
}

inline LL Calc(LL n){
	cnt=0;while(n)bit[++cnt]=n%10,n/=10;
	return Dfs(cnt,0,1,1).sum%Mod;
}

signed main(){
#ifdef Nzy
	freopen("stdin.in","r",stdin);
#endif
	memset(dp,-1,sizeof(dp));
	for(int i=(Pow[0]=Pow[1]=1)+1;i<=20;i++)Pow[i]=Pow[i-1]*10%Mod;
	cin>>n>>m>>k;
	cout<<Mis(Calc(m),Calc(n-1))<<endl;
	return 0;
}


#include <bits/stdc++.h>

typedef long long LL;
using namespace std;
const int Mod=998244353;

inline int Add(int a,int b){
	int ans=a+b;ans=(ans>=Mod?ans-Mod:ans);
	return ans;
}

inline int Mis(int a,int b){
	int ans=a-b;ans=(ans<0?ans+Mod:ans);
	return ans;
}

inline int Mul(int a,LL b){
	return (a*(b%Mod))%Mod;
}

struct Node{
	LL cnt;
	int sum;
	Node(){}
	Node(LL cnt,int sum){
		this->cnt=cnt;
		this->sum=sum;
	}
};

Node dp[20][1025];
int bit[20];
LL Pow[25];
int cnt=0;
LL n,m;
int k;

inline int Count(int x){
	int ans=0;while(x)ans++,x-=(x&(-x));
	return ans;
}

inline Node Dfs(int pos,int sta,int lim,int lead){
	if(Count(sta)>k)return Node(0,0);
	if(!pos)return Node(1,0);
	if((!lim)&&(~dp[pos][sta].cnt))return dp[pos][sta];
	Node ans=Node(0,0),tmp;int Maxv=(lim?bit[pos]:9);
	for(int i=0;i<=Maxv;i++){
		if(lead){
			if(!i){
				tmp=Dfs(pos-1,sta,lim&&i==Maxv,lead);
				ans.sum=Add(ans.sum,tmp.sum);
				ans.cnt+=tmp.cnt;
			}
			else {
				tmp=Dfs(pos-1,sta|(1<<i),lim&&i==Maxv,0);
				ans.sum=Add(ans.sum,tmp.sum);
				ans.sum=Add(ans.sum,Mul(Mul(i,Pow[pos]),tmp.cnt));
				ans.cnt+=tmp.cnt;
			}
		}
		else {
			tmp=Dfs(pos-1,sta|(1<<i),lim&&i==Maxv,0);
			ans.sum=Add(ans.sum,tmp.sum);
			ans.sum=Add(ans.sum,Mul(Mul(i,Pow[pos]),tmp.cnt));
			ans.cnt+=tmp.cnt;
		}
	}
	return lim?ans:dp[pos][sta]=ans;
}

inline LL Calc(LL n){
	cnt=0;while(n)bit[++cnt]=n%10,n/=10;
	return Dfs(cnt,0,1,1).sum;
}

signed main(){
#ifdef Nzy
	freopen("stdin.in","r",stdin);
#endif
	memset(dp,-1,sizeof(dp));
	for(int i=(Pow[0]=Pow[1]=1)+1;i<=20;i++)Pow[i]=Pow[i-1]*10ll%Mod;
	cin>>n>>m>>k;
	cout<<Mis(Calc(m),Calc(n-1))<<endl;
	return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define all(a) a.begin(),a.end()
#define println printf("\n");
#define readln(x) getline(cin,x);
#define pb push_back
#define endl "\n"
#define INT_INF 0x3f3f3f3f
#define LL_INF 0x3f3f3f3f3f3f3f3f
#define MOD 998244353
#define MOD2 1494318097
#define SEED 131
#define mp make_pair
#define fastio cin.tie(0); cin.sync_with_stdio(0);

#define MAXD 20

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef unordered_map<int,int> umii;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef pair<int,pii> triple;
typedef int8_t byte;

mt19937 g1(time(0));

int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);}
ll randlong(ll a,ll b){return uniform_int_distribution<long long>(a, b)(g1);}

ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

int k,nums[MAXD];
ll l,r;
pll dp[MAXD][1<<11][2][2];

pll solve(int pos, int mask, int flag, int lead, ll sum){
    if(pos == 0){
        if(__builtin_popcount(mask) <= k) return mp(1,0);
        return mp(0,0);
    }
    if(dp[pos][mask][flag][lead].first != -1) return dp[pos][mask][flag][lead];
    int up = flag?nums[pos]:9;
    ll res = 0, cnt = 0;
    for(int i=0; i<=up; i++){
        int nxt = flag&&(i==nums[pos]), l = lead&&(i==0);
        pll tsum = solve(pos-1,(l?mask:mask|(1<<i)),nxt,l,sum*10+i);
        ll add = (tsum.first*1LL*i*fpow(10,pos-1,MOD))%MOD;
        res = (res+add+tsum.second)%MOD;
        cnt = (cnt+tsum.first)%MOD;
    }
    return dp[pos][mask][flag][lead] = mp(cnt,res);
}

inline pll init(ll n){
    memset(nums,0,sizeof nums);
    memset(dp,-1,sizeof dp);
    int cnt = 0;
    while(n){
        nums[++cnt] = (int)n%10;
        n/=10;
    }
    return solve(cnt,0,1,1,0);
}

int main(){
    scanf("%lld %lld %d",&l,&r,&k);
    pll first = init(r);
    pll second = init(l-1);
    printf("%lld\n",(first.second-second.second+MOD)%MOD);
}

/*
1 10 2
ans=55

10 20 1
ans=11
 */


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define all(a) a.begin(),a.end()
#define println printf("\n");
#define readln(x) getline(cin,x);
#define pb push_back
#define endl "\n"
#define INT_INF 0x3f3f3f3f
#define LL_INF 0x3f3f3f3f3f3f3f3f
#define MOD 998244353
#define MOD2 1494318097
#define SEED 131
#define mp make_pair
#define fastio cin.tie(0); cin.sync_with_stdio(0);

#define MAXD 20

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef unordered_map<int,int> umii;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef pair<int,pii> triple;
typedef int8_t byte;

mt19937 g1(time(0));

int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);}
ll randlong(ll a,ll b){return uniform_int_distribution<long long>(a, b)(g1);}

ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

int k,nums[MAXD];
ll l,r;
pll dp[MAXD][1<<11][2][2];

pll solve(int pos, int mask, int flag, int lead){
    if(pos == 0){
        if(__builtin_popcount(mask) <= k) return mp(1,0);
        return mp(0,0);
    }
    if(dp[pos][mask][flag][lead].first != -1) return dp[pos][mask][flag][lead];
    int up = flag?nums[pos]:9;
    ll res = 0, cnt = 0;
    for(int i=0; i<=up; i++){
        int nxt = flag&&(i==nums[pos]), l = lead&&(i==0);
        pll tsum = solve(pos-1,(l?mask:mask|(1<<i)),nxt,l);
        ll add = ((tsum.first*i)%MOD*fpow(10,pos-1,MOD))%MOD;
        res = (res+add+tsum.second)%MOD;
        cnt = (cnt+tsum.first);
    }
    return dp[pos][mask][flag][lead] = mp(cnt,res);
}

inline pll init(ll n){
    memset(nums,0,sizeof nums);
    memset(dp,-1,sizeof dp);
    int cnt = 0;
    while(n){
        nums[++cnt] = (int)n%10;
        n/=10;
    }
    return solve(cnt,0,1,1);
}

int main(){
    scanf("%lld %lld %d",&l,&r,&k);
    pll first = init(r);
    pll second = init(l-1);
    printf("%lld\n",(first.second-second.second+MOD)%MOD);
}

/*
1 10 2
ans=55

10 20 1
ans=11

94010733142571570 227078148960766697 9
ans=931911077
 */


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define all(a) a.begin(),a.end()
#define println printf("\n");
#define readln(x) getline(cin,x);
#define pb push_back
#define endl "\n"
#define INT_INF 0x3f3f3f3f
#define LL_INF 0x3f3f3f3f3f3f3f3f
#define MOD 998244353
#define MOD2 1494318097
#define SEED 131
#define mp make_pair
#define fastio cin.tie(0); cin.sync_with_stdio(0);

#define MAXD 20

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef unordered_map<int,int> umii;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef pair<int,pii> triple;
typedef int8_t byte;

mt19937 g1(time(0));

int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);}
ll randlong(ll a,ll b){return uniform_int_distribution<long long>(a, b)(g1);}

ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

int k,nums[MAXD];
ll l,r;
pll dp[MAXD][1<<11][2][2];

pll solve(int pos, int mask, int flag, int lead){
	if(pos == 0){
		if(__builtin_popcount(mask) <= k) return mp(1,0);
		return mp(0,0);
	}
	if(dp[pos][mask][flag][lead].first != -1) return dp[pos][mask][flag][lead];
	int up = flag?nums[pos]:9;
	ll res = 0, cnt = 0;
	for(int i=0; i<=up; i++){
		int nxt = flag&&(i==nums[pos]), l = lead&&(i==0);
		pll tsum = solve(pos-1,(l?mask:mask|(1<<i)),nxt,l);
		ll add = ((tsum.first*i)%MOD*fpow(10,pos-1,MOD))%MOD;
		res = (res+add+tsum.second)%MOD;
		cnt = (cnt+tsum.first);
	}
	return dp[pos][mask][flag][lead] = mp(cnt,res);
}

inline pll init(ll n){
	memset(nums,0,sizeof nums);
	memset(dp,-1,sizeof dp);
	int cnt = 0;
	while(n){
		nums[++cnt] = (int)(n%10);
		n/=10;
	}
	return solve(cnt,0,1,1);
}

int main(){
	scanf("%lld %lld %d",&l,&r,&k);
	pll first = init(r);
	pll second = init(l-1);
	printf("%lld\n",(first.second-second.second+MOD)%MOD);
}

/*
1 10 2
ans=55

10 20 1
ans=11

94010733142571570 227078148960766697 9
ans=931911077
 */


//In the name of Allah

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

typedef long long ll;
typedef pair <int , int> pii;

#define int ll

const int N = 2e5+10 , mod = 998244353;

int dp[20][1 << 11] , k , t[20][1 << 11] , pw[20];

string s(ll x){
	string st = "";
	while(x){
		st += char('0' + (x % 10));
		x /= 10;
	}
	reverse(st.begin() , st.end());
	return st;
}

int get(string st){
   if(st == "")
      return 0;
//	cout << st << endl;
	int nw = 0 , m = st.length() , ret = 0 , smn = 0;
	for(int i = 0 ; i < (1 << 10) ; i++)
      if(__builtin_popcount(i) <= k)
         (ret += dp[m - 1][i]) %= mod;
	for(int i = 0 ; i < m ; i++){
		smn = 10ll * smn % mod;
		for(int j = 0 ; j < st[i] - '0' ; j++){
         if(i == 0 && j == 0)
            continue;
			int nww = nw | (1 << j);
			for(int p = 0 ; p < (1 << 10) ; p++){
				if(__builtin_popcount(p) > k || (p & nww) != nww)
					continue;
				for(int msk = p ; ; msk = ((msk - 1) & p)){
					if((msk | nww) != p){
						if(msk == 0)
                     break;
                  else
                     continue;
					}
//					if(msk == 1 && j == 1)
//						cout << t[m - i - 1][msk] << endl;
					ret += dp[m - i - 1][msk];
					ret += 1ll * t[m - i - 1][msk] * (smn + j) % mod * pw[m - i - 1] % mod;
//					cout << ret << " " << msk << endl;
					ret %= mod;
					//cout << p << " " << msk << " " << ret << endl;
					if(!msk)
						break;
				}
			}
		}
		smn += st[i] - '0';
		nw |= (1 << (st[i] - '0'));
	}
//	cout << ret << " " << smn << endl;
	if(__builtin_popcount(nw) <= k)
		ret += smn;
	ret %= mod;
	return ret;
}

int32_t main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	ll l , r;
	cin >> l >> r >> k;
	pw[0] = 1;
	for(int i = 1 ; i < 20 ; i++)
		pw[i] = 10ll * pw[i - 1] % mod;
	t[0][0] = 1;
	for(int i = 1 ; i < 19 ; i++)
		for(int j = 1 ; j < (1 << 10) ; j++){
			for(int p = 0 ; p < 10 ; p++){
				if(!((1 << p) & j))
					continue;
				t[i][j] += t[i - 1][j];
				t[i][j] %= mod;
				t[i][j] += t[i - 1][j ^ (1 << p)];
				t[i][j] %= mod;
				if(t[i - 1][j])
					dp[i][j] += (10ll * dp[i - 1][j] % mod + 1ll * p * t[i - 1][j] % mod) % mod;
				dp[i][j] %= mod;
				if(t[i - 1][j ^ (1 << p)])
					dp[i][j] += (10ll * dp[i - 1][j ^ (1 << p)] % mod + 1ll * p * t[i - 1][j ^ (1 << p)] % mod) % mod;
				dp[i][j] %= mod;
			}
		}
//	cout << dp[1][1 << 9] << endl;
	//for(int i = 2 ; i <= 2345 ; i++){
		//if(get(s(i)) - get(s(i - 1)) != i)
         //cout << i << endl;
		//cout << i << " " << get(s(i)) << endl;
	//}
	int ret = get(s(r)) - get(s(l - 1));
	ret %= mod;
	ret += mod;
	ret %= mod;
	cout << ret;
	return 0;
}


//In the name of Allah

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

typedef long long ll;
typedef pair <int , int> pii;

const int N = 2e5+10 , mod = 998244353;

int dp[20][1 << 11] , k , t[20][1 << 11] , pw[20];

string s(ll x){
	string st = "";
	while(x){
		st += char('0' + (x % 10));
		x /= 10;
	}
	reverse(st.begin() , st.end());
	return st;
}

int get(string st){
//	cout << st << endl;
	int nw = 0 , m = st.length() , ret = 0 , smn = 0;
	for(int i = 0 ; i < m ; i++){
		smn = 10ll * smn % mod;
		for(int j = 0 ; j < st[i] - '0' ; j++){
			int nww = nw | (1 << j);
			if(i == 0 && j == 0)
				nww = 0;
			for(int p = 0 ; p < (1 << 10) ; p++){
				if(__builtin_popcount(p) > k || (p & nww) != nww)
					continue;
				for(int msk = p ; ; msk = ((msk - 1) & msk)){
					if((msk | nww) != p)
						break;
//					if(msk == 1 && j == 1)
//						cout << t[m - i - 1][msk] << endl;
					ret += dp[m - i - 1][msk];
					ret += 1ll * t[m - i - 1][msk] * (smn + j) % mod * pw[m - i - 1] % mod;
//					cout << ret << " " << msk << endl;
					ret %= mod;
					if(!msk)
						break;
				}
			}
		}
		smn += st[i] - '0';
		nw |= (1 << (st[i] - '0'));
	}
//	cout << ret << " " << smn << endl;
	if(__builtin_popcount(nw) <= k)
		ret += smn;
	ret %= mod;
	return ret;
}

int32_t main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	ll l , r;
	cin >> l >> r >> k;
	pw[0] = 1;
	for(int i = 1 ; i < 20 ; i++)
		pw[i] = 10ll * pw[i - 1] % mod;
	t[0][0] = 1;
	for(int i = 1 ; i < 19 ; i++)
		for(int j = 0 ; j < (1 << 10) ; j++){
			for(int p = 0 ; p < 10 ; p++){
				if(!((1 << p) & j))
					continue;
				t[i][j] += t[i - 1][j];
				t[i][j] %= mod;
				t[i][j] += t[i - 1][j ^ (1 << p)];
				t[i][j] %= mod;
				if(t[i - 1][j])
					dp[i][j] += (10ll * dp[i - 1][j] % mod + p) % mod;
				dp[i][j] %= mod;
				if(t[i - 1][j ^ (1 << p)])
					dp[i][j] += (10ll * dp[i - 1][j ^ (1 << p)] % mod + p) % mod;
				dp[i][j] %= mod;
			}
		}
//	cout << dp[1][1 << 9] << endl;
//	for(int i = 20 ; i <= 20 ; i++)
//		cout << i << " " << get(s(i)) << endl;
	int ret = get(s(r)) - get(s(l - 1));
	ret %= mod;
	ret += mod;
	ret %= mod;
	cout << ret;
	return 0;
}


//In the name of Allah

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

typedef long long ll;
typedef pair <int , int> pii;

#define int ll

const int N = 2e5+10 , mod = 998244353;

int dp[20][1 << 11] , k , t[20][1 << 11] , pw[20] , dp2[20][1 << 11] , t2[20][1 << 11];

string s(ll x){
	string st = "";
	while(x){
		st += char('0' + (x % 10));
		x /= 10;
	}
	reverse(st.begin() , st.end());
	return st;
}

int get(string st){
   if(st == "")
      return 0;
//	cout << st << endl;
	int nw = 0 , m = st.length() , ret = 0 , smn = 0;
	for(int j = 1 ; j < m ; j++)
      for(int i = 0 ; i < (1 << 10) ; i++)
         if(__builtin_popcount(i) <= k)
            (ret += dp2[j][i]) %= mod;
	for(int i = 0 ; i < m ; i++){
		smn = 10ll * smn % mod;
		for(int j = 0 ; j < st[i] - '0' ; j++){
         if(i == 0 && j == 0)
            continue;
			int nww = nw | (1 << j);
			for(int p = 0 ; p < (1 << 10) ; p++){
				if(__builtin_popcount(p) > k || (p & nww) != nww)
					continue;
				for(int msk = p ; ; msk = ((msk - 1) & p)){
					if((msk | nww) != p){
						if(msk == 0)
                     break;
                  else
                     continue;
					}
//					if(msk == 1 && j == 1)
//						cout << t[m - i - 1][msk] << endl;
					ret += dp[m - i - 1][msk];
					ret += 1ll * t[m - i - 1][msk] * (smn + j) % mod * pw[m - i - 1] % mod;
//					cout << ret << " " << msk << endl;
					ret %= mod;
					//cout << p << " " << msk << " " << ret << endl;
					if(!msk)
						break;
				}
			}
		}
		smn += st[i] - '0';
		nw |= (1 << (st[i] - '0'));
	}
//	cout << ret << " " << smn << endl;
	if(__builtin_popcount(nw) <= k)
		ret += smn;
	ret %= mod;
	return ret;
}

int32_t main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	ll l , r;
	cin >> l >> r >> k;
	pw[0] = 1;
	for(int i = 1 ; i < 20 ; i++)
		pw[i] = 10ll * pw[i - 1] % mod;
	t[0][0] = 1;
	for(int i = 1 ; i < 19 ; i++)
		for(int j = 1 ; j < (1 << 10) ; j++){
			for(int p = 0 ; p < 10 ; p++){
				if(!((1 << p) & j))
					continue;
				t[i][j] += t[i - 1][j];
				t[i][j] %= mod;
				t[i][j] += t[i - 1][j ^ (1 << p)];
				t[i][j] %= mod;
				if(t[i - 1][j])
					dp[i][j] += (10ll * dp[i - 1][j] % mod + 1ll * p * t[i - 1][j] % mod) % mod;
				dp[i][j] %= mod;
				if(t[i - 1][j ^ (1 << p)])
					dp[i][j] += (10ll * dp[i - 1][j ^ (1 << p)] % mod + 1ll * p * t[i - 1][j ^ (1 << p)] % mod) % mod;
				dp[i][j] %= mod;
			}
		}
   t2[0][0] = 1;
	for(int i = 1 ; i < 19 ; i++)
		for(int j = 2 ; j < (1 << 10) ; j++){
			for(int p = 0 ; p < 10 ; p++){
				if(!((1 << p) & j))
					continue;
				t2[i][j] += t2[i - 1][j];
				t2[i][j] %= mod;
				t2[i][j] += t2[i - 1][j ^ (1 << p)];
				t2[i][j] %= mod;
				if(t[i - 1][j])
					dp2[i][j] += (10ll * dp2[i - 1][j] % mod + 1ll * p * t2[i - 1][j] % mod) % mod;
				dp2[i][j] %= mod;
				if(t2[i - 1][j ^ (1 << p)])
					dp2[i][j] += (10ll * dp2[i - 1][j ^ (1 << p)] % mod + 1ll * p * t2[i - 1][j ^ (1 << p)] % mod) % mod;
				dp2[i][j] %= mod;
			}
		}
//	cout << dp[1][1 << 9] << endl;
	//for(int i = 2 ; i <= 2345 ; i++){
		//if(get(s(i)) - get(s(i - 1)) != i)
         //cout << i << endl;
		//cout << i << " " << get(s(i)) << endl;
	//}
	int ret = get(s(r)) - get(s(l - 1));
	ret %= mod;
	ret += mod;
	ret %= mod;
	cout << ret;
	return 0;
}


#include<bits/stdc++.h>
#define int long long
#define pa pair<int,int>
using namespace std;
inline int read(){int x=0,f=1,ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}
inline void write(int x){if (x<0) putchar('-'),x=-x; if (x>=10) write(x/10); putchar(x%10+'0');}
inline void writeln(int x){write(x); puts("");}
const int mod=998244353;
int g[20][1<<11],l,r,k,len,num[20],f[20][1<<11],bin[20],sz[1<<11];
inline void init(){
	l=read(); r=read(); k=read();
}
pa dfs(int now,int st,bool limit){
	if (now==0) return pa(sz[st]<=k,0);
	if (!limit&&~f[now][st]) return pa(f[now][st],g[now][st]);
	int ans1=0,ans2=0,mx=9; bool sta=1;
	if (st==0) sta=0;
	if (limit) mx=num[now];
	for (int i=0;i<=mx;i++){
		pa tmp=dfs(now-1,(!sta&&i==0)?st:st|(1<<i),limit&(i==mx));
		(ans1+=tmp.first)%=mod; (ans2+=tmp.second+tmp.first*i%mod*bin[now-1]%mod)%=mod;
	}
	if (!limit) f[now][st]=ans1,g[now][st]=ans2;
	return pa(ans1,ans2);
}
inline int sol(int x){
	len=0;
	for (;x;x/=10) num[++len]=x%10;
	return dfs(len,0,1).second;
}
inline void solve(){
	for (int i=1;i<(1<<11);i++){
		int cnt=0;
		for (int x=i;x;x-=x&(-x)) cnt++;
		sz[i]=cnt;
	}
	bin[0]=1;
	for (int i=1;i<=18;i++) bin[i]=bin[i-1]*10%mod;
	memset(f,-1,sizeof f);
	writeln(((sol(r)-sol(l-1))%mod+mod)%mod);
}
signed main(){
	init(); solve();
	return 0;
}


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

const long long MOD = 998244353LL;
typedef long long int lli;
typedef pair<lli, lli> ii;

ii dp[20][1<<10][2];
int vis[20][1<<10][2];
lli pow10[20];
vector<int> number;

int K;

ii calc(int pos, int mask, int f) {

    if(pos == number.size()) {
        int bitset = __builtin_popcount(mask);
        // printf("BIT %d", bitset);
        if(bitset > 0 && bitset <= K) return ii(0,1);
        else return ii(0LL,0LL);
    }

    if(vis[pos][mask][f] != -1) return dp[pos][mask][f];
    vis[pos][mask][f] = 1;

    int LIM = number[pos];
    if(f) LIM = 9;

    ii ans = ii(0LL,0LL);

    for(int i = 0; i <= LIM; ++i) {

        int nmask = mask;
        if( i> 0 || mask > 0) nmask = (nmask|(1<<i));
        ii result = calc(pos+1, nmask, f || (i < LIM));
        ans.first += result.first;
        ans.first += (((i * pow10[pos])%MOD) * ((result.second)%MOD))%MOD;
        // ans.first %= MOD;
        ans.second += result.second;
        ans.second %=MOD;
    }

    return dp[pos][mask][f] = ans;

}

lli solve(lli a) {

    number.clear();
    while(a > 0) {
        number.push_back(a%10);
        a = a/10;
    }

    reverse(number.begin(), number.end());
    memset(vis, -1, sizeof vis);

    pow10[number.size()-1] = 1LL;
    for(int i = number.size()-2; i >= 0; i--) {
        pow10[i] = (pow10[i+1] * 10)%MOD;
    }

    return calc(0,0,0).first;
    // return 0;

}

int main() {

    lli A, B;
    cin >> A >> B >> K;
    // lli ansB = solve(B);
    // lli ansA = solve(A-1) << '\n';

    lli ans = (solve(B) - solve(A-1));
    // cout << B << '\n';

    ans %= MOD; // ans += MOD; ans%=MOD;
    cout << ans << '\n';
    // cout << ansB - ansA << '\n';
    // cout << ans << '\n';

}


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

const int MOD = 998244353;
typedef long long int lli;
typedef pair<lli, lli> ii;

ii dp[20][1<<18][2];
int vis[20][1<<18][2];
lli pow10[20];
vector<int> number;

int K;

ii calc(int pos, int mask, int f) {

    if(pos == number.size()) {
        int bitset = __builtin_popcount(mask);
        // printf("BIT %d", bitset);
        if(bitset > 0 && bitset <= K) return ii(0,1);
        else return ii(0,0);
    }

    if(vis[pos][mask][f] != -1) return dp[pos][mask][f];

    int LIM = number[pos];
    if(f) LIM = 9;

    ii ans = ii(0,0);

    for(int i = 0; i <= LIM; ++i) {

        int nmask = mask;
        if( i> 0 || mask > 0) nmask = (nmask|(1<<i));
        ii result = calc(pos+1, nmask, f || (i < LIM));
        ans.first += result.first;
        ans.first += (((i * pow10[pos])%MOD) * ((result.second)%MOD))%MOD;
        ans.first %= MOD;
        ans.second += result.second;
        ans.second %MOD;
    }

    return dp[pos][mask][f] = ans;

}

lli solve(int a) {

    number.clear();
    while(a > 0) {
        number.push_back(a%10);
        a = a/10;
    }

    reverse(number.begin(), number.end());
    memset(vis, -1, sizeof vis);

    pow10[number.size()-1] = 1;
    for(int i = number.size()-2; i >= 0; i--) {
        pow10[i] = (pow10[i+1] * 10)%MOD;
    }

    return calc(0,0,0).first;

}

int main() {

    lli A, B;
    cin >> A >> B >> K;
    // lli ansB = solve(B);
    // lli ansA = solve(A-1) << '\n';

    lli ans = (solve(B) - solve(A-1))%MOD;
    cout << ans << '\n';
    // cout << ansB - ansA << '\n';
    // cout << ans << '\n';

}


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

const long long MOD = 998244353LL;
typedef long long int lli;
typedef pair<lli, lli> ii;

ii dp[20][1<<10][2];
int vis[20][1<<10][2];
lli pow10[20];
vector<int> number;

int K;

ii calc(int pos, int mask, int f) {

    if(pos == number.size()) {
        int bitset = __builtin_popcount(mask);
        // printf("BIT %d", bitset);
        if(bitset > 0 && bitset <= K) return ii(0,1);
        else return ii(0LL,0LL);
    }

    if(vis[pos][mask][f] != -1) return dp[pos][mask][f];
    vis[pos][mask][f] = 1;

    int LIM = number[pos];
    if(f) LIM = 9;

    ii ans = ii(0LL,0LL);

    for(int i = 0; i <= LIM; ++i) {

        int nmask = mask;
        if( i> 0 || mask > 0) nmask = (nmask|(1<<i));
        ii result = calc(pos+1, nmask, f || (i < LIM));
        ans.first += result.first;
        ans.first += (((i * pow10[pos])%MOD) * ((result.second)%MOD))%MOD;
        ans.first %= MOD;
        ans.second += result.second;
        ans.second %=MOD;
    }

    return dp[pos][mask][f] = ans;

}

lli solve(lli a) {

    number.clear();
    while(a > 0) {
        number.push_back(a%10);
        a = a/10;
    }

    reverse(number.begin(), number.end());
    memset(vis, -1, sizeof vis);

    pow10[number.size()-1] = 1LL;
    for(int i = number.size()-2; i >= 0; i--) {
        pow10[i] = (pow10[i+1] * 10)%MOD;
    }

    return calc(0,0,0).first;
    // return 0;

}

int main() {

    lli A, B;
    cin >> A >> B >> K;
    // lli ansB = solve(B);
    // lli ansA = solve(A-1) << '\n';

    lli ans = (solve(B) - solve(A-1));
    // cout << B << '\n';

    ans %= MOD; ans += MOD; ans%=MOD;
    cout << ans << '\n';
    // cout << ansB - ansA << '\n';
    // cout << ans << '\n';

}


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

const long long MOD = 998244353LL;
typedef long long int lli;
typedef pair<lli, lli> ii;

ii dp[20][1<<10][2];
int vis[20][1<<10][2];
lli pow10[20];
vector<int> number;

int K;

ii calc(int pos, int mask, int f) {

    if(pos == number.size()) {
        int bitset = __builtin_popcount(mask);
        // printf("BIT %d", bitset);
        if(bitset > 0 && bitset <= K) return ii(0,1);
        else return ii(0LL,0LL);
    }

    if(vis[pos][mask][f] != -1) return dp[pos][mask][f];
    vis[pos][mask][f] = 1;

    int LIM = number[pos];
    if(f) LIM = 9;

    ii ans = ii(0LL,0LL);

    for(int i = 0; i <= LIM; ++i) {

        int nmask = mask;
        if( i> 0 || mask > 0) nmask = (nmask|(1<<i));
        ii result = calc(pos+1, nmask, f || (i < LIM));
        ans.first += result.first;
        ans.first += (((i * pow10[pos])%MOD) * ((result.second)%MOD))%MOD;
        // ans.first %= MOD;
        ans.second += result.second;
        ans.second %=MOD;
    }

    return dp[pos][mask][f] = ans;

}

lli solve(lli a) {

    number.clear();
    while(a > 0) {
        number.push_back(a%10);
        a = a/10;
    }

    reverse(number.begin(), number.end());
    memset(vis, -1, sizeof vis);

    pow10[number.size()-1] = 1LL;
    for(int i = number.size()-2; i >= 0; i--) {
        pow10[i] = (pow10[i+1] * 10)%MOD;
    }

    return calc(0,0,0).first;
    // return 0;

}

int main() {

    lli A, B;
    cin >> A >> B >> K;
    // lli ansB = solve(B);
    // lli ansA = solve(A-1) << '\n';

    lli ans = (solve(B) - solve(A-1));
    // cout << B << '\n';

    ans %= MOD; ans += MOD; ans%=MOD;
    cout << ans << '\n';
    // cout << ansB - ansA << '\n';
    // cout << ans << '\n';

}


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

const long long MOD = 998244353LL;
typedef long long int lli;
typedef pair<lli, lli> ii;

ii dp[20][1<<10][2];
int vis[20][1<<10][2];
lli pow10[20];
vector<int> number;

int K;

ii calc(int pos, int mask, int f) {

    if(pos == number.size()) {
        int bitset = __builtin_popcount(mask);
        // printf("BIT %d", bitset);
        if(bitset > 0 && bitset <= K) return ii(0,1);
        else return ii(0,0);
    }

    if(vis[pos][mask][f] != -1) return dp[pos][mask][f];

    int LIM = number[pos];
    if(f) LIM = 9;

    ii ans = ii(0,0);

    for(int i = 0; i <= LIM; ++i) {

        int nmask = mask;
        if( i> 0 || mask > 0) nmask = (nmask|(1<<i));
        ii result = calc(pos+1, nmask, f | (i < LIM));
        ans.first += result.first;
        ans.first += (((i * pow10[pos])%MOD) * ((result.second)%MOD))%MOD;
        // ans.first %= MOD;
        ans.second += result.second;
        ans.second %MOD;
    }

    return dp[pos][mask][f] = ans;

}

lli solve(lli a) {

    number.clear();
    while(a > 0) {
        number.push_back(a%10);
        a = a/10;
    }

    reverse(number.begin(), number.end());
    memset(vis, -1, sizeof vis);

    pow10[number.size()-1] = 1LL;
    for(int i = number.size()-2; i >= 0; i--) {
        pow10[i] = (pow10[i+1] * 10)%MOD;
    }

    return calc(0,0,0).first;

}

int main() {

    lli A, B;
    cin >> A >> B >> K;
    // lli ansB = solve(B);
    // lli ansA = solve(A-1) << '\n';

    lli ans = (solve(B) - solve(A-1));
    // cout << B << '\n';

    ans %= MOD; ans += MOD; ans%=MOD;
    cout << ans << '\n';
    // cout << ansB - ansA << '\n';
    // cout << ans << '\n';

}


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

#define LL long long

const int N=20;
const int mod=998244353;

struct node {
	int sum,tot;
	node() {};
	node(int S,int T) { sum=S; tot=T; }
	bool check() { return ~sum && ~tot; }
}f[2][2][N][1<<10];

int A[N],ret,pw[30],k;

int lowbit(int x) {
	return x&-x;
}

int ccount(int x) {
	int cnt=0;
	if(!x) return 0;
	while(x) { x^=lowbit(x); cnt++; }
	return cnt;
}

node dfs(bool lim,bool zero,int pos,int st) {
	if(!pos) return node(0,1);
	node& now=f[lim][zero][pos][st];
	if(now.check()) return now;
	now.sum=now.tot=0;
	for(int i=0;i<= (lim?A[pos]:9);i++) {
		if(ccount(zero&&!i?0:st|(1<<i))<=k) {
			node nxt=dfs(lim && i==A[pos],zero && !i,pos-1,zero&&!i?0:st|(1<<i));
			now.sum=(now.sum+nxt.sum+1ll*i*nxt.tot%mod*pw[pos-1]%mod)%mod;
			now.tot=(now.tot+nxt.tot)%mod;
		}
	}
	f[lim][zero][pos][st]=now;
	return now;

}

int calc(LL x) {
	ret=0;
	memset(f,-1,sizeof(f));
	while(x) { A[++ret]=x%10; x/=10; }
	return dfs(1,1,ret,0).sum;
}

int main() {
	pw[0]=1;
	for(int i=1;i<=20;i++) pw[i]=10ll*pw[i-1]%mod;
	LL l,r;
	cin>>l>>r>>k;
	cout<<(mod+calc(r)-calc(l-1))%mod;
}


#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=20,MOD=998244353;
int n,m,k;
int a[N],dp[N][1<<12],f[N][1<<12],inv[N];

struct node{int num,sum;};  //num是个数，sum是和

node dfs(int x,int p,int cnt,int lead,int limit)
{
	if (x==0)
	{
		if (lead) return (node){0,0};
		else return (node){1,0};
	}
	if (!lead && !limit && dp[x][p]!=-1) return (node){dp[x][p],f[x][p]};
	int h;
	if (limit) h=a[x]; else h=9;
	node res,now;
	res.num=res.sum=now.num=now.sum=0;
	for (register int i=0; i<=h; ++i)
	{
		if (cnt==k && ((1ll<<i)&p)==0) continue;
		if (lead && (i==0))
		{
			now=dfs(x-1,p,cnt,1,(i==h)&&limit);
			res.num=(res.num+now.num)%MOD;
			res.sum=(res.sum+now.sum)%MOD;
			res.sum=(res.sum+i*inv[x]%MOD*now.num%MOD)%MOD;
			continue;
		}
		if ((1ll<<i)&p)
		{
			now=dfs(x-1,p,cnt,0,(i==h)&&limit);
			res.num=(res.num+now.num)%MOD;
			res.sum=(res.sum+now.sum)%MOD;
			res.sum=(res.sum+i*inv[x]%MOD*now.num%MOD)%MOD;
		}
		else
		{
			now=dfs(x-1,(1ll<<i)|p,cnt+1,0,(i==h)&&limit);
			res.num=(res.num+now.num)%MOD;
			res.sum=(res.sum+now.sum)%MOD;
			res.sum=(res.sum+i*inv[x]%MOD*now.num%MOD)%MOD;
		}
	}
	if (!limit && !lead)
	{
		dp[x][p]=res.num;
		f[x][p]=res.sum;
	}
	return res;
}

inline int solve(int x)
{
	memset(dp,-1,sizeof(dp));
	memset(f,0,sizeof(f));
	int len=0;
	while (x)
	{
		a[++len]=x%10;
		x/=10;
	}
	return dfs(len,0,0,1,1).sum;
	//当前位，上一位数字，当前状态，已有多少数码，lead,limit
}

signed main(){
	scanf("%lld%lld%lld",&n,&m,&k);
	inv[1]=1;
	for (register int i=2; i<=20; ++i) inv[i]=inv[i-1]*10%MOD;
	printf("%lld\n",((solve(m)-solve(n-1))%MOD+MOD)%MOD);
return 0;
}


# include <bits/stdc++.h>
# define rr register
# define int long long
const int N=20,MOD=998244353ll;
struct Node{
	int tot;
	int sum;
};
int f[N][(1<<12)][12][2][2];
int tot[N][(1<<12)][12][2][2];
int a[N],len;
int Pow[N];
int L,R;
int k;

inline void make(int x){
	len=0;
	while(x){
		a[++len]=x%10;
		x/=10;
	}
	return;
}
Node dfs(int i,int state,int cnt,int last,bool zero,bool high){
	if(cnt>k){
		return (Node){tot[i][state][last][zero][high]=0,f[i][state][last][zero][high]=0};
	}

	if(!i){
		return (Node){tot[i][state][last][zero][high]=1,f[i][state][last][zero][high]=0};
	}

	if(~f[i][state][last][zero][high]){
		return (Node){tot[i][state][last][zero][high]%MOD,f[i][state][last][zero][high]%MOD};
	}

	int totres=0,sumres=0;
	for(rr int j=0;j<=9;++j){
		if(high&&j>a[i])
			break;
		Node result;
		if(zero){
			if(!j)
				result=dfs(i-1,state,cnt,j,zero,high&&j==a[i]);
			else
				result=dfs(i-1,state|(1<<j),cnt+1,j,false,high&&j==a[i]);
		}else{
			if((state|(1<<j))!=state)
				result=dfs(i-1,state|(1<<j),cnt+1,j,zero,high&&j==a[i]);
			else
				result=dfs(i-1,state,cnt,j,zero,high&&j==a[i]);
		}
		totres=(totres+result.tot)%MOD;
		sumres=(sumres+(result.tot*j%MOD*Pow[i]+result.sum))%MOD;
	}
	return (Node){tot[i][state][last][zero][high]=totres,f[i][state][last][zero][high]=sumres};
}
inline int work(int x){
	make(x);
	memset(f,-1,sizeof(f));
	memset(tot,-1,sizeof(tot));
	return dfs(len,0,0,0,true,true).sum;
}
signed main(void){
	scanf("%I64d%I64d%I64d",&L,&R,&k);
	Pow[1]=1;
	for(rr int i=2;i<=19;++i){
		Pow[i]=(Pow[i-1]*10ll)%MOD;
	}
	printf("%I64d",(work(R)+MOD-work(L-1))%MOD);
	return 0;
}


#include<bits/stdc++.h>
#define LL long long
#define Mod 998244353
using namespace std;
inline void read(LL &x)
{
	LL f=1;x=0;char ch=getchar();
	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
	while (isdigit(ch)){x=(x<<3)+(x<<1)+(ch&15);ch=getchar();}
	x*=f;
}
LL K,L,R,a[20],top,F[20][1<<20],power[20],ans,G[20][1<<20];
inline LL dfs(LL now,LL tmp,LL limit,LL is_zero)
{
	if (now>top) return __builtin_popcount(tmp)<=K;
	if (F[now][tmp]!=-1&&(!limit)&&(!is_zero)) {ans+=G[now][tmp];ans%=Mod;return F[now][tmp];}
	LL sum=0,Max=limit?a[top-now+1]:9,lstans=ans;
	for (LL i=0;i<=Max;i++)
	{
//		if (__builtin_popcount((is_zero&&i==0)?tmp:tmp|(1<<i))>K) continue;
		LL X=dfs(now+1,(is_zero&&(i==0))?tmp:tmp|(1<<i),limit&&(i==Max),is_zero&&(i==0));
		ans+=(X%Mod)*i*power[top-now]%Mod;
		ans%=Mod;
		sum+=X;
	}
	if (!limit&&(!is_zero)) F[now][tmp]=sum,G[now][tmp]=(ans-lstans+Mod)%Mod;
	return sum;
}
inline LL solve(LL x)
{
	top=ans=0;
	memset(F,-1,sizeof(F));
	while (x){a[++top]=x%10;x/=10;}
	dfs(1,0,1,1);
	return ans;
}
int main()
{
	power[0]=1;
	for (int i=1;i<=18;i++) power[i]=(power[i-1]<<3)+(power[i-1]<<1),power[i]%=Mod;
	read(L),read(R),read(K);
	cout<<(solve(R)-solve(L-1)+Mod)%Mod<<"\n";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define MAXN 1005
typedef long long LL;
#define int LL
typedef pair<LL,LL> pii;
const LL INF=0x7f7f7f7f7f7f;
const LL mo=998244353;
LL k,l,cnt,r,a[20],pw[20];
pii dp[20][(1<<10)+5];
pii dfs(LL pos,LL S,bool lead,bool lim){
	if(!~pos)return pii(__builtin_popcount(S)<=k,0);
	if(!lead&&!lim&&~dp[pos][S].first)return dp[pos][S];
	LL up=lim?a[pos]:9;pii ans=make_pair(0,0);
	for(LL i=0;i<=up;i++){
		LL S1=(lead&&i==0)?S:(S|(1<<i));
		pii nxt=dfs(pos-1,S1,lead&&i==0,lim&&i==up);
		ans=pii((ans.first+nxt.first)%mo,(nxt.first*pw[pos]%mo*i%mo+nxt.second+ans.second)%mo);
	}
	if(!lim&&!lead)dp[pos][S]=ans;return ans;
}
LL calc(int x){
	memset(a,0,sizeof(a));cnt=0;
	while(x)a[cnt++]=x%10,x/=10;
	for(int i=0;i<=18;i++)
		for(int j=0;j<(1<<10);j++)
			dp[i][j].first=dp[i][j].second=-1;
	return dfs(cnt-1,0,1,1).second;
}
signed main(){
	pw[0]=1;for(int i=1;i<=18;i++)pw[i]=pw[i-1]*10ll%mo;
	scanf("%lld %lld %lld",&l,&r,&k);\
	printf("%lld\n",(calc(r)-calc(l-1)+mo)%mo);
	return 0;
}


#include<bits/stdc++.h>
#define sz 1000020
#define mod 998244353
using namespace std;
typedef long long ll;
struct FastIO{
    inline FastIO& operator>>(int& x)
    {
        x=0;char f=0,ch=getchar();
        while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar();
        while(ch<='9'&&ch>='0') x=x*10+ch-48,ch=getchar();
        return x=(f?-x:x),*this;
    }
    inline FastIO& operator>>(ll& x)
    {
        x=0;char f=0,ch=getchar();
        while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar();
        while(ch<='9'&&ch>='0') x=x*10+ch-48,ch=getchar();
        return x=(f?-x:x),*this;
    }
    inline FastIO& operator>>(double& x)
    {
        x=0;char f=0,ch=getchar();
        double d=0.1;
        while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar();
        while(ch<='9'&&ch>='0') x=x*10+ch-48,ch=getchar();
        if(ch=='.')
        {
        	ch=getchar();
            while(ch<='9'&&ch>='0') x+=d*(ch^48),d*=0.1,ch=getchar();
        }
        return x=(f?-x:x),*this;
    }
}read;
void file(){
    #ifndef ONLINE_JUDGE
    freopen("a.txt","r",stdin);
    #endif
}
unsigned int log2(int x){unsigned int ret;__asm__ __volatile__ ("bsrl %1, %%eax":"=a"(ret):"m"(x));return ret;}
inline ll mul(ll a,ll b){ll d=(ll)(a*(double)b/mod+0.5);ll ret=a*b-d*mod;if (ret<0) ret+=mod;return ret;}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
ll sum[20][1111][2];
ll dp[20][1111][2];
int bit[20];
ll pow10[20];
int K;
#define pll pair<ll,ll>
#define fir first
#define sec second
#define MP make_pair
pll dfs(int cur,int mask,bool zero,bool lim)
{
	if (__builtin_popcount(mask)>K) return MP(0ll,0ll);
	if (!cur) return MP(0ll,dp[cur][mask][zero]=!zero);
	if (!lim&&sum[cur][mask][zero]!=-1) return MP(sum[cur][mask][zero],dp[cur][mask][zero]);
	int End=lim?bit[cur]:9;
	ll ret=0,cnt=0,x,y;pll X;
	for (int i=0;i<=End;i++)
	{
		if (!i) X=dfs(cur-1,zero?0:(mask|1),zero,lim&&i==End);
		else X=dfs(cur-1,mask|(1<<i),0,lim&&i==End);
		x=X.fir;y=X.sec;
		(cnt+=y)%=mod;(ret+=x+y*i%mod*pow10[cur]%mod)%=mod;
	}
	if (!lim) { dp[cur][mask][zero]=cnt; sum[cur][mask][zero]=ret; }
	return MP(ret,cnt);
}
ll solve(ll x)
{
	int cnt=0;ll xx=x;
	while (xx) ++cnt,xx/=10;
	for (int i=1;i<=cnt;x/=10,i++) bit[i]=x%10;
	return dfs(cnt,0,1,1).fir;
}
int main()
{
	file();
	memset(dp,-1,sizeof(dp));memset(sum,-1,sizeof(sum));
	int i,x,y;
	pow10[1]=1;
	for (i=2;i<20;i++) pow10[i]=(pow10[i-1]*10ll)%mod;
	ll L,R;
	read>>L>>R>>K;
	x=solve(R);y=solve(L-1);
	cout<<(x-y+mod)%mod;
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#define mod 998244353
using namespace std;
struct node {
	long long x,y;
	node(){};
	node(long long X,long long Y){
		x = X,y = Y;
	}
}dp[20][(1 << 10) + 5];
long long l,r,pw[20];
int k,num[20],cnt;
node dfs(int x,int s,int up,int zero){
	if (!x)
		return node(__builtin_popcount(s) <= k,0);
	if (!up && ! zero && ~dp[x][s].x)
		return dp[x][s];
	node ans = node(0,0);
	for (int i = 0;i <= 9;i ++){
		if (up && i > num[x])
			break;
		int to;
		if (i == 0 && zero)
			to = s;
		else
			to = (s | (1 << i));
		node t = dfs(x - 1,to,(up && i == num[x]),(zero && i == 0));
		ans.x = (ans.x + t.x) % mod;
		ans.y = (ans.y + t.y + i * pw[x - 1] % mod * t.x % mod) % mod;
	}
	if (!up && ! zero)
		dp[x][s] = ans;
	return ans;
}
long long solve(int x){
	cnt = 0;
	while (x){
		num[++ cnt] = x % 10;
		x /= 10;
	}
	return dfs(cnt,0,1,1).y;
}
int main(){
	memset(dp,-1,sizeof(dp));
	scanf ("%lld%lld%d",&l,&r,&k);
	pw[0] = 1;
	for (int i = 1;i <= 18;i ++)
		pw[i] = pw[i - 1] * 10 % mod;
	printf("%lld\n",(solve(r) - solve(l - 1) + mod) % mod);
}


//package hiougyf;
import java.io.*;
import java.util.*;
import java.util.Map.Entry;
public class Solution {
		public static void main(String[] args){
			Scanner sc =new Scanner(System.in);
			int t=sc.nextInt();
			while(t-->0) {
				int n=sc.nextInt();
				int a[][]=new int[n][n];
				for(int i=0;i<n;i++) {
					for(int j=0;j<n;j++) {
						if(i==j) {
							a[i][j]=1;
							a[i][n-j-1]=1;
						}
					}
				}
				if(n%2!=0) a[0][n/2]=1;
				for(int i=0;i<n;i++) {
					for(int j=0;j<n;j++) {
						System.out.print(a[i][j]+" ");
					}
					System.out.println();
				}
			}
		}
		 static void sieveOfEratosthenes(int n,ArrayList<Integer> a)
		    {
		        // Create a boolean array "prime[0..n]" and initialize
		        // all entries it as true. A value in prime[i] will
		        // finally be false if i is Not a prime, else true.
		        boolean prime[] = new boolean[n+1];
		        for(int i=0;i<n;i++)
		            prime[i] = true;

		        for(int p = 2; p*p <=n; p++)
		        {
		            // If prime[p] is not changed, then it is a prime
		            if(prime[p] == true)
		            {
		                // Update all multiples of p
		                for(int i = p*p; i <= n; i += p)
		                    prime[i] = false;
		            }
		        }

		        // Print all prime numbers
		        for(int i = 2; i <= n; i++)
		        {
		            if(prime[i] == true)
		               a.add(i);
		        }
		    }
	  public static int floorSqrt(int x)
	    {
	        // Base Cases
	        if (x == 0 || x == 1)
	            return x;

	        // Do Binary Search for floor(sqrt(x))
	        int start = 1, end = x, ans=0;
	        while (start <= end)
	        {
	            int mid = (start + end) / 2;

	            // If x is a perfect square
	            if (mid*mid == x)
	                return mid;

	            // Since we need floor, we update answer when mid*mid is
	            // smaller than x, and move closer to sqrt(x)
	            if (mid*mid < x)
	            {
	                start = mid + 1;
	                ans = mid;
	            }
	            else   // If mid*mid is greater than x
	                end = mid-1;
	        }
	        return ans;
	    }
		static int div(int n,int b) {
			int g=-1;
			for(int i=2;i<=Math.sqrt(n);i++) {
				if(n%i==0&&i!=b) {
					g=i;
					break;
				}
			}
			return g;
		}

	  public static int gcd(int a, int b)
	    {
	        if (a == 0)
	            return b;

	        return gcd(b%a, a);
	    }
	   public static int lcm(int a, int b)
	  {
	     return (a*b)/gcd(a, b);
	  }
	   public static boolean isPrime1(int n) {
           if (n <= 1) {
               return false;
           }
           if (n == 2) {
               return true;
           }
           for (int i = 2; i <= Math.sqrt(n) + 1; i++) {
               if (n % i == 0) {
                   return false;
               }
           }
           return true;
       }
       public static boolean isPrime(int n) {
           if (n <= 1) {
               return false;
           }
           if (n == 2) {
               return true;
           }
           if (n % 2 == 0) {
               return false;
           }
           for (int i = 3; i <= Math.sqrt(n) + 1; i = i + 2) {
               if (n % i == 0) {
                   return false;
               }
           }
           return true;
       }

}


//package hiougyf;
import java.io.*;
import java.util.*;
import java.util.Map.Entry;
public class Solution {
		public static void main(String[] args){
			Scanner sc =new Scanner(System.in);
			int t=sc.nextInt();
			while(t-->0) {
				int n=sc.nextInt();
				int a[][]=new int[n][n];
				for(int i=0;i<n;i++) {
					for(int j=0;j<n;j++) {
						if(i==j) {
							a[i][j]=1;
							a[i][n-j-1]=1;
						}
					}
				}
				if(n%2!=0) {
					a[0][n/2]=1;
					a[n/2][0]=1;
				}
				for(int i=0;i<n;i++) {
					for(int j=0;j<n;j++) {
						System.out.print(a[i][j]+" ");
					}
					System.out.println();
				}
			}
		}
		 static void sieveOfEratosthenes(int n,ArrayList<Integer> a)
		    {
		        // Create a boolean array "prime[0..n]" and initialize
		        // all entries it as true. A value in prime[i] will
		        // finally be false if i is Not a prime, else true.
		        boolean prime[] = new boolean[n+1];
		        for(int i=0;i<n;i++)
		            prime[i] = true;

		        for(int p = 2; p*p <=n; p++)
		        {
		            // If prime[p] is not changed, then it is a prime
		            if(prime[p] == true)
		            {
		                // Update all multiples of p
		                for(int i = p*p; i <= n; i += p)
		                    prime[i] = false;
		            }
		        }

		        // Print all prime numbers
		        for(int i = 2; i <= n; i++)
		        {
		            if(prime[i] == true)
		               a.add(i);
		        }
		    }
	  public static int floorSqrt(int x)
	    {
	        // Base Cases
	        if (x == 0 || x == 1)
	            return x;

	        // Do Binary Search for floor(sqrt(x))
	        int start = 1, end = x, ans=0;
	        while (start <= end)
	        {
	            int mid = (start + end) / 2;

	            // If x is a perfect square
	            if (mid*mid == x)
	                return mid;

	            // Since we need floor, we update answer when mid*mid is
	            // smaller than x, and move closer to sqrt(x)
	            if (mid*mid < x)
	            {
	                start = mid + 1;
	                ans = mid;
	            }
	            else   // If mid*mid is greater than x
	                end = mid-1;
	        }
	        return ans;
	    }
		static int div(int n,int b) {
			int g=-1;
			for(int i=2;i<=Math.sqrt(n);i++) {
				if(n%i==0&&i!=b) {
					g=i;
					break;
				}
			}
			return g;
		}

	  public static int gcd(int a, int b)
	    {
	        if (a == 0)
	            return b;

	        return gcd(b%a, a);
	    }
	   public static int lcm(int a, int b)
	  {
	     return (a*b)/gcd(a, b);
	  }
	   public static boolean isPrime1(int n) {
           if (n <= 1) {
               return false;
           }
           if (n == 2) {
               return true;
           }
           for (int i = 2; i <= Math.sqrt(n) + 1; i++) {
               if (n % i == 0) {
                   return false;
               }
           }
           return true;
       }
       public static boolean isPrime(int n) {
           if (n <= 1) {
               return false;
           }
           if (n == 2) {
               return true;
           }
           if (n % 2 == 0) {
               return false;
           }
           for (int i = 3; i <= Math.sqrt(n) + 1; i = i + 2) {
               if (n % i == 0) {
                   return false;
               }
           }
           return true;
       }

}


import java.util.Scanner;

public class BPrimeSqure {
    public static void main(String[] args) {
        Scanner scnr = new Scanner(System.in);
        String str = scnr.next();
        int numCases = Integer.parseInt(str);

        while (--numCases >= 0) {
            int n = scnr.nextInt();
            int[][] mat = new int[n][n];
            solution(0, mat);
        }

        scnr.close();
    }

    public static void solution(int start, int[][] mat) {
        if (mat.length - (2 * start) <= 3) {
            for (int row = start; row < mat.length - start; row++) {
                for (int col = start; col < mat.length - start; col++) {
                    mat[row][col] = 1;
                }
            }

            for (int row = 0; row < mat.length; row++) {
                for (int col = 0; col < mat.length; col++) {
                    System.out.print(mat[row][col] + " ");
                }
                System.out.println();
            }
            return;
        }
        mat[start][start] = 1;
        mat[mat.length - start - 1][start] = 1;
        mat[start][mat.length - start - 1] = 1;
        mat[mat.length - start - 1][mat.length - start - 1] = 1;
        solution(start + 1, mat);
    }
}


import java.util.Scanner;

public class BPrimeSqure {
    public static void main(String[] args) {
        Scanner scnr = new Scanner(System.in);
        String str = scnr.next();
        int numCases = Integer.parseInt(str);

        while (--numCases >= 0) {
            int n = scnr.nextInt();
            int[][] mat = new int[n][n];
            solution(0, mat);
        }

        scnr.close();
    }

    public static void solution(int start, int[][] mat) {
        if (mat.length - start <= 3) {
            for (int row = start; row < mat.length - start; row++) {
                for (int col = start; col < mat.length - start; col++) {
                    mat[row][col] = 1;
                }
            }

            for (int row = 0; row < mat.length; row++) {
                for (int col = 0; col < mat.length; col++) {
                    System.out.print(mat[row][col]);
                }
                System.out.println();
            }
            return;
        }
        mat[start][start] = 1;
        mat[mat.length - start - 1][start] = 1;
        mat[start][mat.length - start - 1] = 1;
        mat[mat.length - start - 1][mat.length - start - 1] = 1;
        solution(start + 1, mat);
    }
}


import java.util.Scanner;

public class BPrimeSqure {
    public static void main(String[] args) {
        Scanner scnr = new Scanner(System.in);
        String str = scnr.next();
        int numCases = Integer.parseInt(str);

        while (--numCases >= 0) {
            int n = scnr.nextInt();
            int[][] mat = new int[n][n];
            solution(0, mat);
        }

        scnr.close();
    }

    public static void solution(int start, int[][] mat) {
        if (mat.length - (2 * start) <= 3) {
            for (int row = start; row < mat.length - start; row++) {
                for (int col = start; col < mat.length - start; col++) {
                    mat[row][col] = 1;
                }
            }

            for (int row = 0; row < mat.length; row++) {
                for (int col = 0; col < mat.length; col++) {
                    System.out.print(mat[row][col]);
                }
                System.out.println();
            }
            return;
        }
        mat[start][start] = 1;
        mat[mat.length - start - 1][start] = 1;
        mat[start][mat.length - start - 1] = 1;
        mat[mat.length - start - 1][mat.length - start - 1] = 1;
        solution(start + 1, mat);
    }
}


import java.util.*;

public final class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        for (int t = 0; t < T; t++) {
            int n = sc.nextInt();
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if(i == j || (n + j - 1) % n == i)
                        System.out.print("1 ");
                    else
                        System.out.print("0 ");
                }
                System.out.println();
            }
        }
    }
}


import java.util.*;

public final class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        for (int t = 0; t < T; t++) {
            int n = sc.nextInt();
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if(i == j || (n + j - 1) % n == i)
                        System.out.print(1);
                    else
                        System.out.print(0);
                }
                System.out.println();
            }
        }
    }
}


import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 *
 * @author Master_ex
 */
public class PB {

    static Set<Integer> primes = new HashSet<>() {
        {
            add(2);
            add(3);
            add(5);
            add(7);
            add(11);
        }
    };
    static int maxPrime = 11;

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        for (int i = 0; i < t; i++) {
            int n = in.nextInt();
            int lastNumber = 1;
            while (!isPrime(n - 1 + lastNumber)) {
                do {
                    lastNumber++;
                } while (isPrime(lastNumber));
            }
            for (int j = 0; j < n; j++) {
                for (int k = 0; k < n; k++) {
                    if (j == k) {
                        System.out.print(lastNumber + " ");
                    } else {
                        System.out.print(1 + " ");
                    }
                }
                System.out.println();
            }
        }
    }

    static boolean isPrime(int x) {
        if (x <= maxPrime) {
            return primes.contains(x);
        }
        boolean isprime = true;
        for (int i = 2; i <= x / 2; i++) {
            if (x % i == 0) {
                isprime = false;
                break;
            }
        }
        if (isprime) {
            if (x > maxPrime) {
                maxPrime = x;
                primes.add(x);
            }
        }
        return isprime;
    }

}


import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 *
 * @author Master_ex
 */
public class PB {

    static Set<Integer> primes = new HashSet<>() {
        {
            add(2);
            add(3);
            add(5);
            add(7);
            add(11);
        }
    };
    static int maxPrime = 11;

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        for (int i = 0; i < t; i++) {
            int n = in.nextInt();
            int lastNumber = 1;
            while (!isPrime(n - 1 + lastNumber)) {
                do {
                    lastNumber++;
                } while (isPrime(lastNumber));
            }
            for (int j = 0; j < n; j++) {
                for (int k = 0; k < n; k++) {
                    if (j == k) {
                        System.out.print(lastNumber + " ");
                    } else {
                        System.out.print(1 + " ");
                    }
                }
                System.out.println();
            }
        }
    }

    static boolean isPrime(int x) {
//        if (x <= maxPrime) {
//            return primes.contains(x);
//        }
        boolean isprime = true;
        for (int i = 2; i <= x / 2; i++) {
            if (x % i == 0) {
                isprime = false;
                break;
            }
        }
//        if (isprime) {
//            if (x > maxPrime) {
//                maxPrime = x;
//                primes.add(x);
//            }
//        }
        return isprime;
    }

}


import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 *
 * @author Master_ex
 */
public class PB {

    static Set<Integer> primes = new HashSet<>() {
        {
            add(2);
            add(3);
            add(5);
            add(7);
            add(11);
        }
    };
    static int maxPrime = 11;

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        for (int i = 0; i < t; i++) {
            int n = in.nextInt();
            int lastNumber = 1;
            while (!isPrime(n - 1 + lastNumber)) {
                do {
                    lastNumber++;
                } while (isPrime(lastNumber));
            }
            for (int j = 0; j < n; j++) {
                for (int k = 0; k < n; k++) {
                    if (j == k) {
                        System.out.print(lastNumber);
                    } else {
                        System.out.print(1);
                    }
                }
                System.out.println();
            }
        }
    }

    static boolean isPrime(int x) {
        if (x <= maxPrime) {
            return primes.contains(x);
        }
        boolean isprime = true;
        for (int i = 2; i <= x / 2; i++) {
            if (x % i == 0) {
                isprime = false;
                break;
            }
        }
        if (isprime) {
            if (x > maxPrime) {
                maxPrime = x;
                primes.add(x);
            }
        }
        return isprime;
    }

}


import java.io.*;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public class Main {

  private static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
  private static Lib l = new Lib();

  /**
   * Prime Square
   * https://codeforces.com/problemset/problem/1436/B
   */
  public static void main(String[] args) {

    int testCases = l.nextInt();
    while (testCases-- > 0) {
      process(l.nextInt());
    }

    out.close();
  }

  private static void process(int size) {
    int a[] = new int[size];
    a[0] = 1;
    a[1] = 1;
    for (int i = 0; i < size; i++) {
      for (int j = 0; j < size; j++) {
        out.print(a[(i + j) % size]);
        out.print(" ");
      }
      out.println();
    }
  }

  public static class Lib {
    BufferedReader br;
    StringTokenizer st;

    public Lib() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }

    private String next() {
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    long[] nextLongArr(int size) {
      long[] a = new long[size];
      for (int i = 0; i < size; i++) {
        a[i] = nextInt();
      }
      return a;
    }

    long nextLong() {
      return Long.parseLong(next());
    }

    double nextDouble() {
      return Double.parseDouble(next());
    }

    String nextLine() {
      String str = "";
      try {
        str = br.readLine();
      } catch (IOException e) {
        e.printStackTrace();
      }
      return str;
    }

    void shuffle(long[] arr) {
      int n = arr.length;
      Random rnd = new Random();
      for (int i = 0; i < n; ++i) {
        long tmp = arr[i];
        int randomPos = i + rnd.nextInt(n - i);
        arr[i] = arr[randomPos];
        arr[randomPos] = tmp;
      }
    }

    void sort(long[] arr) {
      // mitigate quicksort's worst case
      shuffle(arr);
      Arrays.sort(arr);
    }
  }
}


import java.io.*;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public class Main {

  private static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
  private static Lib l = new Lib();

  /**
   * Prime Square
   * https://codeforces.com/problemset/problem/1436/B
   */
  public static void main(String[] args) {

    int testCases = l.nextInt();
    while (testCases-- > 0) {
      process(l.nextInt());
    }

    out.close();
  }

  private static void process(int size) {
    int nextPrime = size;
    while (!isPrime(nextPrime)) {
      nextPrime++;
    }
    if (size == nextPrime) {
      for (int i = 0; i < size; i++) {
        for (int j = 0; j < size; j++) {
          out.print(1);
          out.print(" ");
        }
        out.println();
      }
    } else {
      for (int i = 0; i < size; i++) {
        for (int j = 0; j < size; j++) {
          if (j == i) {
            out.print(nextPrime - 1);
          } else if (j == 0 || (i == 0 && j == size - 1)) {
            out.print(1);
          } else {
            out.print(0);
          }
          out.print(" ");
        }
        out.println();
      }
    }
  }

  private static boolean isPrime(int num) {
    for (int i = 2; i * i <= num; i++) {
      if (num % i == 0) {
        return false;
      }
    }
    return true;
  }

  public static class Lib {
    BufferedReader br;
    StringTokenizer st;

    public Lib() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }

    private String next() {
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    long[] nextLongArr(int size) {
      long[] a = new long[size];
      for (int i = 0; i < size; i++) {
        a[i] = nextInt();
      }
      return a;
    }

    long nextLong() {
      return Long.parseLong(next());
    }

    double nextDouble() {
      return Double.parseDouble(next());
    }

    String nextLine() {
      String str = "";
      try {
        str = br.readLine();
      } catch (IOException e) {
        e.printStackTrace();
      }
      return str;
    }

    void shuffle(long[] arr) {
      int n = arr.length;
      Random rnd = new Random();
      for (int i = 0; i < n; ++i) {
        long tmp = arr[i];
        int randomPos = i + rnd.nextInt(n - i);
        arr[i] = arr[randomPos];
        arr[randomPos] = tmp;
      }
    }

    void sort(long[] arr) {
      // mitigate quicksort's worst case
      shuffle(arr);
      Arrays.sort(arr);
    }
  }
}


import java.io.*;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public class Main {

  private static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
  private static Lib l = new Lib();

  /**
   * Prime Square
   * https://codeforces.com/problemset/problem/1436/B
   */
  public static void main(String[] args) {

    int testCases = l.nextInt();
    while (testCases-- > 0) {
      process(l.nextInt());
    }

    out.close();
  }

  private static void process(int size) {
    int nextPrime = size;
    while (!isPrime(nextPrime)) {
      nextPrime++;
    }
    for (int i = 0; i < size; i++) {
      for (int j = 0; j < size; j++) {
        if (j == i) {
          out.print(nextPrime - size + 1);
        } else {
          out.print(1);
        }
        out.print(" ");
      }
      out.println();
    }
  }

  private static boolean isPrime(int num) {
    for (int i = 2; i * i <= num; i++) {
      if (num % i == 0) {
        return false;
      }
    }
    return true;
  }

  public static class Lib {
    BufferedReader br;
    StringTokenizer st;

    public Lib() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }

    private String next() {
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    long[] nextLongArr(int size) {
      long[] a = new long[size];
      for (int i = 0; i < size; i++) {
        a[i] = nextInt();
      }
      return a;
    }

    long nextLong() {
      return Long.parseLong(next());
    }

    double nextDouble() {
      return Double.parseDouble(next());
    }

    String nextLine() {
      String str = "";
      try {
        str = br.readLine();
      } catch (IOException e) {
        e.printStackTrace();
      }
      return str;
    }

    void shuffle(long[] arr) {
      int n = arr.length;
      Random rnd = new Random();
      for (int i = 0; i < n; ++i) {
        long tmp = arr[i];
        int randomPos = i + rnd.nextInt(n - i);
        arr[i] = arr[randomPos];
        arr[randomPos] = tmp;
      }
    }

    void sort(long[] arr) {
      // mitigate quicksort's worst case
      shuffle(arr);
      Arrays.sort(arr);
    }
  }
}


import java.io.*;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public class Main {

  private static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
  private static Lib l = new Lib();

  /**
   * Prime Square
   * https://codeforces.com/problemset/problem/1436/B
   */
  public static void main(String[] args) {

    int testCases = l.nextInt();
    while (testCases-- > 0) {
      process(l.nextInt());
    }

    out.close();
  }

  private static void process(int size) {
    int nextPrime = size;
    while (!isPrime(nextPrime)) {
      nextPrime++;
    }
    if (size == nextPrime) {
      for (int i = 0; i < size; i++) {
        for (int j = 0; j < size; j++) {
          out.print(1);
          out.print(" ");
        }
        out.println();
      }
    } else {
      for (int i = 0; i < size; i++) {
        int count = 0;
        for (int j = 0; j < size; j++) {
          if (j == i) {
            out.print(nextPrime - 1);
          } else if (j == (i + 1) % size) {
            out.print(1);
          } else {
            out.print(0);
          }
          out.print(" ");
        }
        out.println();
      }
    }
  }

  private static boolean isPrime(int num) {
    for (int i = 2; i * i <= num; i++) {
      if (num % i == 0) {
        return false;
      }
    }
    return true;
  }

  public static class Lib {
    BufferedReader br;
    StringTokenizer st;

    public Lib() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }

    private String next() {
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    long[] nextLongArr(int size) {
      long[] a = new long[size];
      for (int i = 0; i < size; i++) {
        a[i] = nextInt();
      }
      return a;
    }

    long nextLong() {
      return Long.parseLong(next());
    }

    double nextDouble() {
      return Double.parseDouble(next());
    }

    String nextLine() {
      String str = "";
      try {
        str = br.readLine();
      } catch (IOException e) {
        e.printStackTrace();
      }
      return str;
    }

    void shuffle(long[] arr) {
      int n = arr.length;
      Random rnd = new Random();
      for (int i = 0; i < n; ++i) {
        long tmp = arr[i];
        int randomPos = i + rnd.nextInt(n - i);
        arr[i] = arr[randomPos];
        arr[randomPos] = tmp;
      }
    }

    void sort(long[] arr) {
      // mitigate quicksort's worst case
      shuffle(arr);
      Arrays.sort(arr);
    }
  }
}


import java.util.*;
import java.io.*;
public class Codeforces {

	static void sort(int[] ar) {
		ArrayList<Integer> al=new ArrayList<>();
		for (int i=0;i<ar.length;i++) al.add(ar[i]);
		Collections.sort(al);
		for (int i=0; i<ar.length; i++) ar[i]=al.get(i);
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int t=sc.nextInt();
		while(t-->0)
		{
			int n=sc.nextInt();
			int a[][]=new int[n][n];
			int cnt=0;
			for(int i=0;i<n;i++)
			{

				int x=a[i][cnt];
				int y=a[i][n-cnt-1];
				for(int j=0;j<n;j++)
				{
					if(j==cnt || j==n-cnt-1)
						a[i][j]=1;
					else
						a[i][j]=0;
				}
				cnt++;
			}
			if(n%2!=0)
				a[(n+1)/2-1][(n+1)/2-1-1]=1;

			for(int i=0;i<n;i++)
			{
				for(int j=0;j<n;j++)
					System.out.print(a[i][j]+" ");
				System.out.println();
			}

		}

	}

}


import java.util.*;
import java.io.*;
public class Codeforces {

	static void sort(int[] ar) {
		ArrayList<Integer> al=new ArrayList<>();
		for (int i=0;i<ar.length;i++) al.add(ar[i]);
		Collections.sort(al);
		for (int i=0; i<ar.length; i++) ar[i]=al.get(i);
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int t=sc.nextInt();
		while(t-->0)
		{
			int n=sc.nextInt();
			int a[][]=new int[n][n];
			int cnt=0;
			for(int i=0;i<n;i++)
			{

				int x=a[i][cnt];
				int y=a[i][n-cnt-1];
				for(int j=0;j<n;j++)
				{
					if(j==cnt || j==n-cnt-1)
						a[i][j]=1;
					else
						a[i][j]=0;
				}
				cnt++;
			}
			if(n%2!=0)
			{
				a[(n+1)/2-1][(n+1)/2-1-1]=1;
				a[(n+1)/2-1-1][(n+1)/2-1]=1;
			}

			for(int i=0;i<n;i++)
			{
				for(int j=0;j<n;j++)
					System.out.print(a[i][j]+" ");
				System.out.println();
			}

		}

	}

}


//   package com.company;
import java.text.DecimalFormat;
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main{
    /*
     ** || ॐ श्री गणेशाय नमः ||
     ** @𝙖𝙪𝙩𝙝𝙤𝙧 𝙅𝙞𝙜𝙖𝙧_𝙉𝙖𝙞𝙣𝙪𝙟𝙞
     ** 𝙎𝙑𝙉𝙄𝙏-𝙎𝙐𝙍𝘼𝙏
     */
    public static void main(String args[]){
        PrintWriter out=new PrintWriter(System.out);
        InputReader in=new InputReader(System.in);
        TASK solver = new TASK();
        int t=1;
         t = in.nextInt();
        for(int i=0;i<t;i++)
        {
            solver.solve(in,out,i);
        }
        out.close();
    }
    static class TASK {
        static int mod = 1000000007;
        static int a[] = new int[100000];
        static int x = 2;
        static {
            for(int i=2;i<100000;i++)
            {
                if(a[i]==0)
                {
                    for(int j=2;j*i<100000;j++)
                    {
                        a[j]=1;
                    }
                }
            }
            for(int i=99999;i>=0;i--)
            {
                if(a[i]==0)
                {
                    x=i;
                    break;
                }
            }
        }
        void solve(InputReader in, PrintWriter out, int testNumber) {
            int n = in.nextInt();
            for(int i=0;i<n;i++)
            {
                for(int j=0;j<n;j++)
                {
                    if(j==n-1)
                        System.out.print(2);
                    else
                        System.out.print(0+" ");
                }
                System.out.println();
            }

        }
    }

    static class pair{
        int x;
        int y;
        pair(int x,int y)
        {
            this.x=x;
            this.y=y;
        }

    }
    static class Maths {
        static long gcd(long a, long b) {
            if (a == 0)
                return b;
            return gcd(b % a, a);
        }

        public static long lcm(long a, long b) {
            return (a * b) / gcd(a, b);
        }

        public static long factorial(int n) {
            long fact = 1;
            for (int i = 1; i <= n; i++) {
                fact *= i;
            }
            return fact;
        }
    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        public int nextInt() {
            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
}


//   package com.company;
import java.text.DecimalFormat;
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main{
    /*
     ** || ॐ श्री गणेशाय नमः ||
     ** @𝙖𝙪𝙩𝙝𝙤𝙧 𝙅𝙞𝙜𝙖𝙧_𝙉𝙖𝙞𝙣𝙪𝙟𝙞
     ** 𝙎𝙑𝙉𝙄𝙏-𝙎𝙐𝙍𝘼𝙏
     */
    public static void main(String args[]){
        PrintWriter out=new PrintWriter(System.out);
        InputReader in=new InputReader(System.in);
        TASK solver = new TASK();
        int t=1;
         t = in.nextInt();
        for(int i=0;i<t;i++)
        {
            solver.solve(in,out,i);
        }
        out.close();
    }
    static class TASK {
        static int mod = 1000000007;

        void solve(InputReader in, PrintWriter out, int testNumber) {
            int n = in.nextInt();
            for(int i=0;i<n;i++)
            {
                for(int j=0;j<n;j++)
                {
                    if(j==i)
                        System.out.print(2+" ");
                    else
                        System.out.print(0+" ");
                }
                System.out.println();
            }

        }
    }

    static class pair{
        int x;
        int y;
        pair(int x,int y)
        {
            this.x=x;
            this.y=y;
        }

    }
    static class Maths {
        static long gcd(long a, long b) {
            if (a == 0)
                return b;
            return gcd(b % a, a);
        }

        public static long lcm(long a, long b) {
            return (a * b) / gcd(a, b);
        }

        public static long factorial(int n) {
            long fact = 1;
            for (int i = 1; i <= n; i++) {
                fact *= i;
            }
            return fact;
        }
    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        public int nextInt() {
            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
}


//   package com.company;
import java.text.DecimalFormat;
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main{
    /*
     ** || ॐ श्री गणेशाय नमः ||
     ** @𝙖𝙪𝙩𝙝𝙤𝙧 𝙅𝙞𝙜𝙖𝙧_𝙉𝙖𝙞𝙣𝙪𝙟𝙞
     ** 𝙎𝙑𝙉𝙄𝙏-𝙎𝙐𝙍𝘼𝙏
     */
    public static void main(String args[]){
        PrintWriter out=new PrintWriter(System.out);
        InputReader in=new InputReader(System.in);
        TASK solver = new TASK();
        int t=1;
//         t = in.nextInt();
        for(int i=0;i<t;i++)
        {
            solver.solve(in,out,i);
        }
        out.close();
    }
    static class TASK {
        static int mod = 1000000000+7;
//        static long a[] = new long[1001];
//        static {
//            a[0]=1l;
//            for(int i=1;i<1001;i++)
//            {
//                a[i]=(a[i-1]*i)%mod;
//            }
//        }
       static int a[] = new int[100000];
        static ArrayList<Integer> al = new ArrayList<>();
        static {
            al.add(2);
            for(int i=3;i<100000;i++)
            {
                boolean flag=true;
                for(int j=0;j<al.size();j++)
                {
                    if(i%al.get(j)==0)
                    {
                        flag=false;
                        break;
                    }
                }
                if(flag)
                    al.add(i);
            }
            for(int i=0;i<al.size();i++)
            {
                a[al.get(i)]++;
            }
//            System.out.println(al);

        }

        void solve(InputReader in, PrintWriter out, int testNumber) {
            int n = in.nextInt();
            for(int i=0;i<al.size();i++)
            {
                if(al.get(i)-(n-1)>=0 && a[al.get(i)-(n-1)]==0)
                {
                    for(int j=0;j<n;j++)
                    {
                        for(int k=0;k<n;k++)
                        {
                            if(j==k)
                                System.out.print(al.get(i)-(n-1)+" ");
                            else
                                System.out.print(1+" ");
                        }
                        System.out.println();
                    }
                    break;
                }
            }

        }
    }

    static class pair{
        int x;
        int y;
        pair(int x,int y)
        {
            this.x=x;
            this.y=y;
        }

    }
    static class Maths {
        static long gcd(long a, long b) {
            if (a == 0)
                return b;
            return gcd(b % a, a);
        }

        public static long lcm(long a, long b) {
            return (a * b) / gcd(a, b);
        }

        public static long factorial(int n) {
            long fact = 1;
            for (int i = 1; i <= n; i++) {
                fact *= i;
            }
            return fact;
        }
    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        public int nextInt() {
            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
}