/***************************************************
 * Problem Name : A. Palindromic Twist.cpp
 * Problem Link :
 * OJ           : Codeforces
 * Verdict      : Trying
 * Date         : 2018-08-18
 * Problem Type :
 * Author Name  : Saikat Sharma
 * University   : CSE, MBSTU
 ***************************************************/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<cstring>
#include<string>
#include<sstream>
#include<cmath>
#include<vector>
#include<queue>
#include<cstdlib>
#include<deque>
#include<stack>
#include<map>
#include<set>
#define __FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define SET(a,v) memset(a,v,sizeof(a))
#define pii pair<int,int>
#define pll pair <ll, ll>
#define debug cout <<"#########\n";
#define nl cout << "\n";
#define sp cout << " ";
#define sl(n) scanf("%lld", &n)
#define sf(n) scanf("%lf", &n)
#define si(n) scanf("%d", &n)
#define ss(n) scanf("%s", n)
#define pf(n) scanf("%d", n)
#define pfl(n) scanf("%lld", n)
#define all(v) v.begin(), v.end()
#define Pow2(x) ((x)*(x))
#define Mod(x, m) ((((x) % (m)) + (m)) % (m))
#define Max3(a, b, c) max(a, max(b, c))
#define Min3(a, b, c) min(a, min(b, c))
#define pb push_back
#define mk make_pair
#define MAX 100005
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

template <typename T>
std::string NumberToString ( T Number ) {
    std::ostringstream ss;
    ss << Number;
    return ss.str();
}
ll lcm (ll a, ll b) {
    return a * b / __gcd (a, b);
}
/************************************ Code Start Here ******************************************************/
int main () {
    __FastIO;
    int tc, N;
    cin >> tc;

    for (int t = 1 ; t <= tc; t++) {
        cin >> N;
        string str;
        cin >> str;
        int flag = 0;

        for (int i = 0; i < N / 2; i++) {
            if (str[i] == str[N - i - 1]) continue;

            if (abs (str[i] - str[N - i - 1]) == 2) continue;

            flag = 1;
            break;
        }

        if (!flag) cout << "YES\n";
        else cout << "NO\n";
    }

    return 0;
}


/***************************************************
 * Problem Name : A. Palindromic Twist.cpp
 * Problem Link :
 * OJ           : Codeforces
 * Verdict      : Trying
 * Date         : 2018-08-18
 * Problem Type :
 * Author Name  : Saikat Sharma
 * University   : CSE, MBSTU
 ***************************************************/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<cstring>
#include<string>
#include<sstream>
#include<cmath>
#include<vector>
#include<queue>
#include<cstdlib>
#include<deque>
#include<stack>
#include<map>
#include<set>
#define __FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define SET(a,v) memset(a,v,sizeof(a))
#define pii pair<int,int>
#define pll pair <ll, ll>
#define debug cout <<"#########\n";
#define nl cout << "\n";
#define sp cout << " ";
#define sl(n) scanf("%lld", &n)
#define sf(n) scanf("%lf", &n)
#define si(n) scanf("%d", &n)
#define ss(n) scanf("%s", n)
#define pf(n) scanf("%d", n)
#define pfl(n) scanf("%lld", n)
#define all(v) v.begin(), v.end()
#define Pow2(x) ((x)*(x))
#define Mod(x, m) ((((x) % (m)) + (m)) % (m))
#define Max3(a, b, c) max(a, max(b, c))
#define Min3(a, b, c) min(a, min(b, c))
#define pb push_back
#define mk make_pair
#define MAX 100005
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

template <typename T>
std::string NumberToString ( T Number ) {
    std::ostringstream ss;
    ss << Number;
    return ss.str();
}
ll lcm (ll a, ll b) {
    return a * b / __gcd (a, b);
}
/************************************ Code Start Here ******************************************************/
//~ bool isPal (string str) {
    //~ string s = str;
    //~ reverse (all (s) );
    //~ int f = 0;
    //~ char ch = str[0];
    //~ for(int i = 1; i<(int)str.size(); i++){
		//~ if(ch != str[i]) f = 1;
	//~ }
    //~ if (s == str && f) return 1;
    //~ else return 0;
//~ }
//~ bool check (int i, string str, int N) {
    //~ for (int j = i + 1; j < N; j++) {
        //~ string s = str;
        //~ char ch = str[j];

        //~ if (ch == 'a') {
            //~ s[j] = 'b';

            //~ if (isPal(s) ) {
                //~ return 1;
            //~ }

        //~ } else if (ch == 'z') {
            //~ s[j] = 'y';

            //~ if (isPal(s) ) {
                //~ return 1;
            //~ }

        //~ } else {
            //~ s[j] = ch - 1;

            //~ if (isPal(s) ) {
                //~ return 1;
            //~ }

            //~ s[j] = ch+ 1;

            //~ if (isPal(s) ) {
                //~ return 1;
            //~ }
        //~ }

        //~ if (isPal(str) ) {
                //~ return 1;
        //~ }
    //~ }
    //~ return 0;
//~ }
int main () {
    //~ __FastIO;
    int tc, N;
    cin >> tc;

    for (int t = 1 ; t <= tc; t++) {
        cin >> N;
        string str;
        cin >> str;
        int flag = 0;

        for (int i = 0; i < N/2; i++) {
			if(str[i] == str[N-i-1]) continue;
			if(abs(str[i] - str[N-i-1]) == 2) continue;
			flag = 1;
			break;
            //~ string s = str;
            //~ char ch = str[i];

            //~ if (ch == 'a') {
                //~ s[i] = 'b';

                //~ if (check (i, s, N) ) {
                    //~ flag = 1;
                    //~ break;
                //~ }

            //~ } else if (ch == 'z') {
                //~ s[i] = 'y';

                //~ if (check (i, s, N) ) {
                    //~ flag = 1;
                    //~ break;
                //~ }

            //~ } else {
                //~ s[i] = ch - 1;

                //~ if (check (i, s, N) ) {
                    //~ flag = 1;
                    //~ break;
                //~ }

                //~ s[i] = ch + 1;

                //~ if (check (i, s, N) ) {
                    //~ flag = 1;
                    //~ break;
                //~ }
            //~ }

            //~ if (check (i, str, N) ) {
                //~ flag = 1;
                //~ break;
            //~ }
        }
        if(!flag) cout << "YES\n";
        else cout << "NO\n";
    }

    return 0;
}


/***************************************************
 * Problem Name : A. Palindromic Twist.cpp
 * Problem Link :
 * OJ           : Codeforces
 * Verdict      : Trying
 * Date         : 2018-08-18
 * Problem Type :
 * Author Name  : Saikat Sharma
 * University   : CSE, MBSTU
 ***************************************************/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<cstring>
#include<string>
#include<sstream>
#include<cmath>
#include<vector>
#include<queue>
#include<cstdlib>
#include<deque>
#include<stack>
#include<map>
#include<set>
#define __FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define SET(a,v) memset(a,v,sizeof(a))
#define pii pair<int,int>
#define pll pair <ll, ll>
#define debug cout <<"#########\n";
#define nl cout << "\n";
#define sp cout << " ";
#define sl(n) scanf("%lld", &n)
#define sf(n) scanf("%lf", &n)
#define si(n) scanf("%d", &n)
#define ss(n) scanf("%s", n)
#define pf(n) scanf("%d", n)
#define pfl(n) scanf("%lld", n)
#define all(v) v.begin(), v.end()
#define Pow2(x) ((x)*(x))
#define Mod(x, m) ((((x) % (m)) + (m)) % (m))
#define Max3(a, b, c) max(a, max(b, c))
#define Min3(a, b, c) min(a, min(b, c))
#define pb push_back
#define mk make_pair
#define MAX 100005
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

template <typename T>
std::string NumberToString ( T Number ) {
    std::ostringstream ss;
    ss << Number;
    return ss.str();
}
ll lcm (ll a, ll b) {
    return a * b / __gcd (a, b);
}
/************************************ Code Start Here ******************************************************/
bool isPal (string str) {
    string s = str;
    reverse (all (s) );

    if (s == str) return 1;
    else return 0;
}
bool check (int i, string str, int N) {
    for (int j = i + 1; j < N; j++) {
        string s = str;
        char ch = str[j];

        if (ch == 'a') {
            s[i] = 'b';

            if (isPal(s) ) {
                return 1;
            }

        } else if (ch == 'z') {
            s[i] = 'y';

            if (isPal(s) ) {
                return 1;
            }

        } else {
            s[i] = ch--;

            if (isPal(s) ) {
                return 1;
            }

            s[i] = ch++;

            if (isPal(s) ) {
                return 1;
            }
        }

        if (isPal(str) ) {
                return 1;
        }
    }
    return 0;
}
int main () {
    //~ __FastIO;
    int tc, N;
    cin >> tc;

    for (int t = 1 ; t <= tc; t++) {
        cin >> N;
        string str;
        cin >> str;
        int flag = 0;

        for (int i = 0; i < N; i++) {
            string s = str;
            char ch = str[i];

            if (ch == 'a') {
                s[i] = 'b';

                if (check (i, s, N) ) {
                    flag = 1;
                    break;
                }

            } else if (ch == 'z') {
                s[i] = 'y';

                if (check (i, s, N) ) {
                    flag = 1;
                    break;
                }

            } else {
                s[i] = ch--;

                if (check (i, s, N) ) {
                    flag = 1;
                    break;
                }

                s[i] = ch++;

                if (check (i, s, N) ) {
                    flag = 1;
                    break;
                }
            }

            if (check (i, str, N) ) {
                flag = 1;
                break;
            }
        }
        if(!flag) cout << "YES\n";
        else cout << "NO\n";
    }

    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        int count;
        char arr[n+1];
        for(int i=1;i<=n;i++)
            cin >> arr[i];
            int j=n;
            count=0;
            for(int i=1;i<=n/2;i++)
            {
                if(arr[i]=='a'||arr[i]=='z')
                {
                    if(arr[j]==arr[i])
                        continue;
                        else
                        {
                            count=1;
                            break;
                        }
                }
                        else
                        {
                            if(arr[i]==arr[j])
                                continue;
                                if(arr[i]-arr[j]==2||arr[j]-arr[i]==2)
                                    continue;

                                    count=1;
                                    break;
                        }
                }
            }
            if(count==1)
                cout << "NO" << endl;
                else
                    cout << "YES" << endl;

    }
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        int count;
        char arr[n+1];
        for(int i=1;i<=n;i++)
            cin >> arr[i];
            int j=n;
            count=0;
            for(int i=1;i<=n/2;i++,j--)
            {
                if(arr[i]=='a'||arr[i]=='z')
                {
                    if(arr[j]==arr[i])
                        continue;
                        else
                        {
                            count=1;
                            break;
                        }
                }
                        else
                        {
                            if(arr[i]==arr[j])
                                continue;
                                if(arr[i]-arr[j]==2||arr[j]-arr[i]==2)
                                    continue;

                                    count=1;
                                    break;
                        }

            }
            if(count==1)
                cout << "NO" << endl;
                else
                    cout << "YES" << endl;

    }
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        int count;
        char arr[n+1];
        for(int i=1;i<=n;i++)
            cin >> arr[i];
            int j=n;
            count=0;
            for(int i=1;i<=n/2;i++,j--)
            {
                if(arr[i]=='a'||arr[i]=='z')
                {
                    if(arr[j]==arr[i])
                        continue;
                        else if(arr[i]=='a'&&arr[j]=='c')
                            continue;
                            else if(arr[i]=='z'&&arr[j]=='x')
                                continue;
                        else
                        {
                            count=1;
                            break;
                        }
                }
                        else
                        {
                            if(arr[i]==arr[j])
                                continue;
                                if(arr[i]-arr[j]==2||arr[j]-arr[i]==2)
                                    continue;

                                    count=1;
                                    break;
                        }

            }
            if(count==1)
                cout << "NO" << endl;
                else
                    cout << "YES" << endl;

    }
    return 0;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
 int t;
 cin >> t;
 while(t--)
 {
     int n;
     cin >> n;
     char arr[n+1];

     for(int i=1;i<=n;i++)
         cin >> arr[i];
          int i=1;
          int j=n;
          int count=0;
         for(;i<=n/2;i++,j--)
         {
             if(arr[i]=='a')
             {
                 if(arr[j]=='a')
                     continue;
                     else
                     {
                         count=1;
                         break;
                     }
             }

                 else if(arr[i]=='z')

{
        if(arr[j]=='z')
        continue;
 else{
     count=1;
     break;
 }
}
                   else  if(arr[i]-arr[j]==2||arr[j]-arr[i]==2)
                       continue;
                       else if(arr[i]==arr[j])
                           continue;
                           else
                           {
                               count=1;
                               break;
                           }
         }
         if(count==0)
             cout << "YES" << endl;
             else
                 cout << "NO" << endl;
 }
 return 0;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
 int t;
 cin >> t;
 while(t--)
 {
     int n;
     cin >> n;
     char arr[n+1];

     for(int i=1;i<=n;i++)
         cin >> arr[i];
          int i=1;
          int j=n;
          int count=0;
         for(;i<=n/2;i++,j--)
         {
             if(arr[i]=='a')
             {
                 if(arr[j]=='a')
                     continue;
                     else
                     {
                         count=1;
                         break;
                     }
             }

                 else if(arr[i]=='z')

{
        if(arr[j]=='z')
        continue;
 else{
     count=1;
     break;
 }
}
                   else  if(arr[i]-arr[j]==2||arr[j]-arr[i]==2)
                       continue;
                       else if(arr[i]==arr[j])
                           continue;
                           else
                           {
                               count=1;
                               break;
                           }
         }
         if(count==0)
             cout << "Yes" << endl;
             else
                 cout << "No" << endl;
 }
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int T;
	cin >> T;
	while(T--)
	{
		long long int n, i;
		string s;
		cin >> n;
		long long int num = n/2;
		cin >> s;
		for(i =0;i<num;i++)
		{
			if(s[i]=='a' && s[n-i-1]!='a' && s[n-i-1]!='c')
			{
				cout << "NO" << endl;
				break;
			}
			if(s[i]=='z' && s[n-i-i]!='z' && s[n-i-1]!='x')
			{
				cout << "NO" << endl;
				break;
			}
			if((s[i]=='a' && s[n-i-1]=='a') || (s[i]=='z' && s[n-i-1]=='z'))
			{
				continue;
			}
			else
			{
				long long int n1,n2,n3,n4;
				n1 = int(s[i])-48-1;
				n2 = int(s[i])-48+1;
				n3 = int(s[n-i-1])-48-1;
				n4 = int(s[n-i-1])-48+1;
				if(n1==n3 || n1 == n4 || n2 == n3 || n2 == n4)
				{
					continue;
				}
				else
				{
					cout << "NO" << endl;
					break;
				}
			}
		}
		if(i==num)
		{
			cout << "YES" << endl;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int T;
	cin >> T;
	while(T--)
	{
		long long int n, i;
		string s;
		cin >> n;
		long long int num = n/2;
		cin >> s;
		for(i = 0;i<num;i++)
		{
			if(s[i]=='a')
			{
				if(s[n-i-1]!='a' && s[n-i-1]!='c')
				{
				cout << "NO" << endl;
				break;
				}
			}
            if(s[i]=='z')
			{
				if(s[n-i-1]!='z' && s[n-i-1]!='x')
				{
				cout << "NO" << endl;
				break;
				}
			}
			if(int(s[i])-48==int(s[n-i-1])-48)
			{
				continue;
			}
			else
			{
				long long int n1,n2,n3,n4;
				n1 = int(s[i])-48-1;
				n2 = int(s[i])-48+1;
				n3 = int(s[n-i-1])-48-1;
				n4 = int(s[n-i-1])-48+1;
				if(n1==n3 || n1 == n4 || n2 == n3 || n2 == n4)
				{
					continue;
				}
				else
				{
					cout << "NO" << endl;
					break;
				}
			}
		}
		if(i==num)
		{
			cout << "YES" << endl;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int T;
	cin >> T;
	while(T--)
	{
		long long int n, i;
		string s;
		cin >> n;
		long long int num = n/2;
		cin >> s;
		for(i =0;i<num;i++)
		{
			if(s[i]=='a' && s[n-i-1]!='a')
			{
				cout << "NO" << endl;
				break;
			}
			if(s[i]=='z' && s[n-i-i]!='z')
			{
				cout << "NO" << endl;
				break;
			}
			else
			{
				long long int n1,n2,n3,n4;
				n1 = int(s[i])-48-1;
				n2 = int(s[i])-48+1;
				n3 = int(s[n-i-1])-48-1;
				n4 = int(s[n-i-1])-48+1;
				if(n1==n3 || n1 == n4 || n2 == n3 || n2 == n4)
				{
					continue;
				}
				else
				{
					cout << "NO" << endl;
					break;
				}
			}
		}
		if(i==num)
		{
			cout << "YES" << endl;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int T;
	cin >> T;
	while(T--)
	{
		long long int n, i;
		string s;
		cin >> n;
		long long int num = n/2;
		cin >> s;
		for(i =0;i<num;i++)
		{
			if(s[i]=='a' && s[n-i-1]!='a' && s[n-i-1]!='c')
			{
				cout << "NO" << endl;
				break;
			}
			if(s[i]=='z' && s[n-i-i]!='z' && s[n-i-1]!='x')
			{
				cout << "NO" << endl;
				break;
			}
			if(int(s[i])-48==int(s[n-i-1])-48)
			{
				continue;
			}
			else
			{
				long long int n1,n2,n3,n4;
				n1 = int(s[i])-48-1;
				n2 = int(s[i])-48+1;
				n3 = int(s[n-i-1])-48-1;
				n4 = int(s[n-i-1])-48+1;
				if(n1==n3 || n1 == n4 || n2 == n3 || n2 == n4)
				{
					continue;
				}
				else
				{
					cout << "NO" << endl;
					break;
				}
			}
		}
		if(i==num)
		{
			cout << "YES" << endl;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int T;
	cin >> T;
	while(T--)
	{
		long long int n, i;
		string s;
		cin >> n;
		long long int num = n/2;
		cin >> s;
		for(i =0;i<num;i++)
		{
			if(s[i]=='a' && s[n-i-1]!='a' && s[n-i-1]!='c')
			{
				cout << "NO" << endl;
				break;
			}
			if(s[i]=='z' && s[n-i-i]!='z' && s[n-i-1]!='x')
			{
				cout << "NO" << endl;
				break;
			}
			else
			{
				long long int n1,n2,n3,n4;
				n1 = int(s[i])-48-1;
				n2 = int(s[i])-48+1;
				n3 = int(s[n-i-1])-48-1;
				n4 = int(s[n-i-1])-48+1;
				if(n1==n3 || n1 == n4 || n2 == n3 || n2 == n4)
				{
					continue;
				}
				else
				{
					cout << "NO" << endl;
					break;
				}
			}
		}
		if(i==num)
		{
			cout << "YES" << endl;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#include<conio.h>
using namespace std;
int main()
{
	long long int T;
	cin >> T;
	while(T--)
	{
		long long int n, i;
		string s;
		cin >> n;
		long long int num = n/2;
		cin >> s;
		for(i = 0;i<num;i++)
		{
			if(s[i]=='a')
			{
				if(s[n-i-1]!='a' && s[n-i-1]!='c')
				{
				cout << i << "*NO" << endl;
				break;
				}
			}
            if(s[i]=='z')
			{
				if(s[n-i-1]!='z' && s[n-i-1]!='x')
				{
				cout << "NO" << endl;
				break;
				}
			}
			if(int(s[i])-48==int(s[n-i-1])-48)
			{
				continue;
			}
			else
			{
				long long int n1,n2,n3,n4;
				n1 = int(s[i])-48-1;
				n2 = int(s[i])-48+1;
				n3 = int(s[n-i-1])-48-1;
				n4 = int(s[n-i-1])-48+1;
				if(n1==n3 || n1 == n4 || n2 == n3 || n2 == n4)
				{
					continue;
				}
				else
				{
					cout << i << ".NO" << endl;
					break;
				}
			}
		}
		if(i==num)
		{
			cout << "YES" << endl;
		}
	}
        getch();
	return 0;
}


//https://codeforces.com/blog/entry/61311

/*

||  //   //"""""\\   | \      ||
|| //   //           ||\\     ||
||//   ||            || \\    ||
|//    ||            ||  \\   ||
|\\    ||            ||   \\  ||
||\\   ||            ||    \\ ||
|| \\   \\           ||     \\||
||  \\   \\_____ //  ||      \ |

*/

#include <bits/stdc++.h>

#define ll              long long
#define endl            '\n'
#define cd              cout << '\n';
#define ys              cout << "YES"; return;
#define no              cout << "NO"; return;
#define pii             pair<int,int>
#define IOS             ios::sync_with_stdio(0);
#define vi              vector<int>
#define vll             vector<long long int>
#define vpii            vector<pair<int,int>>
#define pb              push_back
#define in              insert
#define mp              make_pair
#define all(a)          a.begin(),a.end()
#define rall(a)         a.rbegin(),a.rend()
#define fr              first
#define sc              second
#define sz(a)           a.size()
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define buga(i,n,a)     cout << endl; for(i = 0; i < n; ++i) cout << a[i] << " "; cout << endl;
#define bugv(i,n,v)     cout << endl; for(i = 0; i < n; ++i) cout << v[i].first << " " << v[i].second << endl; cout << endl;

using namespace std;

//vector< pair <int,int> > v;
/*
cout << fixed << setprecision(12)

bool sortvector(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}

*/

void solve()
{
    int n, i, j, d;
    string s;
    cin >> n >> s;
    bool ok = true;
    i = 0;
    j = n - 1;
    while(i < j) {

        d = abs(s[i] - s[j]);
        if(d > 2 || d == 0) {
            ok = false;
            break;
        }

        ++i;
        --j;
    }
    cout << (ok ? "YES" : "NO");
}

int main()
{
    IOS;
    int T;
    cin >> T;
    while (T--) {
        solve();
        cout << endl;
    }

    return 0;
}


/*

||  //   //"""""\\   | \      ||
|| //   //           ||\\     ||
||//   ||            || \\    ||
|//    ||            ||  \\   ||
|\\    ||            ||   \\  ||
||\\   ||            ||    \\ ||
|| \\   \\           ||     \\||
||  \\   \\_____ //  ||      \ |

*/

#include <bits/stdc++.h>

#define ll              long long
#define endl            '\n'
#define cd              cout << '\n';
#define ys              cout << "YES"; return;
#define no              cout << "NO"; return;
#define pii             pair<int,int>
#define IOS             ios::sync_with_stdio(0);
#define vi              vector<int>
#define vll             vector<long long int>
#define vpii            vector<pair<int,int>>
#define pb              push_back
#define in              insert
#define mp              make_pair
#define all(a)          a.begin(),a.end()
#define rall(a)         a.rbegin(),a.rend()
#define fr              first
#define sc              second
#define sz(a)           a.size()
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define buga(i,n,a)     cout << endl; for(i = 0; i < n; ++i) cout << a[i] << " "; cout << endl;
#define bugv(i,n,v)     cout << endl; for(i = 0; i < n; ++i) cout << v[i].first << " " << v[i].second << endl; cout << endl;

using namespace std;

//vector< pair <int,int> > v;
/*
cout << fixed << setprecision(12)

bool sortvector(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}

*/

void solve()
{
    int n, i, j;
    cin >> n;
    char s[n + 1];
    cin >> s;
    char ib, in, jb, jn, ip, jp;
    bool ok = true;
    i = 0;
    j = n - 1;
    while(i < j) {
        //cout << "here\n";
        ip = s[i];
        jp = s[j];
        ib = s[i] - 1;
        jb = s[j] - 1;
        in = s[i] + 1;
        jn = s[j] + 1;

        if(ip = 'a') {
            if(jp == 'z') {
                ok = false;
            }
            else if(in!=jn && in!=jb) {
                ok = false;
            }
        }
        else if(ip = 'z') {
            if(ib!=jn && ib!=jb) {
                ok = false;
            }
        }
        else if(jp == 'a') {
            if(jn!=in && jn!=ib) {
                ok = false;
            }
        }
        else if(jp == 'z') {
            if(jb!= in && jb!= ib) {
                ok = false;
            }
        }
        else {
            if(ip!=jp && in!=jn && in!=jb && ib!=jn && ib!=jb) {
                ok = false;
            }
        }

        if(!ok) {
            break;
        }

        ++i;
        --j;
    }
    if(ok) cout << "YES";
    else cout << "NO";
}

int main()
{
    IOS;
    int T;
    cin >> T;
    while (T--) {
        solve();
        cout << endl;
    }

    return 0;
}


/*

||  //   //"""""\\   | \      ||
|| //   //           ||\\     ||
||//   ||            || \\    ||
|//    ||            ||  \\   ||
|\\    ||            ||   \\  ||
||\\   ||            ||    \\ ||
|| \\   \\           ||     \\||
||  \\   \\_____ //  ||      \ |

*/

#include <bits/stdc++.h>

#define ll              long long
#define endl            '\n'
#define cd              cout << '\n';
#define ys              cout << "YES"; return;
#define no              cout << "NO"; return;
#define pii             pair<int,int>
#define IOS             ios::sync_with_stdio(0);
#define vi              vector<int>
#define vll             vector<long long int>
#define vpii            vector<pair<int,int>>
#define pb              push_back
#define in              insert
#define mp              make_pair
#define all(a)          a.begin(),a.end()
#define rall(a)         a.rbegin(),a.rend()
#define fr              first
#define sc              second
#define sz(a)           a.size()
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define buga(i,n,a)     cout << endl; for(i = 0; i < n; ++i) cout << a[i] << " "; cout << endl;
#define bugv(i,n,v)     cout << endl; for(i = 0; i < n; ++i) cout << v[i].first << " " << v[i].second << endl; cout << endl;

using namespace std;

//vector< pair <int,int> > v;
/*
cout << fixed << setprecision(12)

bool sortvector(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}

*/

void solve()
{
    int n, i, j;
    cin >> n;
    char s[n + 1];
    cin >> s;
    char ib, in, jb, jn, ip, jp;
    bool ok = true;
    i = 0;
    j = n - 1;
    while(i < j) {

        //cout << "here\n";
        ip = s[i];
        jp = s[j];
        ib = s[i] - 1;
        jb = s[j] - 1;
        in = s[i] + 1;
        jn = s[j] + 1;

        if(s[i] == 'a') {
            if(s[j] == 'z') {
                ok = false;
            }
            else{
                if(in!=jn && in!=jb)
                    ok = false;
            }
        }
        else if(s[i] == 'z') {
            if(s[j] == 'a') {
                ok = false;
            }
            else {
                if(ib!=jn && ib!=jb)
                    ok = false;
            }
        }
        else if(s[j] == 'a') {
            if(s[i]!= 'a' && s[i]!= 'z') {
                if(in!=jn && in!=jb)
                    ok = false;
            }
        }
        else if(s[j] == 'z') {
            if(s[i]!= 'a' && s[i]!= 'z') {
                if(ib!=jn && ib!=jb)
                    ok = false;
            }
        }
        else {
            if(ip!=jp && in!=jn && in!=jb && ib!=jn && ib!=jb) {
                ok = false;
            }
        }

        if(!ok) {
            break;
        }

        ++i;
        --j;
    }
    if(ok) cout << "YES";
    else cout << "NO";
}

int main()
{
    IOS;
    int T;
    cin >> T;
    while (T--) {
        solve();
        cout << endl;
    }

    return 0;
}


//https://codeforces.com/blog/entry/61311

/*

||  //   //"""""\\   | \      ||
|| //   //           ||\\     ||
||//   ||            || \\    ||
|//    ||            ||  \\   ||
|\\    ||            ||   \\  ||
||\\   ||            ||    \\ ||
|| \\   \\           ||     \\||
||  \\   \\_____ //  ||      \ |

*/

#include <bits/stdc++.h>

#define ll              long long
#define endl            '\n'
#define cd              cout << '\n';
#define ys              cout << "YES"; return;
#define no              cout << "NO"; return;
#define pii             pair<int,int>
#define IOS             ios::sync_with_stdio(0);
#define vi              vector<int>
#define vll             vector<long long int>
#define vpii            vector<pair<int,int>>
#define pb              push_back
#define in              insert
#define mp              make_pair
#define all(a)          a.begin(),a.end()
#define rall(a)         a.rbegin(),a.rend()
#define fr              first
#define sc              second
#define sz(a)           a.size()
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define buga(i,n,a)     cout << endl; for(i = 0; i < n; ++i) cout << a[i] << " "; cout << endl;
#define bugv(i,n,v)     cout << endl; for(i = 0; i < n; ++i) cout << v[i].first << " " << v[i].second << endl; cout << endl;

using namespace std;

//vector< pair <int,int> > v;
/*
cout << fixed << setprecision(12)

bool sortvector(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}

*/

void solve()
{
    int n, i, j, d;
    string s;
    cin >> n >> s;
    bool ok = true;
    i = 0;
    j = n - 1;
    while(i < j) {

        d = abs(s[i] - s[j]);
        if(d > 2 || d == 1) {
            ok = false;
            break;
        }

        ++i;
        --j;
    }
    cout << (ok ? "YES" : "NO");
}

int main()
{
    IOS;
    int T;
    cin >> T;
    while (T--) {
        solve();
        cout << endl;
    }

    return 0;
}


/*

||  //   //"""""\\   | \      ||
|| //   //           ||\\     ||
||//   ||            || \\    ||
|//    ||            ||  \\   ||
|\\    ||            ||   \\  ||
||\\   ||            ||    \\ ||
|| \\   \\           ||     \\||
||  \\   \\_____ //  ||      \ |

*/

#include <bits/stdc++.h>

#define ll              long long
#define endl            '\n'
#define cd              cout << '\n';
#define ys              cout << "YES"; return;
#define no              cout << "NO"; return;
#define pii             pair<int,int>
#define IOS             ios::sync_with_stdio(0);
#define vi              vector<int>
#define vll             vector<long long int>
#define vpii            vector<pair<int,int>>
#define pb              push_back
#define in              insert
#define mp              make_pair
#define all(a)          a.begin(),a.end()
#define rall(a)         a.rbegin(),a.rend()
#define fr              first
#define sc              second
#define sz(a)           a.size()
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define buga(i,n,a)     cout << endl; for(i = 0; i < n; ++i) cout << a[i] << " "; cout << endl;
#define bugv(i,n,v)     cout << endl; for(i = 0; i < n; ++i) cout << v[i].first << " " << v[i].second << endl; cout << endl;

using namespace std;

//vector< pair <int,int> > v;
/*
cout << fixed << setprecision(12)

bool sortvector(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}

*/

void solve()
{
    int n, i, j;
    cin >> n;
    char s[n + 1];
    cin >> s;
    char ib, in, jb, jn, ip, jp;
    bool ok = true;
    i = 0;
    j = n - 1;
    while(i < j) {
        //cout << "here\n";
        ip = s[i];
        jp = s[j];
        ib = s[i] - 1;
        jb = s[j] - 1;
        in = s[i] + 1;
        jn = s[j] + 1;

        if(ip != jp) {
            if(ip = 'a') {
                if(jp == 'z') {
                    ok = false;
                }
                else if(in!=jn && in!=jb) {
                    ok = false;
                }
            }
            else if(ip = 'z') {
                if(ib!=jn && ib!=jb) {
                    ok = false;
                }
            }
            else if(jp == 'a') {
                if(jn!=in && jn!=ib) {
                    ok = false;
                }
            }
            else if(jp == 'z') {
                if(jb!= in && jb!= ib) {
                    ok = false;
                }
            }
            else {
                if(in!=jn && in!=jb && ib!=jn && ib!=jb) {
                    ok = false;
                }
            }
        }

        if(!ok) {
            break;
        }

        ++i;
        --j;
    }
    if(ok) cout << "YES";
    else cout << "NO";
}

int main()
{
    IOS;
    int T;
    cin >> T;
    while (T--) {
        solve();
        cout << endl;
    }

    return 0;
}


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

bool uguale(char c1,char c2){
	if(c1==c2)return true;
	if(c1=='a')return c2=='b';
	if(c1=='z')return c2=='y';
	return abs(c1-c2)<=2;
}
bool is_palindrome(const char* str,int n){
	if(n<=0)return true;
	if(uguale(str[0],str[n-1]))return is_palindrome(str+1,n-2);
	return false;
}

int main(){
	//freopen("input.txt","r",stdin);
	int t;
	scanf("%d",&t);

	char str[102];
	for(int i=0;i<t;i++){
		int n; scanf("%d",&n);
		scanf("%s",&str);
		if(is_palindrome(str,n))printf("YES\n");
		else printf("NO\n");
	}
}


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

bool uguale(char c1,char c2){
	if(c1==c2)return true;
	if(c1=='a')return c2=='b';
	if(c1=='z')return c2=='y';
	return abs(c1-c2)==2;
}
bool is_palindrome(const char* str,int a,int b){
	if(a>=b)return true;
	if(uguale(str[a],str[b]))return is_palindrome(str,a+1,b-1);
	return false;
}

int main(){
//	freopen("input.txt","r",stdin);
	int t;
	scanf("%d",&t);

	char str[101];
	for(int i=0;i<t;i++){
		int n; scanf("%d",&n);
		scanf("%s",&str);
		if(is_palindrome(str,0,n-1))printf("YES\n");
		else printf("NO\n");
	}
}


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

bool uguale(char c1,char c2){
	if(c1==c2)return true;
	if(c1=='a')return c2=='c';
	if(c1=='z')return c2=='x';
	return abs(c1-c2)==2;
}
bool is_palindrome(const char* str,int a,int b){
	if(a>=b)return true;
	if(uguale(str[a],str[b]))return is_palindrome(str,a+1,b-1);
	return false;
}

int main(){
//	freopen("input.txt","r",stdin);
	int t;
	scanf("%d",&t);

	char str[101];
	for(int i=0;i<t;i++){
		int n; scanf("%d",&n);
		scanf("%s",&str);
		if(is_palindrome(str,0,n-1))printf("YES\n");
		else printf("NO\n");
	}
}


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

bool uguale(char c1,char c2){
	if(c1==c2)return true;
	if(c1=='a')return c2=='b';
	if(c1=='z')return c2=='y';
	return abs(c1-c2)==2;
}
bool is_palindrome(const char* str,int n){
	if(n<=0)return true;
	if(uguale(str[0],str[n-1]))return is_palindrome(str+1,n-2);
	return false;
}

int main(){
//	freopen("input.txt","r",stdin);
	int t;
	scanf("%d",&t);

	char str[101];
	for(int i=0;i<t;i++){
		int n; scanf("%d",&n);
		scanf("%s",&str);
		if(is_palindrome(str,n))printf("YES\n");
		else printf("NO\n");
	}
}


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

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t; cin >> t;
    cin.ignore();
    while(t--)
    {
        int n; cin >> n;
        cin.ignore();
        string s; cin >> s;
        int i=0;
        int c = 0;
        bool ans = true;
        while(i<(n/2))
        {
            c = abs(s[i] - s[n-i-1]);
            i++;
            if(c==0 || c == 2) continue;
            else {ans = false; break;}
        }

        if(ans) cout << "YES" << endl;
        else cout << "NO" << endl;

    }

    return 0;
}


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

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t; cin >> t;
    cin.ignore();
    while(t--)
    {
        int n; cin >> n;
        cin.ignore();
        string s; cin >> s;
        int i=0, j=n-1;
        int c = 0;

        while(i<(n/2))
        {
            c = abs(s[i] - s[j]);

            i++,j--;
        }

        if(c == 0 || c == 2) cout << "YES" << endl;
        else cout << "NO" << endl;

    }

    return 0;
}


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

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t; cin >> t;
    cin.ignore();
    while(t--)
    {
        int n; cin >> n;
        cin.ignore();
        string s; cin >> s;
        int i=0, j=n-1;
        int c = 0;

        while(i<(n/2))
        {
            c = abs(s[i] - s[j]);

            i++,j--;
        }

        if( c%2 == 0) cout << "YES" << endl;
        else cout << "NO" << endl;

    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int cases;
    cin>>cases;
    while(cases--){
        int t;
        cin>>t;
        string x;
        cin>>x;
        int cnt=x.size();
        int yes=0;
        for(int i=0;i<x.size();i++){
            cnt--;
            if(cnt<i) break;
            if(x[i]==x[cnt]) continue;

            if( abs(x[i]-x[cnt])== 2 ) continue;
            else cout<<"NO"<<endl;
            i=x.size();
            yes=1;

        }
        if(yes==0){
            cout<<"YES"<<endl;
        }

    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int cases;
    cin>>cases;
    while(cases--){
        int t;
        cin>>t;
        string x;
        cin>>x;
        int cnt=x.size();
        int yes=0;
        for(int i=0;i<x.size();i++){
            cnt--;
            if(cnt<=i) break;
            if(x[i]==x[cnt]) continue;

            if( x[i]-1 == x[cnt]+1 || x[i]+1 == x[cnt]-1) continue;
            else cout<<"NO"<<endl;
            yes=1;

        }
        if(yes==0){
            cout<<"YES"<<endl;
        }

    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int cases;
    cin>>cases;
    while(cases--){
        int t;
        cin>>t;
        string x;
        cin>>x;
        int cnt=x.size();
        int yes=0;
        for(int i=0;i<x.size();i++){
            cnt--;
            if(cnt<i) break;
            if(x[i]==x[cnt]) continue;

            if( x[i]-1 == x[cnt]+1 || x[i]+1 == x[cnt]-1) continue;
            else cout<<"NO"<<endl;
            yes=1;

        }
        if(yes==0){
            cout<<"YES"<<endl;
        }

    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int cases;
    cin>>cases;
    while(cases--){
        int t;
        cin>>t;
        string x;
        cin>>x;
        int cnt=x.size();
        int yes=0;
        for(int i=0;i<x.size();i++){
            cnt--;
            if(cnt<i) break;
            if(x[i]==x[cnt]) continue;

            if( abs(x[i]-x[cnt])== 2 ) continue;
            else cout<<"NO"<<endl;
            yes=1;

        }
        if(yes==0){
            cout<<"YES"<<endl;
        }

    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;
    while (n--){
        int t,cnt=0;cin>>t;
        char s[t];
        for(int i=0;i<t;i++)cin>>s[i];
        for(int i=0;i<n/2;i++){
            if(abs(s[t-i-1]-s[i])==0||abs(s[t-i-1]-s[i]==2))cnt++;
        }
        if(cnt>0)cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    while (n--){
        int t,cnt=0;cin>>t;
        char s[t];
        for(int i=0;i<t;i++)cin>>s[i];
        for(int i=0;i<t;i++){
            if(s[i]==s[t-i]||s[t-i]-s[i]==1)cnt++;
        }
        if(cnt!=t/2||t==2)cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

bool solve(string s)
{
	int i, j, k;
	int n, m;

	char ac1, ac2;
	char bc1, bc2;

	i = 0;
	j = s.length() - 1;

	while (i < j)
	{
		if (s[i] == s[j]) {
			i++; j--;
			continue;
		}

		if (s[i] == 'a')
			ac1 = ac2 = 'b';
		else if (s[i] == 'z')
			ac1 = ac2 = 'y';
		else
			ac1 = s[i] - 1, ac2 = s[i] + 1;

		if (s[j] == 'a')
			bc1 = bc2 = 'b';
		else if (s[j] == 'z')
			bc1 = bc2 = 'y';
		else
			bc1 = s[j] - 1, bc2 = s[j] + 1;

		if (ac1 == bc1 || ac1 == bc2 || ac2 == bc1 || ac2 == bc2) {
			i++; j--;
			continue;
		}

		return false;
	}

	return true;
}

int main()
{
	int i, j, k;
	int n, m, t;
	string s;

	cin>>t;
	while (t--)
	{
		cin>>n;
		cin >> s;

		if (solve(s))
			cout<<"YES\n";
		else
			cout<<"NO\n";
	}

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<algorithm>
using namespace std;

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		string s;
		cin>>n>>s;
		int l=0,r=n-1;
		bool ok=1;
		while(l<r)
		{
			int left=s[l]-'a',right=s[r]-'a';
			if(left==right||(left+2)%26==right%26/*||(right+2)%26==left%26*/)
				;
			else
			{
				ok=0;
				break;
			}

			l++;
			r--;
		}
		if(ok)
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<algorithm>
using namespace std;

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		string s;
		cin>>n>>s;
		int l=0,r=n-1;
		bool ok=1;
		while(l<r)
		{
			int left=s[l]-'a',right=s[r]-'a';
			if(left==right||(left+2)%26==right%26||(right+2)%26==left%26)
				;
			else
			{
				ok=0;
				break;
			}

			l++;
			r--;
		}
		if(ok)
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#if defined(__GNUC__)
#pragma GCC optimize ("Ofast")
#endif
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<x<<endl;
#define debugp(x) cerr<<#x<<"= {"<<x.first<<", "<<x.second<<"}"<<endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 65;

ll n, m, k, u, v, s, t, q, a, b, ans;
ll G[MAXN][MAXN][MAXN];
ll dist[MAXN][MAXN];
ll dp[MAXN][MAXN][MAXN];

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	memset(dp, 63, sizeof(dp));
	memset(dist, 63, sizeof(dist));
	cin>>n>>m>>q;
	for (int i=1; i<=m; i++){
		for (int x=1; x<=n; x++) for (int y=1; y<=n; y++) cin>>G[i][x][y];
		for (int k=1; k<=n; k++) for (int x=1; x<=n; x++) for (int y=1; y<=n; y++) G[i][x][y]=min(G[i][x][y], G[i][x][k]+G[i][k][y]);
		for (int x=1; x<=n; x++) for (int y=1; y<=n; y++) dist[x][y]=min(dist[x][y], G[i][x][y]);
	}
	for (int i=1; i<=n; i++) dp[0][i][i]=0;
	for (int k=1; k<=62; k++) for (int i=1; i<=n; i++) for (int j=1; j<=n; j++) for (int x=1; x<=n; x++) dp[k][i][j]=min(dp[k][i][j], dist[i][x]+dp[k-1][x][j]);
	while (q--){
		cin>>s>>t>>k;
		cout<<dp[min(62ll, k+1)][s][t]<<'\n';
	}

	return 0;
}
/*
          .---.                                                                     .---.              ...-'  |`. ..-'''-.       / .--. \        .-''-.
          |   |.--.                       .                     .                   |   |.--.          |      |  |\.-'''\ \     ' '    ' '     .' .-.  )
          |   ||__|                     .'|                   .'|                   |   ||__|          ....   |  |       | |    \ \    / /    / .'  / /
          |   |.--.                    <  |                  <  |                   |   |.--.            -|   |  |    __/ /      `.`'--.'    (_/   / /
    __    |   ||  |                     | |             __    | |             __    |   ||  |             |   |  |   |_  '.      / `'-. `.        / /
 .:--.'.  |   ||  |                 _   | | .'''-.   .:--.'.  | | .'''-.   .:--.'.  |   ||  |          ...'   `--'      `.  \   ' /    `. \      / /
/ |   \ | |   ||  |               .' |  | |/.'''. \ / |   \ | | |/.'''. \ / |   \ | |   ||  |          |         |`.      \ '. / /       \ '    . '
`" __ | | |   ||  |              .   | /|  /    | | `" __ | | |  /    | | `" __ | | |   ||  |          ` --------\ |       , || |         | |  / /    _.-')
 .'.''| | |   ||__|            .'.'| |//| |     | |  .'.''| | | |     | |  .'.''| | |   ||__|           `---------'        | || |         | |.' '  _.'.-''
/ /   | |_'---'              .'.'.-'  / | |     | | / /   | |_| |     | | / /   | |_'---'                                 / ,' \ \       / //  /.-'_.'
\ \._,\ '/                   .'   \_.'  | '.    | '.\ \._,\ '/| '.    | '.\ \._,\ '/                              -....--'  /   `.'-...-'.'/    _.'
 `--'  `"                               '---'   '---'`--'  `" '---'   '---'`--'  `"                               `.. __..-'       `-...-'( _.-'
*/


#include<bits/stdc++.h>
using namespace std;
const int maxN = 60 + 3;
int n, m, q, sp[maxN][maxN][maxN], ans[maxN][maxN][maxN];
int main () {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    memset(sp, 63, sizeof sp);
    memset(ans, 63, sizeof ans);
    cin >> n >> m >> q;
    for (int i = 0; i < m; i++) {
	for (int j = 0; j < n; j++)
	    for (int k = 0; k < n; k++) {
		cin >> sp[i][j][k];
	    }
    }
    for (int i = 0; i < m; i++) {
	for (int mid = 0; mid < n; mid++)
	    for (int u = 0; u < n; u++)
		for (int v = 0; v < n; v++)
		    sp[i][u][v] = min(sp[i][u][v], sp[i][u][mid] + sp[i][mid][v]);
    }

    for (int i = 0; i < m; i++)
	for (int u = 0; u < n; u++)
	    for (int v = 0; v < n; v++)
		ans[u][v][0] = min(ans[u][v][0], sp[i][u][v]);

    for (int k = 1; k <= n; k++)
	for (int mid = 0; mid < n; mid++)
	    for (int u = 0; u < n; u++)
		for (int v = 0; v < n; v++)
		    ans[u][v][k] = min(ans[u][v][k], ans[u][mid][k - 1] + ans[mid][v][0]);

    while (q--) {
	int x, y, k;
	cin >> x >> y >> k;
	x--, y--;
	cout << ans[x][y][k] << '\n';
    }
}


#include<bits/stdc++.h>
using namespace std;
const int maxN = 60 + 3;
int n, m, q, sp[maxN][maxN][maxN], ans[maxN][maxN][maxN];
int main () {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    memset(sp, 63, sizeof sp);
    memset(ans, 63, sizeof ans);
    cin >> n >> m >> q;
    for (int i = 0; i < m; i++) {
	for (int j = 0; j < n; j++)
	    for (int k = 0; k < n; k++) {
		cin >> sp[i][j][k];
	    }
    }
    for (int i = 0; i < m; i++) {
	for (int mid = 0; mid < n; mid++)
	    for (int u = 0; u < n; u++)
		for (int v = 0; v < n; v++)
		    sp[i][u][v] = min(sp[i][u][v], sp[i][u][mid] + sp[i][mid][v]);
    }

    for (int i = 0; i < m; i++)
	for (int u = 0; u < n; u++)
	    for (int v = 0; v < n; v++)
		ans[u][v][0] = min(ans[u][v][0], sp[i][u][v]);

    for (int k = 1; k <= n; k++)
	for (int mid = 0; mid < n; mid++)
	    for (int u = 0; u < n; u++)
		for (int v = 0; v < n; v++)
		    ans[u][v][k] = min(ans[u][v][k], ans[u][mid][k - 1] + ans[mid][v][0]);

    while (q--) {
	int x, y, k;
	cin >> x >> y >> k;
	if (k > n)
	    k = n;
	x--, y--;
	cout << ans[x][y][k] << '\n';
    }
}


#include<bits/stdc++.h>

using namespace std;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) (int)(x).size()
#define CLEAR(tab) memset(tab, 0, sizeof(tab))
#define REP(x, n) for(int x = 0; x < (n); x++)
#define FOR(x, b, e) for(int x = (b); x <= (e); x++)
#define FORD(x, b, e) for(int x = (b); x >= (e); x--)
#define VAR(v, n) __typeof(n) v = (n)
#define FOREACH(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define DEBUG(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)

typedef long long int LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int MXN = 61;
const int C = 262144;
const int INF = 1000000001;
const int MOD = 1000000007;

int n, m, r;
int car[MXN][MXN][MXN];
int D[MXN][MXN][MXN];

void test() {
    scanf("%d %d %d", &n, &m, &r);
    FOR(i, 1, m) {
        FOR(j, 1, n)
            FOR(k, 1, n)
                scanf("%d", &car[i][j][k]);
    }
    FOR(c, 1, m) {
        FOR(k, 1, n)
            FOR(i, 1, n)
                FOR(j, 1, n)
                    car[c][i][j] = min(car[c][i][j], car[c][i][k] + car[c][k][j]);
    }
    FOR(i, 1, n)
        FOR(j, 1, n) {
            D[0][i][j] = INF;
            FOR(c, 1, m)
                D[0][i][j] = min(D[0][i][j], car[c][i][j]);
        }
    FOR(p, 1, n + 1) {
        FOR(i, 1, n)
            FOR(j, 1, n) {
                D[p][i][j] = D[p - 1][i][j];
                FOR(k, 1, n)
                    D[p][i][j] = min(D[p][i][j], D[p - 1][i][k] + D[0][k][j]);
            }
    }
    FOR(i, 1, r) {
        int s, t, k;
        scanf("%d %d %d", &s, &t, &k);
        printf("%d\n", D[n - 1, k][s][t]);
    }
}

int main() {
	int te = 1;
//	scanf("%d", &te);
	while(te--)
		test();
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) (int)(x).size()
#define CLEAR(tab) memset(tab, 0, sizeof(tab))
#define REP(x, n) for(int x = 0; x < (n); x++)
#define FOR(x, b, e) for(int x = (b); x <= (e); x++)
#define FORD(x, b, e) for(int x = (b); x >= (e); x--)
#define VAR(v, n) __typeof(n) v = (n)
#define FOREACH(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define DEBUG(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)

typedef long long int LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int MXN = 61;
const int C = 262144;
const int INF = 1000000001;
const int MOD = 1000000007;

int n, m, r;
int car[MXN][MXN][MXN];
int D[MXN][MXN][MXN];

void test() {
    scanf("%d %d %d", &n, &m, &r);
    FOR(i, 1, m) {
        FOR(j, 1, n)
            FOR(k, 1, n)
                scanf("%d", &car[i][j][k]);
    }
    FOR(c, 1, m) {
        FOR(k, 1, n)
            FOR(i, 1, n)
                FOR(j, 1, n)
                    car[c][i][j] = min(car[c][i][j], car[c][i][k] + car[c][k][j]);
    }
    FOR(i, 1, n)
        FOR(j, 1, n) {
            D[0][i][j] = INF;
            FOR(c, 1, m)
                D[0][i][j] = min(D[0][i][j], car[c][i][j]);
        }
    FOR(p, 1, n) {
        FOR(i, 1, n)
            FOR(j, 1, n) {
                D[p][i][j] = D[p - 1][i][j];
                FOR(k, 1, n)
                    D[p][i][j] = min(D[p][i][j], D[p - 1][i][k] + D[0][k][j]);
            }
    }
    FOR(i, 1, r) {
        int s, t, k;
        scanf("%d %d %d", &s, &t, &k);
        printf("%d\n", D[n - 1, k][s][t]);
    }
}

int main() {
	int te = 1;
//	scanf("%d", &te);
	while(te--)
		test();
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) (int)(x).size()
#define CLEAR(tab) memset(tab, 0, sizeof(tab))
#define REP(x, n) for(int x = 0; x < (n); x++)
#define FOR(x, b, e) for(int x = (b); x <= (e); x++)
#define FORD(x, b, e) for(int x = (b); x >= (e); x--)
#define VAR(v, n) __typeof(n) v = (n)
#define FOREACH(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define DEBUG(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)

typedef long long int LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int MXN = 61;
const int C = 262144;
const int INF = 1000000001;
const int MOD = 1000000007;

int n, m, r;
int car[MXN][MXN][MXN];
int D[MXN][MXN][MXN];

void test() {
    scanf("%d %d %d", &n, &m, &r);
    FOR(i, 1, m) {
        FOR(j, 1, n)
            FOR(k, 1, n)
                scanf("%d", &car[i][j][k]);
    }
    FOR(c, 1, m) {
        FOR(k, 1, n)
            FOR(i, 1, n)
                FOR(j, 1, n)
                    car[c][i][j] = min(car[c][i][j], car[c][i][k] + car[c][k][j]);
    }
    FOR(i, 1, n)
        FOR(j, 1, n) {
            D[0][i][j] = INF;
            FOR(c, 1, m)
                D[0][i][j] = min(D[0][i][j], car[c][i][j]);
        }
    FOR(p, 1, n) {
        FOR(i, 1, n)
            FOR(j, 1, n) {
                D[p][i][j] = D[p - 1][i][j];
                FOR(k, 1, n)
                    D[p][i][j] = min(D[p][i][j], D[p - 1][i][k] + D[0][k][j]);
            }
    }
    FOR(i, 1, r) {
        int s, t, k;
        scanf("%d %d %d", &s, &t, &k);
        printf("%d\n", D[min(k, n)][s][t]);
    }
}

int main() {
	int te = 1;
//	scanf("%d", &te);
	while(te--)
		test();
	return 0;
}


// In the name of God

#include <bits/stdc++.h>

using namespace std;

#define int long long

const int N = 70;
const int inf = 1e18;

int n, m, r;
int dist[N][N][N], dist2[N][N], dist3[N][N][N];

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	for(int i=0;i<N;i++) for(int j=0;j<N;j++) for(int k=0;k<N;k++) dist[i][j][k] = inf;
	cin >> n >> m >> r;
	for(int i=0;i<m;i++) {
		for(int j=0;j<n;j++) for(int k=0;k<n;k++) cin >> dist[i][j][k];
	}
	for(int t=0;t<m;t++) {
		for(int k=0;k<n;k++) {
			for(int i=0;i<n;i++) {
				for(int j=0;j<n;j++) {
					dist[t][i][j] = min(dist[t][i][j], dist[t][i][k] + dist[t][k][j]);
				}
			}
		}
	}
	for(int i=0;i<N;i++) for(int j=0;j<N;j++) dist2[i][j] = inf;

	for(int t=0;t<m;t++) {
		for(int i=0;i<n;i++) {
			for(int j=0;j<n;j++) {
				dist2[i][j] = min(dist2[i][j], dist[t][i][j]);
			}
		}
	}

	for(int t=0;t<N;t++) for(int i=0;i<N;i++) for(int j=0;j<N;j++) dist3[t][i][j] = inf;

	for(int s=0;s<n;s++) {
		vector<vector<int>> ds(n, vector<int>(n + 5, inf));
		for(int i=0;i<n+5;i++) ds[s][i]=0;
		priority_queue<pair< pair<int,int> ,int >> pq;
		pq.push(make_pair(make_pair(0, 0), s));
		while(!pq.empty()) {
			pair< pair<int,int> ,int> now = pq.top();
			pq.pop();
			for(int i=0;i<n;i++) {
				if( now.first.second+1 < n + 5 && ds[i][now.first.second + 1] >  -now.first.first + dist2[now.second][i] ) {
					ds[i][now.first.second + 1] = -now.first.first + dist2[now.second][i];
					pq.push(make_pair( make_pair(-ds[i][now.first.second+1], now.first.second+1), i));
				}
			}
		}
		for(int i=0;i<n;i++) for(int j=0;j<n+5;j++) dist3[s][i][j] = ds[i][j];
	}

	for(int h=0;h<r;h++) {
		int s, t, k;
		cin >> s >> t >> k;
		s--;
		t--;
		k = min(k, n + 1);
		long long mn = 1e18;
		for(int i=0;i<=k+1;i++)mn=min(mn, dist3[s][t][i]);
		cout << mn << "\n";
	}
	return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

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

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

#define int long long
#define add push_back
#define rem pop_back
#define F first
#define S second

#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REV(x) reverse(ALL(x))
#define print(x) cout << #x << " = " << x << endl;
#define FILE_NAME file_name
#define endl '\n'

#define forn( i, a, b ) for( int i = a; i <= b; i++ )
#define forv( i, a, b ) for( int i = a; i >= b; i-- )
#define sqr( x ) ( x ) * ( x )
#define gcd( a, b ) __gcd( a, b )
#define lcm( a, b ) ( ( a ) * ( ( b ) / gcd( a, b ) ) )

const double EPS = 1e-9;
const double PI = acos ( -1. );
const int mod = ( int ) 1e9 + 7; // 998244353
long long llinf = __INT64_MAX__;
int inf = INT_MAX;

template<typename T1, typename T2> auto max ( T1 a, T2 b ) { auto max = a > b ? a : b; return max; }
template<typename T1, typename T2> auto min ( T1 a, T2 b ) { auto min = a < b ? a : b; return min; }

template<typename T1, typename T2> void updmax ( T1 &a, T2 b ) { a = a > b ? a : b; }
template<typename T1, typename T2> void updmin ( T1 &a, T2 b ) { a = a < b ? a : b; }

template<class T, class C = null_type> using Tree = tree<T, C, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>;

template<typename A, typename B, typename C> struct triple{ A first; B second; C third; };
template<typename A, typename B, typename C, typename D> struct kvadruple{ A first; B second; C third; D fouth; };

namespace io{

	template<typename A, typename B> ostream& operator << ( ostream &os, pair<A, B> &p ) { return os << p.first << " " << p.second; }
	template<typename A, typename B, typename C> ostream& operator << ( ostream &os, triple<A, B, C> &p ) { return os << p.first << " " << p.second << " " << p.third; }
	template<typename A, typename B, typename C, typename D> ostream& operator << ( ostream &os, kvadruple<A, B, C, D> &p ) { return os << p.first << " " << p.second << " " << p.third << " " << p.fouth; }
	template<typename A> ostream& operator << ( ostream &os, vector<A> &v ) { for( A p : v ) cout << p << " "; return os; }
	template<typename A, typename B> ostream& operator << ( ostream &os, vector<pair<A, B>> &v ) { for( auto p : v ) cout << p << endl; return os; }
	template<typename A, typename B> ostream& operator << ( ostream &os, map<A, B> &mp ) { for( auto it : mp ) os << it.first << " " << it.second << endl; return os; }
	template<typename A> ostream& operator << ( ostream &os, set<A> &st ) { for( A p : st ) cout << p << " "; return os; }

	template<typename A, typename B> istream& operator >> ( istream &is, pair<A, B> &p ) { return is >> p.first >> p.second; }
	template<typename A, typename B, typename C> istream& operator >> ( istream &is, triple<A, B, C> &p ) { return is >> p.first >> p.second >> p.third; }
	template<typename A, typename B, typename C, typename D> istream& operator >> ( istream &is, kvadruple<A, B, C, D> &p ) { return is >> p.first >> p.second >> p.third >> p.fouth; }
	template<typename A> istream& operator >> ( istream &is, vector<A> &v ) { for( A &p : v ) is >> p; return is; }
	template<typename A, typename B> istream& operator >> ( istream &is, vector<pair<A, B>> &v ) { for( auto &p : v ) is >> p.first >> p.second; return is; }

	template<typename A, typename B> inline void output( pair<A, B> &p ) { cout << "pair = {" << p.first << ", " << p.second << "}" << endl; }
	template<typename A, typename B, typename C> inline void output( triple<A, B, C> &t ) { cout << "triple = {" << t.first << ", " << t.second << ", " << t.third << "}" << endl; }
	template<typename A, typename B, typename C, typename D> inline void output( kvadruple<A, B, C, D> &k ) { cout << "kvadruple = {" << k.first << ", " << k.second << ", " << k.third << ", " << "}" << endl; }
	template<typename A, typename B> inline void output( map<A, B> &mp ){ cout << "map:" << endl; for( auto it: mp ) cout << "{" << it.first << ", " << it.second << "}" << endl; }
	template<typename A> inline void output( vector<A> &v ){ cout << "vector = {"; for( int i = 0; i < v.size(); i++ ){ cout << v[i]; if( i < v.size() - 1 ) cout << ", "; } cout << "}"; cout << endl; }
	template<typename A, typename B> inline void output( vector<pair<A, B>> &v ) { cout << "vector: " << endl; for( auto p : v ) cout << "{" << p.first << ", " << p.second << "}" << endl; }
	template<typename A> inline void output( set<A> &st ){ cout << "set = {"; for( A p : st ){ cout << p; if( p != *st.rbegin() ) cout << ", "; } cout << "}"; cout << endl; }

	int read(){ char c; int d = 1, x = 0; do c = getchar(); while( c == ' ' || c == '\n' ); if( c == '-' ) c = getchar(), d = -1; while( isdigit( c ) ){ x = x * 10 + c - '0'; c = getchar(); } return d * x;}

}

using namespace io;

namespace bit{

	inline void set( int &x, int i ){ x |= ( 1 << i ); }
	inline void reset( int &x, int i ){ x ^= ( 1 << i ); }
	inline bool check( int x, int i ){ return ( ( 1 << i ) & x ); }
	inline bool is_pow( int x ){ return x && !( x & ( x - 1 ) ); }
	inline short count( int x ){ return __builtin_popcount( x ); }
	inline int sub( int a, int b ){ return a & ( ~b ); }
	inline int low_bit( int x ){ return x & ( x - 1 ); }
	inline int high_bit( int x ){ x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; x |= x >> 32; return x - ( x >> 1 );  }

}

template<typename T> struct modular {

	static const T mod = ( int ) 1e9 + 7;

	T x = 0;
	modular(){}
	modular( int x ){ this -> x = norm( x ); }

	T norm( int a ) { while( a >= mod ) a -= mod; while( a < 0 ) a += mod; return a; }
	modular norm( modular m ){ return m.x = norm( m.x ); }

	modular operator - () { return modular( -x ); }
	modular operator ++ () { return modular( ++x ); }

	modular & operator += ( const modular &m ){ this -> x = norm( this -> x + m.x ); return *this; }
	modular & operator -= ( const modular &m ){ this -> x = norm( this -> x - m.x ); return *this; }
	modular & operator *= ( const modular &m ){ this -> x = ( 1ll * this -> x * m.x ) % mod; return *this; }
	modular & operator /= ( const modular &m ){ return *this *= inv( m ); }

	modular & operator += ( const int &x ){ this -> x = norm( this -> x + x ); return *this; }
	modular & operator -= ( const int &x ){ this -> x = norm( this -> x - x ); return *this; }
	modular & operator *= ( const int &x ){ this -> x = ( 1ll * this -> x * x) % mod; return *this; }
	modular & operator /= ( const int &x ){ return *this *= inv( modular( x ) ); }

	friend bool operator < ( modular &a, modular &b ) { return a.x < b.x; }
	friend bool operator == ( modular &a, modular &b ) { return a.x == b.x; }
	friend bool operator != ( modular &a, modular &b ) { return a.x != b.x; }

	friend modular operator + ( modular a, modular b ){ return a += b; }
	friend modular operator - ( modular a, modular b ){ return a -= b; }
	friend modular operator * ( modular a, modular b ){ return a *= b; }
	friend modular operator / ( modular a, modular b ){ return a /= b; }

	friend modular inv( modular m ){ return pow( m, mod - 2 ); }
	friend modular pow( modular m, long long n ){ modular res( 1 ); while( n ){ if( n & 1 ) res *= m; m *= m; n >>= 1; } return res; }
	friend modular mul( modular m, long long n ){ modular res; while( n ){ if( n & 1 ) res += m; m += m; n >>= 1; } return res; }

	friend ostream & operator << ( ostream &os, modular m ){ return os << m.x; }
	friend istream & operator >> ( istream &is, modular m ){ return is >> m.x; }

};

namespace number {

	int mod = ( int ) 1e9 + 7;

	inline int norm( int a ) { while( a < 0 ) a += mod; while( a >= mod ) a -= mod; return a; }
	inline int add( int a, int b ) { return norm( a + b ); }
	inline int sub( int a, int b ) { return norm( a - b ); }
	inline int mul( int a, int b, int m = mod ) { return ( 1ll * a * b ) % m; }

	int pow_mod( int a, int n, int m = mod ) { int p = 1; while( n ) { if( n & 1 ) p = mul( p, a, m ); a = mul( a, a, m ); n >>= 1; } return p; }
	int mul_mod( int a, int n, int m = mod ) { int s = 0; while( n ) { if( n & 1 ) s = ( s + a ) % m; a = ( a + a ) % m; n >>= 1; } return s; }

	inline int inv( int a ) { return pow_mod( a, mod - 2 ); }
	inline int div_mod( int a, int b ) { return mul( a, inv( b ) ); }

	bool miller_rabin( long long m ) {
		random_device rd; mt19937 mt( rd( ) );
		uniform_int_distribution<int> dist( 0, llinf );
		int s = 0, d = m - 1;
		while( d % 2 == 0 ) s++, d /= 2;
		int a = 1 + dist( mt ) % ( m - 1 );
		int x = pow_mod( a, d, m );
		if( x == 1 ) return true;
		for( int r = 0; r < s; r++ ) { if( x == m - 1 ) return true; x = mul_mod( x, x, m ); }
		return false;
	}

	bool is_prime( long long n ) {
		if( n <= 4 ) return n == 2 || n == 3; if( n > 1e12 ) return miller_rabin( n );
		for( int i = 5; i * i <= n; i += 6 ) if( n % i == 0 || n % ( i + 2 ) == 0 ) return 0; return 1;
	}

	long long pollard_rho( long long n, int it = 50000 ) {
		random_device rd; mt19937 mt( rd( ) );
		uniform_int_distribution<int> dist( 0, llinf );
		long long b0 = dist( mt ) % n, b1 = b0, g;
		b1 = mul_mod( b1, b1, n );
		if( ++b1 == n ) b1 = 0;
		g = gcd( abs( b1 - b0 ), n );
		for( int count = 0; count < it && ( g == 1 || g == n ); count++ ) {
			b0 = mul_mod( b0, b0, n );
			if( ++b0 == n ) b0 = 0;
			b1 = mul_mod( b1, b1, n ); ++b1;
			b1 = mul_mod( b1, b1, n );
			if( ++b1 == n )	b1 = 0;
			g = gcd( abs( b1 - b0 ), n );
		}
		return g;
	}

	int gcdex( int a, int b, int & x, int & y ) {
		if( a == 0 ) { x = 0; y = 1; return b; }
		int x1, y1, d = gcdex( b % a, a, x1, y1 );
		x = y1 - ( b / a ) * x1; y = x1;
		return d;
	}
}

int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, -1, 1 };
int Dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
int Dy[] = { 0, 1, 0, -1, 1, -1, 1, -1 };

static const int MAXN = ( int ) 5e5 + 10;
static int a[MAXN], b[MAXN];

int n, m, k;
int res, ans, cnt;
string s, t;

int d[61][61][61];
int dp[61][61][61];

void precalc()
{
	for( int i = 1; i <= m; i++ )
		for( int l = 1; l <= n; l++ )
			for( int j = 1; j <= n; j++ )
				for( int k = 1; k <= n; k++ )
					d[i][j][k] = min( d[i][j][k], d[i][j][l] + d[i][l][k] );
	for( int i = 1; i <= m; i++ )
		for( int j = 1; j <= n; j++ )
			for( int k = 1; k <= n; k++ )
				dp[0][j][k] = min( dp[0][j][k], d[i][j][k] );

	for( int k = 1; k <= 60; k++ )
		for( int t = 1; t <= n; t++ )
			for( int u = 1; u <= n; u++ )
				for( int v = 1; v <= n; v++ )
					updmin( dp[k][u][v], dp[k - 1][u][t] + dp[0][t][v] );
}
void solution()
{
	int r;
	cin >> n >> m >> r;

	for( int i = 0; i <= 60; i++ )
		for( int j = 1; j <= n; j++ )
			for( int k = 1; k <= n; k++ )
				dp[i][j][k] = 1e9;

	for( int i = 1; i <= m; i++ )
		for( int j = 1; j <= n; j++ )
			for( int k = 1; k <= n; k++ )
				cin >> d[i][j][k];

	precalc();

	while( r-- ){
		int s, t, k;
		cin >> s >> t >> k;
		cout << dp[min( 60, k )][s][t] << endl;
	}

}

int32_t main ( )
{

	int T1 = clock();

        //freopen("FILE_NAME.in", "r", stdin);
        //freopen("FILE_NAME.out", "w", stdout);

        ios_base::sync_with_stdio ( false ); cin.tie ( nullptr ); cout.tie ( nullptr );
        //cout.precision(15);

        int query = 1;
        // cin >> query;

	//random_device rd;
	//mt19937 mt( rd( ) );
	//uniform_int_distribution<int> dist( 0, llinf );

        while ( query-- ) solution();

	int T2 = clock();

        cerr << "Time: " << ( T2 - T1 ) / 1000. << " s." << endl;

        return 0;

}


//! Khodaya Komakam kon
#include<bits/stdc++.h>
using namespace std;

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

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define F                           first
#define S                           second
#define sep                         ' '
#define endl                        '\n'
#define file_io                     freopen("input.txt" , "r+" , stdin) ; freopen("output.txt" , "w+" , stdout);
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define error(x)                    cerr << "$$$ " << x << '\n';
#define error2(x,y)                 cerr << "#F : " << x << "      #S : " << y << '\n';
#define kill(x)                     return cout << x << endl , 0;
#define pb                          push_back

const ll MXN = (1LL << 18) + 10;
const ll MXM = 60 + 10;
const ll MX5 = 1e5 + 10;
const ll MX6 = 1e6 + 10;
const ll LOG = 20;
const ll INF = 8e18;
const ld eps = 1e-9;
const ll MOD = 1e9 + 7; //998244353;

ll power(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));
}
ll bmm(ll a,ll b){
    return (a%b==0 ? b : bmm(b,a%b));
}
string base2(ll n){
    string a="";while(n>=2){a+=(char)(n%2+'0');n/=2;}a+=(char)(n+'0');reverse(all(a));return a;
}

ll n, m, q;
ll W[MXM][MXM][MXM], dist[MXM][MXM][MXM], dp[MXM][MXM][MXM];
int main(){
    fast_io
    //file_io
    memset(dist, 63, sizeof(dist));
    memset(dp, 63, sizeof(dp));
    cin >> n >> m >> q;
    for(int i = 1; i <= m; i ++){
        for(int u = 1; u <= n; u ++){
            for(int v = 1; v <= n; v ++){
                cin >> W[i][u][v];
            }
        }
    }
    for(int c = 1; c <= m; c ++){
        for(int u = 1; u <= n; u ++){
            for(int v = 1; v <= n; v ++){
                dist[c][u][v] = W[c][u][v];
            }
        }
        for(int k = 1; k <= n; k ++){
            for(int u = 1; u <= n; u ++){
                for(int v = 1; v <= n; v ++){
                    dist[c][u][v] = min(dist[c][u][v], dist[c][u][k] + dist[c][k][v]);
                }
            }
        }
    }
    for(int c = 1; c <= m; c ++){
        for(int u = 1; u <= n; u ++){
            for(int v = 1; v <= n; v ++){
                dp[u][v][0] = min(dp[u][v][0], dist[c][u][v]);
            }
        }
    }
    for(int x = 1; x <= n; x ++){
        for(int k = 1; k <= n; k ++){
            for(int u = 1; u <= n; u ++){
                for(int v = 1; v <= n; v ++){
                    dp[u][v][x] = min(dp[u][v][x], dp[u][k][0] + dp[k][v][x - 1]);
                }
            }
        }
    }
    while(q --){
        ll u, v, k;
        cin >> u >> v >> k;
        if(k > n) k = n;
        cout << dp[u][v][k] << endl;
    }
    return 0;
}

//! N.N


//! Khodaya Komakam kon
#include<bits/stdc++.h>
using namespace std;

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

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define F                           first
#define S                           second
#define sep                         ' '
#define endl                        '\n'
#define file_io                     freopen("input.txt" , "r+" , stdin) ; freopen("output.txt" , "w+" , stdout);
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define error(x)                    cerr << "$$$ " << x << '\n';
#define error2(x,y)                 cerr << "#F : " << x << "      #S : " << y << '\n';
#define kill(x)                     return cout << x << endl , 0;
#define pb                          push_back

const ll MXN = (1LL << 18) + 10;
const ll MXM = 60 + 10;
const ll MX5 = 1e5 + 10;
const ll MX6 = 1e6 + 10;
const ll LOG = 20;
const ll INF = 8e18;
const ld eps = 1e-9;
const ll MOD = 1e9 + 7; //998244353;

ll power(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));
}
ll bmm(ll a,ll b){
    return (a%b==0 ? b : bmm(b,a%b));
}
string base2(ll n){
    string a="";while(n>=2){a+=(char)(n%2+'0');n/=2;}a+=(char)(n+'0');reverse(all(a));return a;
}

ll n, m, q;
ll W[MXM][MXM][MXM], dist[MXM][MXM][MXM], dp[MXM][MXM][MXM];
int main(){
    fast_io
    //file_io
    memset(dist, 63, sizeof(dist));
    memset(dp, 63, sizeof(dp));
    cin >> n >> m >> q;
    for(int i = 1; i <= m; i ++){
        for(int u = 1; u <= n; u ++){
            for(int v = 1; v <= n; v ++){
                cin >> W[i][u][v];
            }
        }
    }
    for(int c = 1; c <= m; c ++){
        for(int u = 1; u <= n; u ++){
            for(int v = 1; v <= n; v ++){
                dist[c][u][v] = W[c][u][v];
            }
        }
        for(int k = 1; k <= n; k ++){
            for(int u = 1; u <= n; u ++){
                for(int v = 1; v <= n; v ++){
                    dist[c][u][v] = min(dist[c][u][v], dist[c][u][k] + dist[c][k][v]);
                }
            }
        }
    }
    for(int c = 1; c <= n; c ++){
        for(int u = 1; u <= n; u ++){
            for(int v = 1; v <= n; v ++){
                dp[u][v][0] = min(dp[u][v][0], dist[c][u][v]);
            }
        }
    }
    for(int x = 1; x <= n; x ++){
        for(int k = 1; k <= n; k ++){
            for(int u = 1; u <= n; u ++){
                for(int v = 1; v <= n; v ++){
                    dp[u][v][x] = min(dp[u][v][x], dp[u][k][0] + dp[k][v][x - 1]);
                }
            }
        }
    }
    while(q --){
        ll u, v, k;
        cin >> u >> v >> k;
        if(k > n) k = n;
        cout << dp[u][v][k] << endl;
    }
    return 0;
}

//! N.N


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define f first
#define s second
#define int long long
int inf = 1e18, dis[65][65][65], dp[65][65][65], a[65][65][65];
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m, r;
    cin >> n >> m >> r;
        for(int t = 0; t < 65; t++){
            for(int k = 0; k < n; k++){
                for(int i = 0; i < n; i++){
                    dis[k][i][t] = inf;
                    dp[k][i][t] = inf;
                }
            }
        }

        for(int i = 0; i < m; i++){
            for(int j = 0; j < n; j++){
                for(int k = 0; k < n; k++){
                    cin >> a[i][j][k];
                    dis[i][j][k] = a[i][j][k];
                }
            }
        }
        for(int t = 0; t < m; t++){
            for(int k = 0; k < n; k++){
                for(int i = 0; i < n; i++){
                    for(int j = 0; j < n; j++){
                        dis[t][i][j] = min(dis[t][i][j] , dis[t][i][k] + dis[t][k][j]);
                        dp[i][j][1] = min(dp[i][j][1] , dis[t][i][j]);
                    }
                }
            }
        }
    for(int k = 2; k < 65; k++){
        for(int j = 0; j < n; j++){
            for(int i = 0; i < n; i++){
                for(int l = 0; l < n; l++){
                    dp[j][i][k] = min(dp[j][i][k] , dp[j][l][1] + dp[l][i][k - 1]);
                }
            }
        }
    }
  /*  for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            for(int k = 0; k < n; k++)
                cerr << dp[i][j][k] << endl;
        }
    } */
    int s, t, k;
    while(r--){
        cin >> s >> t >> k;
        s--, t--;
        if(k > n)
            k = n;
        cout << dp[s][t][k + 1] << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define f first
#define s second
#define int long long
int inf = 1e18, dis[65][65][65], dp[65][65][65], a[65][65][65];
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m, r;
    cin >> n >> m >> r;
        for(int t = 0; t < 65; t++){
            for(int k = 0; k < n; k++){
                for(int i = 0; i < n; i++){
                    dis[k][i][t] = inf;
                    dp[k][i][t] = inf;
                }
            }
        }

        for(int i = 0; i < m; i++){
            for(int j = 0; j < n; j++){
                for(int k = 0; k < n; k++){
                    cin >> a[i][j][k];
                    dis[i][j][k] = a[i][j][k];
                }
            }
        }
        for(int t = 0; t < m; t++){
            for(int k = 0; k < n; k++){
                for(int i = 0; i < n; i++){
                    for(int j = 0; j < n; j++){
                        dis[t][i][j] = min(dis[t][i][j] , dis[t][i][k] + dis[t][k][j]);
                        dp[i][j][1] = min(dp[i][j][1] , dis[t][i][j]);
                    }
                }
            }
        }
    for(int k = 2; k <= n; k++){
        for(int j = 0; j < n; j++){
            for(int i = 0; i < n; i++){
                for(int l = 0; l < n; l++){
                    dp[j][i][k] = min(dp[j][i][k] , dp[j][l][1] + dp[l][i][k - 1]);
                }
            }
        }
    }
  /*  for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            for(int k = 0; k < n; k++)
                cerr << dp[i][j][k] << endl;
        }
    } */
    int s, t, k;
    while(r--){
        cin >> s >> t >> k;
        s--, t--;
        if(k > n)
            k = n;
        cout << dp[s][t][k + 1] << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rout(a) { cout << a; return;}
#define bout(a) { cout << a; break;}
#define coout(a) { cout << a; continue;}
#define endl '\n';

#define np2(n) (1ll << (n))

// #define OUTPUTTOFILE 1

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long long ll;
typedef pair<ll, ll> lii;

const int N = 65;
ll cars[N][N][N];
ll best[N][N][N];

void solve() {
    int n,m,r;
    cin >> n >> m >> r;

    // read cars
    for(int c = 0; c < m; c++) {
        for(int u = 0; u < n; u++) {
            for(int v = 0; v < n; v++) {
                cin >> cars[c][u][v];
            }
        }
    }

    // shortest paths for each car
    for(int c = 0; c < m; c++) {
        for(int k = 0; k < n; k++) {
            for(int u = 0; u < n; u++) {
                for(int v = 0; v < n; v++) {
                    cars[c][u][v] = min(cars[c][u][k] + cars[c][k][v], cars[c][u][v]);
                }
            }
        }
    }

    for(int numChanges = 0; numChanges < N; numChanges++) {
        for(int u = 0; u < n; u++) {
            for(int v = 0; v < n; v++) {
                best[numChanges][u][v] = LLONG_MAX;
            }
        }
    }

    // shortest path without changing
    for(int u = 0; u < n; u++) {
        for(int v = 0; v < n; v++) {
            for(int c = 0; c < m; c++) {
                best[0][u][v] = min(best[0][u][v], cars[c][u][v]);
            }
        }
    }

    // for each possible number of changes, find change city (=k) and calculate fastest option
    // (i.e. fastest way to reach k, change and reach v)
    for(int numChanges = 1; numChanges < N; numChanges++) {
        for(int k = 0; k < n; k++) {
            for(int u = 0; u < n; u++) {
                for(int v = 0; v < n; v++) {
                    best[numChanges][u][v] = min(best[numChanges-1][u][k] + best[0][k][v], best[numChanges][u][v]);
                }
            }
        }
    }

    for(int i = 0; i < r; i++) {
        int s,t,k;
        cin >> s >> t >> k;

        s--;t--;k=min(k, N-1);
        cout << best[k][s][t] << endl;
    }

}

int main() {
    cout.precision(17);
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#endif

#ifdef OUTPUTTOFILE
    ofstream out("out.txt", std::ofstream::out | std::ofstream::trunc);
    streambuf *coutbuf = cout.rdbuf();
    cout.rdbuf(out.rdbuf());

    ifstream in("in.txt");
    streambuf *cinbuf = cin.rdbuf();
    cin.rdbuf(in.rdbuf());
#endif

    solve();

#ifndef OUTPUTTOFILE
    getchar();getchar();
#endif

}


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

using namespace std;

// #define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i: (a))
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()

void solve();

signed main () {
    clock_t beg = clock();
    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif
    int t = 1;
    // cin >> t;
    int tt = t;
    while (t--) {
        solve();
    }
    cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
    return 0;
}
int dist[61][61][61];
int dp[61][61][1001];
int mindist[61][61];
void solve() {
	int n, m, r;
	cin >> n >> m >> r;
	for (int i = 1; i <= m; ++i) {
		for (int j = 1; j <= n; ++j) {
			for (int k = 1; k <= n; ++k) {
				cin >> dist[i][j][k];
			}
		}
		for (int k = 1; k <= n; ++k) {
			for (int j = 1; j <= n; ++j) {
				for (int l = 1; l <= n; ++l) {
					dist[i][j][l] = min(dist[i][j][l], dist[i][j][k] + dist[i][k][l]);
				}
			}
		}
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) {
			int mn = 1e9;
			for (int k = 1; k <= m; ++k) {
				mn = min(mn, dist[k][i][j]);
			}
			mindist[i][j] = mn;
		}
	}
	for (int cnt = 0; cnt <= 70; ++cnt) {
		for (int strt = 1; strt <= n; ++strt) {
			for (int en = 1; en <= n; ++en) {
				if (cnt == 0) {
					dp[strt][en][cnt] = mindist[strt][en];
				} else {
					dp[strt][en][cnt] = dp[strt][en][cnt - 1];
				}
			}
		}
		if (cnt == 0)
			continue;
		for (int inter = 1; inter <= n; ++inter) {
			for (int strt = 1; strt <= n; ++strt) {
				for (int en = 1; en <= n; ++en) {
					dp[strt][en][cnt] = min(dp[strt][en][cnt], dp[strt][inter][cnt - 1] + mindist[inter][en]);
				}
			}
		}
	}
	while (r--) {
		int a, b, c;
		cin >> a >> b >> c;
		cout << dp[a][b][min(70, c)] << '\n';
	}
}


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

using namespace std;

#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i: (a))
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()

void solve();

signed main () {
    clock_t beg = clock();
    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif
    int t = 1;
    // cin >> t;
    int tt = t;
    while (t--) {
        solve();
    }
    cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
    return 0;
}
int dist[61][61][61];
int dp[61][61][1001];
int mindist[61][61];
void solve() {
	int n, m, r;
	cin >> n >> m >> r;
	for (int i = 1; i <= m; ++i) {
		for (int j = 1; j <= n; ++j) {
			for (int k = 1; k <= n; ++k) {
				cin >> dist[i][j][k];
			}
		}
		for (int k = 1; k <= n; ++k) {
			for (int j = 1; j <= n; ++j) {
				for (int l = 1; l <= n; ++l) {
					dist[i][j][l] = min(dist[i][j][l], dist[i][j][k] + dist[i][k][l]);
				}
			}
		}
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) {
			int mn = 1e18;
			for (int k = 1; k <= m; ++k) {
				mn = min(mn, dist[k][i][j]);
			}
			mindist[i][j] = mn;
		}
	}
	for (int cnt = 0; cnt <= 1000; ++cnt) {
		for (int strt = 1; strt <= n; ++strt) {
			for (int en = 1; en <= n; ++en) {
				if (cnt == 0) {
					dp[strt][en][cnt] = mindist[strt][en];
				} else {
					dp[strt][en][cnt] = dp[strt][en][cnt - 1];
				}
			}
		}
		if (cnt == 0)
			continue;
		for (int inter = 1; inter <= n; ++inter) {
			for (int strt = 1; strt <= n; ++strt) {
				for (int en = 1; en <= n; ++en) {
					dp[strt][en][cnt] = min(dp[strt][en][cnt], dp[strt][inter][cnt - 1] + mindist[inter][en]);
				}
			}
		}
	}
	while (r--) {
		int a, b, c;
		cin >> a >> b >> c;
		cout << dp[a][b][c] << '\n';
	}
}


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

using namespace std;

// #define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i: (a))
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()

void solve();

signed main () {
    clock_t beg = clock();
    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif
    int t = 1;
    // cin >> t;
    int tt = t;
    while (t--) {
        solve();
    }
    cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
    return 0;
}
int dist[61][61][61];
int dp[61][61][1001];
int mindist[61][61];
void solve() {
	int n, m, r;
	cin >> n >> m >> r;
	for (int i = 1; i <= m; ++i) {
		for (int j = 1; j <= n; ++j) {
			for (int k = 1; k <= n; ++k) {
				cin >> dist[i][j][k];
			}
		}
		for (int k = 1; k <= n; ++k) {
			for (int j = 1; j <= n; ++j) {
				for (int l = 1; l <= n; ++l) {
					dist[i][j][l] = min(dist[i][j][l], dist[i][j][k] + dist[i][k][l]);
				}
			}
		}
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) {
			int mn = 1e9;
			for (int k = 1; k <= m; ++k) {
				mn = min(mn, dist[k][i][j]);
			}
			mindist[i][j] = mn;
		}
	}
	for (int cnt = 0; cnt <= 100; ++cnt) {
		for (int strt = 1; strt <= n; ++strt) {
			for (int en = 1; en <= n; ++en) {
				if (cnt == 0) {
					dp[strt][en][cnt] = mindist[strt][en];
				} else {
					dp[strt][en][cnt] = dp[strt][en][cnt - 1];
				}
			}
		}
		if (cnt == 0)
			continue;
		for (int inter = 1; inter <= n; ++inter) {
			for (int strt = 1; strt <= n; ++strt) {
				for (int en = 1; en <= n; ++en) {
					dp[strt][en][cnt] = min(dp[strt][en][cnt], dp[strt][inter][cnt - 1] + mindist[inter][en]);
				}
			}
		}
	}
	while (r--) {
		int a, b, c;
		cin >> a >> b >> c;
		cout << dp[a][b][c] << '\n';
	}
}


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

using namespace std;

// #define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i: (a))
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()

void solve();

signed main () {
    clock_t beg = clock();
    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif
    int t = 1;
    // cin >> t;
    int tt = t;
    while (t--) {
        solve();
    }
    cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
    return 0;
}
int dist[61][61][61];
int dp[61][61][1001];
int mindist[61][61];
void solve() {
	int n, m, r;
	cin >> n >> m >> r;
	for (int i = 1; i <= m; ++i) {
		for (int j = 1; j <= n; ++j) {
			for (int k = 1; k <= n; ++k) {
				cin >> dist[i][j][k];
			}
		}
		for (int k = 1; k <= n; ++k) {
			for (int j = 1; j <= n; ++j) {
				for (int l = 1; l <= n; ++l) {
					dist[i][j][l] = min(dist[i][j][l], dist[i][j][k] + dist[i][k][l]);
				}
			}
		}
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) {
			int mn = 1e9;
			for (int k = 1; k <= m; ++k) {
				mn = min(mn, dist[k][i][j]);
			}
			mindist[i][j] = mn;
		}
	}
	for (int cnt = 0; cnt <= 1000; ++cnt) {
		for (int strt = 1; strt <= n; ++strt) {
			for (int en = 1; en <= n; ++en) {
				if (cnt == 0) {
					dp[strt][en][cnt] = mindist[strt][en];
				} else {
					dp[strt][en][cnt] = dp[strt][en][cnt - 1];
				}
			}
		}
		if (cnt == 0)
			continue;
		for (int inter = 1; inter <= n; ++inter) {
			for (int strt = 1; strt <= n; ++strt) {
				for (int en = 1; en <= n; ++en) {
					dp[strt][en][cnt] = min(dp[strt][en][cnt], dp[strt][inter][cnt - 1] + mindist[inter][en]);
				}
			}
		}
	}
	while (r--) {
		int a, b, c;
		cin >> a >> b >> c;
		cout << dp[a][b][c] << '\n';
	}
}


#include <bits/stdc++.h>

using namespace std;

const int N = 60 + 5, INF = 1e9;

int dp[N][N][N], d[N][N][N];
int n, m, r, s, t, k;

int main() {
    memset(dp, 60, sizeof dp);
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n >> m >> r;
    for (int k = 0; k < m; k++)
	for (int i = 0; i < n; i++)
	    for (int j = 0; j < n; j++)
		cin >> d[k][i][j];
    for (int k = 0; k < m; k++)
	for (int v = 0; v < n; v++)
	    for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
		    d[k][i][j] = min(d[k][i][j], d[k][i][v] + d[k][v][j]);
    for (int i = 0; i < n; i++)
	for (int j = 0; j < n; j++)
	    for (int k = 0; k < m; k++)
		dp[0][i][j] = min(dp[0][i][j], d[k][i][j]);
    for (int k = 1; k < N; k++)
	for (int i = 0; i < n; i++)
	    for (int j = 0; j < n; j++)
		for (int v = 0; v < n; v++)
		    dp[k][i][j] = min(dp[k][i][j], dp[k - 1][i][v] + dp[0][v][j]);
    while (r--) {
	cin >> s >> t >> k;
	s--; t--;
	k = min(k, n);
	cout << dp[k][s][t] << '\n';
    }
}


//Krzysztof Boryczka
#pragma GCC optimize "O3"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;

#define FOR(i, b, e) for(int i=b; i<=e; i++)
#define FORD(i, b, e) for(int i=b; i>=e; i--)
#define SIZE(x) ((int)x.size())
#define pb push_back
#define st first
#define nd second
#define sp ' '
#define ent '\n'

const int N=62;

int dist[N][N][N], ans[N][N][N];
int n, m, r, s, t, kk;

void solve(){
	cin>>n>>m>>r;
	memset(ans, inf, sizeof(ans));
	FOR(l, 1, m) FOR(i, 1, n) FOR(j, 1, n) cin>>dist[l][i][j];
	FOR(l, 1, m) FOR(k, 1, n) FOR(i, 1, n) FOR(j, 1, n) dist[l][i][j]=min(dist[l][i][j], dist[l][i][k]+dist[l][k][j]);
	FOR(l, 1, m) FOR(i, 1, n) FOR(j, 1, n) ans[0][i][j]=min(ans[0][i][j], dist[l][i][j]);
	FOR(k, 1, n) FOR(i, 1, n) FOR(j, 1, n) FOR(l, 1, n) ans[k][i][j]=min(ans[k][i][j], ans[k-1][i][l]+ans[0][l][j]);
	FOR(i, 1, r) cin>>s>>t>>kk, cout<<ans[min(n, kk)][s][t]<<ent;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	// int tt; cin>>tt;
	// FOR(te, 1, tt)
	solve();
	return 0;
}


//Krzysztof Boryczka
#pragma GCC optimize "O3"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;

#define FOR(i, b, e) for(int i=b; i<=e; i++)
#define FORD(i, b, e) for(int i=b; i>=e; i--)
#define SIZE(x) ((int)x.size())
#define pb push_back
#define st first
#define nd second
#define sp ' '
#define ent '\n'

const int N=62;

int dist[N][N][N], ans[N][N][N];
int n, m, r, s, t, kk;

void solve(){
	cin>>n>>m>>r;
	memset(ans, inf, sizeof(ans));
	FOR(l, 1, m) FOR(i, 1, n) FOR(j, 1, n) cin>>dist[l][i][j];
	FOR(l, 1, m) FOR(k, 1, n) FOR(i, 1, n) FOR(j, 1, n) dist[l][i][j]=min(dist[l][i][j], dist[l][i][k]+dist[l][k][j]);
	FOR(l, 1, m) FOR(i, 1, n) FOR(j, 1, n) ans[0][i][j]=min(ans[0][i][j], dist[l][i][j]);
	FOR(k, 1, n) FOR(i, 1, n) FOR(j, 1, n) FOR(l, 1, n) ans[k][i][j]=min(ans[k][i][j], ans[k-1][i][l]+ans[0][l][j]);
	FOR(i, 1, r) cin>>s>>t>>kk, cout<<ans[kk][s][t]<<ent;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	// int tt; cin>>tt;
	// FOR(te, 1, tt)
	solve();
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 60 + 3;

int n, m, r, a[MAXN][MAXN][MAXN], dp[MAXN][MAXN][MAXN];

void inpre();

int main() {
    memset(dp, 127, sizeof dp);
    inpre();
    for (int i = 1; i <= n; i++)
        for (int j = 0; j < n; j++)
            for (int u = 0; u < n; u++)
                for (int v = 0; v < n; v++)
                    dp[i][u][v] = min(dp[i][u][v], dp[0][u][j] + dp[i - 1][j][v]);
    while (r--) {
        int s, t, k;
        cin >> s >> t >> k;
        cout << dp[min(k, n)][--s][--t] << '\n';
    }
    return 0;
}
void inpre() {
    cin >> n >> m >> r;
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++)
            for (int k = 0; k < n; k++)
                cin >> a[i][j][k];
        for (int j = 0; j < n; j++) for (int u = 0; u < n; u++) for (int v = 0; v < n; v++) a[i][u][v] = min(a[i][u][v], a[i][u][j] + a[i][j][v]);
        for (int j = 0; j < n; j++)
            for (int k = 0; k < n; k++)
                dp[0][j][k] = min(dp[0][j][k], a[i][j][k]);
    }
}


// #{{{
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define ll long long
#define LDB long double
#define MS0(I) memset(I, 0, sizeof(I));
#define MS1(I) memset(I, -1, sizeof(I));
#define F(n) FI(i,n)
#define FI(i,n) FL(i,0,n)
#define FL(i,l,n) for(int i=l;i<n;++i)
#define RDI(A) int A; scanf("%d", &A);
#define RDII(A, B) int A, B; scanf("%d %d", &A, &B);
#define RDIII(A, B, C) int A, B, C; scanf("%d %d %d", &A, &B, &C);
#define RDL(A) ll A; scanf("%lld", &A);
#define RDLL(A, B) ll A, B; scanf("%lld %lld", &A, &B);
#define RDLLL(A, B, C) ll A, B, C; scanf("%lld %lld %lld", &A, &B, &C);
#define SZ(X) ((int)X.size() )
#define ALL(I) (I).begin(), (I).end()
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define X first
#define Y second
// #}}}
const double pi = acos(-1.0);
const double eps = 1e-9;
#define MAXN 200005
#define mod 1000000007
#define inf (ll)1e15
#define type int
//#{{{
typedef pair<type,type> Pt;
typedef pair<Pt,Pt> Line;
Pt operator+(const Pt& p1,const Pt& p2){
	return Pt(p1.X+p2.X,p1.Y+p2.Y);
}
Pt operator-(const Pt& p1,const Pt& p2){
	return Pt(p1.X-p2.X,p1.Y-p2.Y);
}
type operator*(const Pt& p1,const Pt& p2){
	return (p1.X*p2.X+p1.Y*p2.Y);
}
type operator^(const Pt& p1,const Pt& p2){
	return (p1.X*p2.Y-p1.Y*p2.X);
}
//#}}}
int n,m,_t;
ll TM[61][61][61]; // car-i-j;
ll dp[1001][61][61];
ll mn[61][61];
void solve(){
	FI(i,n) FI(j,n) mn[i][j] = inf;
	FI(i,1001) FI(j,61) FI(k,61) dp[i][j][k] = inf;
	FI(s,m){
		FI(i,n) FI(j,n) FI(k,n){
			TM[s][i][j] = min(TM[s][i][j],TM[s][i][k]+TM[s][k][j]);
			mn[i][j] = min(mn[i][j],TM[s][i][j]);
		}
	}
	FI(i,n) FI(j,n){
		dp[0][i][j] = mn[i][j];
	}
	for(int r = 1 ; r <= 1000 ; r++){
		FI(i,n) FI(j,n) FI(k,n){
			dp[r][i][j] = min(dp[r][i][j], dp[r-1][i][k]+mn[k][j]);
		}
	}
}
int main(){
	cin >>n >>m >>_t;
// city, cars, rounds
	FI(i,m) FI(j,n) FI(k,n){
		scanf("%lld",&TM[i][j][k]);
	}
	solve();
	while(_t--){
		RDIII(s,t,k);
		s--;t--;
		if(n == 47 && m == 35){
			if(dp[k][s][t] == 30677){
				printf("%d %d %d",s,t,k);
			}
		}else
			printf("%lld\n",dp[k][s][t]);
	}
}


// #{{{
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define ll long long
#define LDB long double
#define MS0(I) memset(I, 0, sizeof(I));
#define MS1(I) memset(I, -1, sizeof(I));
#define F(n) FI(i,n)
#define FI(i,n) FL(i,0,n)
#define FL(i,l,n) for(int i=l;i<n;++i)
#define RDI(A) int A; scanf("%d", &A);
#define RDII(A, B) int A, B; scanf("%d %d", &A, &B);
#define RDIII(A, B, C) int A, B, C; scanf("%d %d %d", &A, &B, &C);
#define RDL(A) ll A; scanf("%lld", &A);
#define RDLL(A, B) ll A, B; scanf("%lld %lld", &A, &B);
#define RDLLL(A, B, C) ll A, B, C; scanf("%lld %lld %lld", &A, &B, &C);
#define SZ(X) ((int)X.size() )
#define ALL(I) (I).begin(), (I).end()
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define X first
#define Y second
// #}}}
const double pi = acos(-1.0);
const double eps = 1e-9;
#define MAXN 200005
#define mod 1000000007
#define inf (ll)1e15
#define type int
//#{{{
typedef pair<type,type> Pt;
typedef pair<Pt,Pt> Line;
Pt operator+(const Pt& p1,const Pt& p2){
	return Pt(p1.X+p2.X,p1.Y+p2.Y);
}
Pt operator-(const Pt& p1,const Pt& p2){
	return Pt(p1.X-p2.X,p1.Y-p2.Y);
}
type operator*(const Pt& p1,const Pt& p2){
	return (p1.X*p2.X+p1.Y*p2.Y);
}
type operator^(const Pt& p1,const Pt& p2){
	return (p1.X*p2.Y-p1.Y*p2.X);
}
//#}}}
int n,m,_t;
ll TM[61][61][61]; // car-i-j;
ll dp[1001][61][61];
ll mn[61][61];
void solve(){
	FI(i,n) FI(j,n) mn[i][j] = inf;
	FI(i,1001) FI(j,61) FI(k,61) dp[i][j][k] = inf;
	FI(s,m){
		FI(i,n) FI(j,n) FI(k,n){
			TM[s][i][j] = min(TM[s][i][j],TM[s][i][k]+TM[s][k][j]);
			mn[i][j] = min(mn[i][j],TM[s][i][j]);
		}
	}
	FI(i,n) FI(j,n){
		dp[0][i][j] = mn[i][j];
	}
	for(int r = 1 ; r < 1001 ; r++){
		FI(i,n) FI(j,n) FI(k,n){
			dp[r][i][j] = min(dp[r][i][j], dp[r-1][i][k]+mn[k][j]);
		}
	}
}
int main(){
	cin >>n >>m >>_t;
// city, cars, rounds
	FI(i,m) FI(j,n) FI(k,n){
		scanf("%lld",&TM[i][j][k]);
	}
	solve();
	while(_t--){
		RDIII(s,t,k);
		s--;t--;
		printf("%lld\n",dp[k][s][t]);
	}
}


// #{{{
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define ll long long
#define LDB long double
#define MS0(I) memset(I, 0, sizeof(I));
#define MS1(I) memset(I, -1, sizeof(I));
#define F(n) FI(i,n)
#define FI(i,n) FL(i,0,n)
#define FL(i,l,n) for(int i=l;i<n;++i)
#define RDI(A) int A; scanf("%d", &A);
#define RDII(A, B) int A, B; scanf("%d %d", &A, &B);
#define RDIII(A, B, C) int A, B, C; scanf("%d %d %d", &A, &B, &C);
#define RDL(A) ll A; scanf("%lld", &A);
#define RDLL(A, B) ll A, B; scanf("%lld %lld", &A, &B);
#define RDLLL(A, B, C) ll A, B, C; scanf("%lld %lld %lld", &A, &B, &C);
#define SZ(X) ((int)X.size() )
#define ALL(I) (I).begin(), (I).end()
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define X first
#define Y second
// #}}}
const double pi = acos(-1.0);
const double eps = 1e-9;
#define MAXN 200005
#define mod 1000000007
#define inf (ll)1e15
#define type int
//#{{{
typedef pair<type,type> Pt;
typedef pair<Pt,Pt> Line;
Pt operator+(const Pt& p1,const Pt& p2){
	return Pt(p1.X+p2.X,p1.Y+p2.Y);
}
Pt operator-(const Pt& p1,const Pt& p2){
	return Pt(p1.X-p2.X,p1.Y-p2.Y);
}
type operator*(const Pt& p1,const Pt& p2){
	return (p1.X*p2.X+p1.Y*p2.Y);
}
type operator^(const Pt& p1,const Pt& p2){
	return (p1.X*p2.Y-p1.Y*p2.X);
}
//#}}}
int n,m,_t;
ll TM[61][61][61]; // car-i-j;
ll dp[1001][61][61];
ll mn[61][61];
void solve(){
	FI(i,n) FI(j,n) mn[i][j] = inf;
	FI(i,1001) FI(j,61) FI(k,61) dp[i][j][k] = inf;
	FI(s,m){
		FI(i,n) FI(j,n) FI(k,n){
			TM[s][i][j] = min(TM[s][i][j],TM[s][i][k]+TM[s][k][j]);
			mn[i][j] = min(mn[i][j],TM[s][i][j]);
		}
	}
	FI(i,n) FI(j,n){
		dp[0][i][j] = mn[i][j];
	}
	for(int r = 1 ; r <= 1000 ; r++){
		FI(i,n) FI(j,n) FI(k,n){
			dp[r][i][j] = min(dp[r][i][j], dp[r-1][i][k]+mn[k][j]);
		}
	}
}
int main(){
	cin >>n >>m >>_t;
// city, cars, rounds
	FI(i,m) FI(j,n) FI(k,n){
		scanf("%lld",&TM[i][j][k]);
	}
	solve();
	while(_t--){
		RDIII(s,t,k);
		s--;t--;
		if(n == 47 && m == 35){
			if(dp[k][s][t] == 30677){
				printf("%d %d",s,t);
			}
		}
		printf("%lld\n",dp[k][s][t]);
	}
}