#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ll long long int
#define ld long double
#define fi first
#define se second
#define mod 1000000007
#define test long long int t; cin>>t; while(t-->0)
#define fIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define loop(n) for(long long int i=0;i<n;i++)
using namespace std;
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b)
 {
    return (a*b)/__gcd(a, b);
 }
 ll power(ll x, unsigned ll y)
 {
    ll temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
 }
 bool isPrime(ll num)
 {
    bool flag=true;
    for(ll i =2;i<=num/2;i++)
    {
       if(num%i==0)
       {
          flag=false;
          break;
       }
    }
    return flag;
}
bool isPalin(ll num)
{
    bool flag=false;
    ll digit,rev=0,n=num;
    do
     {
         digit = num % 10;
         rev = (rev * 10) + digit;
         num = num / 10;
     } while (num != 0);
     if(rev==n)
     flag=true;
     return flag;
}
ll sumofdigits(ll n)
{
    ll c=0;
    while(n>0)
    {
        c++;
        n/=10;
    }
    return c;
}
bool sortinrev(const pair<int,int>&a,const pair<int,int>&b)
{
    return (a.first > b.first);
}
int main()
{
    fIO
    ll n;
    cin>>n;
    ll a[n][n];
    ll d=1;
    ll f=1;
    for(ll i=1;i<=n;i++)
    {
        if(f==1)
        {
        for(ll j=1;j<=n;j++)
        {
            a[j][i]=d;
            d++;
        }
        }
        else
        {
            for(ll j=n;j>=1;j--)
            {

                a[j][i]=d;
                d++;
            }
        }
        f=0;
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
        {
            cout<<a[i][j]<<" ";
        }
        cout<<endl;
    }
	return 0;
}


#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ll long long int
#define ld long double
#define fi first
#define se second
#define mod 1000000007
#define test long long int t; cin>>t; while(t-->0)
#define fIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define loop(n) for(long long int i=0;i<n;i++)
using namespace std;
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
int lcm(int a, int b)
 {
    return (a*b)/__gcd(a, b);
 }
 int power(int x, unsigned int y)
 {
    int temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
 }
 bool isPrime(int num)
 {
    bool flag=true;
    for(int i =2;i<=num/2;i++)
    {
       if(num%i==0)
       {
          flag=false;
          break;
       }
    }
    return flag;
}
bool isPalin(int num)
{
    bool flag=false;
    int digit,rev=0,n=num;
    do
     {
         digit = num % 10;
         rev = (rev * 10) + digit;
         num = num / 10;
     } while (num != 0);
     if(rev==n)
     flag=true;
     return flag;
}
int sumofdigits(int n)
{
    int c=0;
    while(n>0)
    {
        c++;
        n/=10;
    }
    return c;
}
bool sortinrev(const pair<int,int>&a,const pair<int,int>&b)
{
    return (a.first > b.first);
}
int main()
{
    fIO
    int n;
    cin>>n;
    int a[n][n];
    int d=1;
    int f=1;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            a[i][j]=0;
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(f==1)
        {
        for(int j=1;j<=n;j++)
        {
            a[j][i]=d++;
        }
        }
        else
        {
            for(int j=n;j>=1;j--)
            {

                a[j][i]=d++;
            }
        }
        f=!f;
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            cout<<a[i][j]<<" ";
        }
        cout<<endl;
    }
	return 0;
}


#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ll long long int
#define ld long double
#define fi first
#define se second
#define mod 1000000007
#define test long long int t; cin>>t; while(t-->0)
#define fIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define loop(n) for(long long int i=0;i<n;i++)
using namespace std;
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b)
 {
    return (a*b)/__gcd(a, b);
 }
 ll power(ll x, unsigned ll y)
 {
    ll temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
 }
 bool isPrime(ll num)
 {
    bool flag=true;
    for(ll i =2;i<=num/2;i++)
    {
       if(num%i==0)
       {
          flag=false;
          break;
       }
    }
    return flag;
}
bool isPalin(ll num)
{
    bool flag=false;
    ll digit,rev=0,n=num;
    do
     {
         digit = num % 10;
         rev = (rev * 10) + digit;
         num = num / 10;
     } while (num != 0);
     if(rev==n)
     flag=true;
     return flag;
}
ll sumofdigits(ll n)
{
    ll c=0;
    while(n>0)
    {
        c++;
        n/=10;
    }
    return c;
}
bool sortinrev(const pair<int,int>&a,const pair<int,int>&b)
{
    return (a.first > b.first);
}
int main()
{
    fIO
    ll n;
    cin>>n;
    ll a[n][n];
    ll d=1;
    ll f=1;
    for(ll i=1;i<=n;i++)
    {
        if(f==1)
        {
        for(ll j=1;j<=n;j++)
        {
            a[j][i]=d++;
        }
        }
        else
        {
            for(ll j=n;j>=1;j--)
            {

                a[j][i]=d++;
            }
        }
        f=!f;
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
        {
            cout<<a[i][j]<<" ";
        }
        cout<<endl;
    }
	return 0;
}


#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ll long long int
#define ld long double
#define fi first
#define se second
#define mod 1000000007
#define test long long int t; cin>>t; while(t-->0)
#define fIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define loop(n) for(long long int i=0;i<n;i++)
using namespace std;
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
int lcm(int a, int b)
 {
    return (a*b)/__gcd(a, b);
 }
 int power(int x, unsigned int y)
 {
    int temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
 }
 bool isPrime(int num)
 {
    bool flag=true;
    for(int i =2;i<=num/2;i++)
    {
       if(num%i==0)
       {
          flag=false;
          break;
       }
    }
    return flag;
}
bool isPalin(int num)
{
    bool flag=false;
    int digit,rev=0,n=num;
    do
     {
         digit = num % 10;
         rev = (rev * 10) + digit;
         num = num / 10;
     } while (num != 0);
     if(rev==n)
     flag=true;
     return flag;
}
int sumofdigits(int n)
{
    int c=0;
    while(n>0)
    {
        c++;
        n/=10;
    }
    return c;
}
bool sortinrev(const pair<int,int>&a,const pair<int,int>&b)
{
    return (a.first > b.first);
}
int main()
{
    fIO
    ll n;
    cin>>n;
    ll a[n][n];
    ll d=1;
    ll f=1;
    for(ll i=0;i<n;i++)
    {
        if(f==1)
        {
        for(ll j=0;j<n;j++)
        {
            a[j][i]=d++;
        }
        }
        else
        {
            for(ll j=n-1;j>=0;j--)
            {

                a[j][i]=d++;
            }
        }
        f=!f;
    }
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<n;j++)
        {
            cout<<a[i][j]<<" ";
        }
        cout<<endl;
    }
	return 0;
}


#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ll long long int
#define ld long double
#define fi first
#define se second
#define mod 1000000007
#define test long long int t; cin>>t; while(t-->0)
#define fIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define loop(n) for(long long int i=0;i<n;i++)
using namespace std;
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b)
 {
    return (a*b)/__gcd(a, b);
 }
 ll power(ll x, unsigned ll y)
 {
    ll temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
 }
 bool isPrime(ll num)
 {
    bool flag=true;
    for(ll i =2;i<=num/2;i++)
    {
       if(num%i==0)
       {
          flag=false;
          break;
       }
    }
    return flag;
}
bool isPalin(ll num)
{
    bool flag=false;
    ll digit,rev=0,n=num;
    do
     {
         digit = num % 10;
         rev = (rev * 10) + digit;
         num = num / 10;
     } while (num != 0);
     if(rev==n)
     flag=true;
     return flag;
}
ll sumofdigits(ll n)
{
    ll c=0;
    while(n>0)
    {
        c++;
        n/=10;
    }
    return c;
}
bool sortinrev(const pair<int,int>&a,const pair<int,int>&b)
{
    return (a.first > b.first);
}
int main()
{
    fIO
    ll n;
    cin>>n;
    ll a[n][n]={0};
    ll d=1;
    ll f=1;
    for(ll i=1;i<=n;i++)
    {
        if(f==1)
        {
        for(ll j=1;j<=n;j++)
        {
            a[j][i]=d++;
        }
        }
        else
        {
            for(ll j=n;j>=1;j--)
            {

                a[j][i]=d++;
            }
        }
        f=!f;
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
        {
            cout<<a[i][j]<<" ";
        }
        cout<<endl;
    }
	return 0;
}


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

#define pii  pair<int, int>
#define vi vector<int >
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (x).size()
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal
#define endl "\n"

#define ll long long
#define ld long double

const ld EPS = 10e-9;
const int INF = 1e9 + 5;
const long long INFLL = (ll)INF * (ll)INF;
const ll MOD = 1e9 + 7;
const ld PI = 3.14159265358979323846;

struct HASH{
    size_t operator()(const pair<int,int>&x)const{
        return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
    }
};

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "[";
    for (int i = 0; i < (int)v.size(); ++i) {
        os << v[i];
        if (i != (int)v.size() - 1)
            os << ", ";
    }
    os << "]\n";
    return os;
}

template <typename T>
ostream& operator<<(ostream& os, const set<T>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it;
        if (it != *v.rbegin())
            os << ", ";
    }
    os << "}\n";
    return os;
}

template <typename T>
ostream& operator<<(ostream& os, const unordered_set<T>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it;
        os << ", ";
    }
    os << "}\n";
    return os;
}

template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it.first << " : "
           << it.second;

        if( it != *v.rbegin())
            os  << ", ";
    }

    os << "}\n";
    return os;
}

template <typename T, typename S>
ostream& operator<<(ostream& os, const unordered_map<T, S>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it.first << " : "
           << it.second;

        os  << ", ";
    }

    os << "}\n";
    return os;
}

template <typename T, typename S>
ostream& operator<<(ostream& os, const pair<T, S>& v)
{
    os << "(";
    os << v.first << ", "
       << v.second << ")";
    os << "\n";
    return os;
}

#define DEBUG

#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define debug(...)
#endif

// increase all elements by x, query min and max elements log(n)
//
struct Offset {
    set<ll> s;
    ll delta;

    ll getMinimum() {
        return (*s.begin()) + delta;
    }

    ll getMaximum() {
        return (*s.rbegin()) + delta;
    }

    void increase(ll x) {
        delta += x;
    }

    void add(ll x) {
        s.insert(x-delta);
    }

    void remove(ll x) {
        s.erase(x-delta);
    }

    bool contains(ll x) {
        return s.count(x-delta) != 0;
    }
};

// __gcd(x, y)

// idea behind binary search: there is monotonically increasing predicate and range [l, r]. Find
// x in range such that x is smallest value for which predicate holds true.
//            int lo = 1, hi = 1e9;
//            while(lo < hi)
//            {
//                ll mid = (lo+hi) / 2;
//                if(predicate(mid))
//                {
//                    hi = mid;
//                }
//                else
//                {
//                    lo = mid+1;
//                }
//            }
//            assert(lo == hi);

// OR: given monotonically decreasing predicate, find x in range such that x is largest value for
// which predicate holds true.

//int x = 0;
//for(int s = max_step; s >= 1; s /= 2)
//{
//    while(predicate(x+s)) x += s;
//}
// after this, x is the largest value for which predicate is true

// How to calculate mid element:
// floor((l+r) / 2) might overflow, use l + floor((r-l)/2)

//ll l = 0, r = s.size()-1;
//ll ans = -1;
//while(l < r)
//{
//    ll mid = l + (r-l) / 2;
//    if(P(mid)) {
//        r = mid;
//        ans = mid;
//    }
//    else
//    {
//        l = mid + 1;
//    }
//}
//
// AND
//
//ll l = 0, r = s.size()-1;
//ll ans = -1;
//while(l <= r)
//{
//    ll mid = l + (r-l) / 2;
//    if(P(mid)) {
//        r = mid-1;
//        ans = mid;
//    }
//    else
//    {
//        l = mid + 1;
//    }
//}
//
// ARE EQUIVALENT

//__builtin_popcount(ll) - returns number of set bits
//__builtin_clz(ll) - count leading zeroes
//__builtin_ctz(ll) - count trailing zeroes

// iterate over all subsets of x (x is a set formed like x = (1<<3)|(x<<6)|...
//int b = 0;
//do {
// process subset b
//} while (b=(b-x)&x);

// iterate over all subsets from 0 to 2^n-1
//for (int b = 0; b < (1<<n); b++) {
//vector<int> subset;
//for (int i = 0; i < n; i++) {
//if (b&(1<<i)) subset.push_back(i);
//}
//}

// find number of values in range [l, r] s.t. value % n == remainder:
//this means that we are looking for value = n * k + remainder in range [l, r]
// l <= n*k + remainder <= r
// l - remainder <= n*k <= r - remainder
// (l - remainder) / n <= k <= (r - remainder) / n
// don't forget to:
// ceil((l - remainder) / n) <= k <= floor((r - remainder) / n)

// OR:
// check like this:
// number of values that have remainder 0: r/n - l/n + (l%n == 0)
// number of values that have remainder 1: (r+1)/n - (l+1)/n + ((l+1)%n == 0)
// .......................... remainder 2: (r+2)/n - (l+2)/n + ((l+2)%n == 0)

#define ull unsigned long long

void solve() {
    int n;
    cin >> n;
    vector<vector<int>> ans(n, vector<int>(n));
    if(n%2) {
        int cnt = 1;
        for(int j = 0; j <= n/2; j++) {
            for(int i = 0; i < n; i++) {
                ans[(i+j)%n][j] = cnt;
                cnt++;
            }
        }
        for(int j = n/2 + 1; j < n; j++) {
            for(int i = n-1; i >= 0; i--) {
                int add = (i + n - 1 - j)% n;
                if(add < 0) {
                    add += n;
                }
                ans[add][j] = cnt;
                cnt++;
            }
        }
//        int mi = INT_MAX;
//        for(int i = 0; i < n; i++) {
//            for(int j = i+1; j < n; j++) {
//                int ab = 0, ba = 0;
//                for(int k1 = 0; k1 < n; k1++) {
//                    for(int k2 = 0; k2 < n; k2++) {
//                        if(ans[i][k1] > ans[j][k2]) {
//                            ab++;
//                        }
//                        else {
//                            ba++;
//                        }
//                    }
//                }
//                mi = min({mi, ab, ba});
//            }
//        }

//        assert(mi == n*n/2);
    }
    else {
        int cnt = 1;
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n/2; j++) {
                ans[i][j] = cnt;
                cnt++;
            }
        }
        for(int i = n-1; i >= 0; i--) {
            for(int j = n/2; j < n; j++) {
                ans[i][j] = cnt;
                cnt++;
            }
        }
    }

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }
}

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

    solve();

    return 0;
}


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

#define pii  pair<int, int>
#define vi vector<int >
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (x).size()
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal
#define endl "\n"

#define ll long long
#define ld long double

const ld EPS = 10e-9;
const int INF = 1e9 + 5;
const long long INFLL = (ll)INF * (ll)INF;
const ll MOD = 1e9 + 7;
const ld PI = 3.14159265358979323846;

struct HASH{
    size_t operator()(const pair<int,int>&x)const{
        return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
    }
};

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "[";
    for (int i = 0; i < (int)v.size(); ++i) {
        os << v[i];
        if (i != (int)v.size() - 1)
            os << ", ";
    }
    os << "]\n";
    return os;
}

template <typename T>
ostream& operator<<(ostream& os, const set<T>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it;
        if (it != *v.rbegin())
            os << ", ";
    }
    os << "}\n";
    return os;
}

template <typename T>
ostream& operator<<(ostream& os, const unordered_set<T>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it;
        os << ", ";
    }
    os << "}\n";
    return os;
}

template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it.first << " : "
           << it.second;

        if( it != *v.rbegin())
            os  << ", ";
    }

    os << "}\n";
    return os;
}

template <typename T, typename S>
ostream& operator<<(ostream& os, const unordered_map<T, S>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it.first << " : "
           << it.second;

        os  << ", ";
    }

    os << "}\n";
    return os;
}

template <typename T, typename S>
ostream& operator<<(ostream& os, const pair<T, S>& v)
{
    os << "(";
    os << v.first << ", "
       << v.second << ")";
    os << "\n";
    return os;
}

#define DEBUG

#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define debug(...)
#endif

// increase all elements by x, query min and max elements log(n)
//
struct Offset {
    set<ll> s;
    ll delta;

    ll getMinimum() {
        return (*s.begin()) + delta;
    }

    ll getMaximum() {
        return (*s.rbegin()) + delta;
    }

    void increase(ll x) {
        delta += x;
    }

    void add(ll x) {
        s.insert(x-delta);
    }

    void remove(ll x) {
        s.erase(x-delta);
    }

    bool contains(ll x) {
        return s.count(x-delta) != 0;
    }
};

// __gcd(x, y)

// idea behind binary search: there is monotonically increasing predicate and range [l, r]. Find
// x in range such that x is smallest value for which predicate holds true.
//            int lo = 1, hi = 1e9;
//            while(lo < hi)
//            {
//                ll mid = (lo+hi) / 2;
//                if(predicate(mid))
//                {
//                    hi = mid;
//                }
//                else
//                {
//                    lo = mid+1;
//                }
//            }
//            assert(lo == hi);

// OR: given monotonically decreasing predicate, find x in range such that x is largest value for
// which predicate holds true.

//int x = 0;
//for(int s = max_step; s >= 1; s /= 2)
//{
//    while(predicate(x+s)) x += s;
//}
// after this, x is the largest value for which predicate is true

// How to calculate mid element:
// floor((l+r) / 2) might overflow, use l + floor((r-l)/2)

//ll l = 0, r = s.size()-1;
//ll ans = -1;
//while(l < r)
//{
//    ll mid = l + (r-l) / 2;
//    if(P(mid)) {
//        r = mid;
//        ans = mid;
//    }
//    else
//    {
//        l = mid + 1;
//    }
//}
//
// AND
//
//ll l = 0, r = s.size()-1;
//ll ans = -1;
//while(l <= r)
//{
//    ll mid = l + (r-l) / 2;
//    if(P(mid)) {
//        r = mid-1;
//        ans = mid;
//    }
//    else
//    {
//        l = mid + 1;
//    }
//}
//
// ARE EQUIVALENT

//__builtin_popcount(ll) - returns number of set bits
//__builtin_clz(ll) - count leading zeroes
//__builtin_ctz(ll) - count trailing zeroes

// iterate over all subsets of x (x is a set formed like x = (1<<3)|(x<<6)|...
//int b = 0;
//do {
// process subset b
//} while (b=(b-x)&x);

// iterate over all subsets from 0 to 2^n-1
//for (int b = 0; b < (1<<n); b++) {
//vector<int> subset;
//for (int i = 0; i < n; i++) {
//if (b&(1<<i)) subset.push_back(i);
//}
//}

// find number of values in range [l, r] s.t. value % n == remainder:
//this means that we are looking for value = n * k + remainder in range [l, r]
// l <= n*k + remainder <= r
// l - remainder <= n*k <= r - remainder
// (l - remainder) / n <= k <= (r - remainder) / n
// don't forget to:
// ceil((l - remainder) / n) <= k <= floor((r - remainder) / n)

// OR:
// check like this:
// number of values that have remainder 0: r/n - l/n + (l%n == 0)
// number of values that have remainder 1: (r+1)/n - (l+1)/n + ((l+1)%n == 0)
// .......................... remainder 2: (r+2)/n - (l+2)/n + ((l+2)%n == 0)

#define ull unsigned long long

void solve() {
    int n;
    cin >> n;
    vector<vector<int>> ans(n, vector<int>(n));
    if(n%2) {
        int cnt = 1;
        for(int j = 0; j < n; j++) {
            for(int i = 0; i < n; i++) {
                ans[(i+j)%n][j] = cnt;
                cnt++;
            }
        }
    }
    else {
        int cnt = 1;
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n/2; j++) {
                ans[i][j] = cnt;
                cnt++;
            }
        }
        for(int i = n-1; i >= 0; i--) {
            for(int j = n/2; j < n; j++) {
                ans[i][j] = cnt;
                cnt++;
            }
        }
    }

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }
}

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

    solve();

    return 0;
}


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

#define pii  pair<int, int>
#define vi vector<int >
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (x).size()
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal
#define endl "\n"

#define ll long long
#define ld long double

const ld EPS = 10e-9;
const int INF = 1e9 + 5;
const long long INFLL = (ll)INF * (ll)INF;
const ll MOD = 1e9 + 7;
const ld PI = 3.14159265358979323846;

struct HASH{
    size_t operator()(const pair<int,int>&x)const{
        return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
    }
};

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "[";
    for (int i = 0; i < (int)v.size(); ++i) {
        os << v[i];
        if (i != (int)v.size() - 1)
            os << ", ";
    }
    os << "]\n";
    return os;
}

template <typename T>
ostream& operator<<(ostream& os, const set<T>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it;
        if (it != *v.rbegin())
            os << ", ";
    }
    os << "}\n";
    return os;
}

template <typename T>
ostream& operator<<(ostream& os, const unordered_set<T>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it;
        os << ", ";
    }
    os << "}\n";
    return os;
}

template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it.first << " : "
           << it.second;

        if( it != *v.rbegin())
            os  << ", ";
    }

    os << "}\n";
    return os;
}

template <typename T, typename S>
ostream& operator<<(ostream& os, const unordered_map<T, S>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it.first << " : "
           << it.second;

        os  << ", ";
    }

    os << "}\n";
    return os;
}

template <typename T, typename S>
ostream& operator<<(ostream& os, const pair<T, S>& v)
{
    os << "(";
    os << v.first << ", "
       << v.second << ")";
    os << "\n";
    return os;
}

#define DEBUG

#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define debug(...)
#endif

// increase all elements by x, query min and max elements log(n)
//
struct Offset {
    set<ll> s;
    ll delta;

    ll getMinimum() {
        return (*s.begin()) + delta;
    }

    ll getMaximum() {
        return (*s.rbegin()) + delta;
    }

    void increase(ll x) {
        delta += x;
    }

    void add(ll x) {
        s.insert(x-delta);
    }

    void remove(ll x) {
        s.erase(x-delta);
    }

    bool contains(ll x) {
        return s.count(x-delta) != 0;
    }
};

// __gcd(x, y)

// idea behind binary search: there is monotonically increasing predicate and range [l, r]. Find
// x in range such that x is smallest value for which predicate holds true.
//            int lo = 1, hi = 1e9;
//            while(lo < hi)
//            {
//                ll mid = (lo+hi) / 2;
//                if(predicate(mid))
//                {
//                    hi = mid;
//                }
//                else
//                {
//                    lo = mid+1;
//                }
//            }
//            assert(lo == hi);

// OR: given monotonically decreasing predicate, find x in range such that x is largest value for
// which predicate holds true.

//int x = 0;
//for(int s = max_step; s >= 1; s /= 2)
//{
//    while(predicate(x+s)) x += s;
//}
// after this, x is the largest value for which predicate is true

// How to calculate mid element:
// floor((l+r) / 2) might overflow, use l + floor((r-l)/2)

//ll l = 0, r = s.size()-1;
//ll ans = -1;
//while(l < r)
//{
//    ll mid = l + (r-l) / 2;
//    if(P(mid)) {
//        r = mid;
//        ans = mid;
//    }
//    else
//    {
//        l = mid + 1;
//    }
//}
//
// AND
//
//ll l = 0, r = s.size()-1;
//ll ans = -1;
//while(l <= r)
//{
//    ll mid = l + (r-l) / 2;
//    if(P(mid)) {
//        r = mid-1;
//        ans = mid;
//    }
//    else
//    {
//        l = mid + 1;
//    }
//}
//
// ARE EQUIVALENT

//__builtin_popcount(ll) - returns number of set bits
//__builtin_clz(ll) - count leading zeroes
//__builtin_ctz(ll) - count trailing zeroes

// iterate over all subsets of x (x is a set formed like x = (1<<3)|(x<<6)|...
//int b = 0;
//do {
// process subset b
//} while (b=(b-x)&x);

// iterate over all subsets from 0 to 2^n-1
//for (int b = 0; b < (1<<n); b++) {
//vector<int> subset;
//for (int i = 0; i < n; i++) {
//if (b&(1<<i)) subset.push_back(i);
//}
//}

// find number of values in range [l, r] s.t. value % n == remainder:
//this means that we are looking for value = n * k + remainder in range [l, r]
// l <= n*k + remainder <= r
// l - remainder <= n*k <= r - remainder
// (l - remainder) / n <= k <= (r - remainder) / n
// don't forget to:
// ceil((l - remainder) / n) <= k <= floor((r - remainder) / n)

// OR:
// check like this:
// number of values that have remainder 0: r/n - l/n + (l%n == 0)
// number of values that have remainder 1: (r+1)/n - (l+1)/n + ((l+1)%n == 0)
// .......................... remainder 2: (r+2)/n - (l+2)/n + ((l+2)%n == 0)

#define ull unsigned long long

void solve() {
    int n;
    cin >> n;
    vector<vector<int>> ans(n, vector<int>(n));
    if(n%2) {
        int cnt = 1;
        for(int j = 0; j <= n/2; j++) {
            for(int i = 0; i < n; i++) {
                ans[(i+j)%n][j] = cnt;
                cnt++;
            }
        }
        for(int j = n/2 + 1; j < n; j++) {
            for(int i = n-1; i >= 0; i--) {
                int add = (i + n - 1 - j)% n;
                if(add < 0) {
                    add += n;
                }
                ans[add][j] = cnt;
                cnt++;
            }
        }
        int mi = INT_MAX;
        for(int i = 0; i < n; i++) {
            for(int j = i+1; j < n; j++) {
                int ab = 0, ba = 0;
                for(int k1 = 0; k1 < n; k1++) {
                    for(int k2 = 0; k2 < n; k2++) {
                        if(ans[i][k1] > ans[j][k2]) {
                            ab++;
                        }
                        else {
                            ba++;
                        }
                    }
                }
                mi = min({mi, ab, ba});
            }
        }

        assert(mi == n*n/2);
    }
    else {
        int cnt = 1;
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n/2; j++) {
                ans[i][j] = cnt;
                cnt++;
            }
        }
        for(int i = n-1; i >= 0; i--) {
            for(int j = n/2; j < n; j++) {
                ans[i][j] = cnt;
                cnt++;
            }
        }
    }

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }
}

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

    solve();

    return 0;
}


#include<bits/stdc++.h>
#define pb push_back
#define y second
#define x first

using namespace std;
typedef long long INT;
typedef pair<int, int> pii;
template<typename T, typename U> inline void smin(T &a, const U &b) {if(a>b) a=b;}
template<typename T, typename U> inline void smax(T &a, const U &b) {if(a<b) a=b;}

#define NN 303

vector<int> ans[NN];

int main() {
#ifdef kong
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif

	int n; scanf("%d", &n);
	for(int i=1, nn=0; i<=n; i++) {
		if(i&1) {
			for(int j=1; j<=n; j++) ans[j].pb(++nn);
		}
		else {
			for(int j=n; j>=1; j--) ans[j].pb(++nn);
		}
	}

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


#include <bits/stdc++.h>
#define NN 100010
using namespace std;
int f[333][333];
int main() {
#ifndef ONLINE_JUDGE
  freopen("in.in", "r", stdin);
  freopen("out.out", "w", stdout);
#endif
	int n;
	cin>>n;
	int k=1;
	for(int i=1;i<=n;i++){
		if(i%2){
			for(int j=1;j<=n;j++){
				f[j][i]=k;k++;
			}
		}
		else {
			for(int j=n;j>=1;j--){
				f[j][i]=k;k++;
			}
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cout<<f[i][j]<<' ';
		}
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>

#define pb push_back
#define x first
#define y second
using namespace std;
typedef long long INT;
typedef pair<int, int> pii;
typedef vector<int> VI;
int power(int a, int b, int m, int ans=1) {
	for(; b; b>>=1, a=1LL*a*a%m) if(b&1) ans=1LL*ans*a%m;
	return ans;
}

const int NN = 333;
int ans[NN][NN];

int main() {
#ifndef	ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	int n;
	cin >> n;
	int now = 0;
	for(int i=0; i<n; i++) {
		if(i&1) for(int j=0; j<n; j++) ans[j][i] = ++now;
		else for(int j=n; j--; ) ans[j][i] = ++now;
	}
	for(int i=0; i<n; i++) {
		for(int j=0; j<n; j++) printf("%d ", ans[i][j]);
		puts("");
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long INT;

int a[400][400];

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(j&1){
				a[i][j]=n*(j-1)+i;
			}
			else{
				a[i][j]=n*j-i+1;
			}
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++)printf("%d ",a[i][j]);
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back

using namespace std;
using LL = long long;
using DO = double;
using pii = pair<int, int>;
using VI = vector<int>;

int power(int a, int b, int c, int ans=1) {
	for(; b; b>>=1, a=(LL)a*a%c) if(b&1) ans=(LL)ans*a%c;
	return ans;
}

const int NN = 333;
int ans[NN*NN];

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif

	int n;
	cin>>n;
	for(int i=1; i<=n*n; i++) ans[i]=i;
	for(int i=1; i<=n*n; i+=n+n) {
		reverse(ans+i, ans+i+n);
	}
	for(int i=1; i<=n; i++) {
		for(int j=i; j<=n*n; j+=n) printf("%d ", ans[j]);
		puts("");
	}

	return 0;
}


#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back

using namespace std;
using LL = long long;
using DO = double;
using pii = pair<int, int>;
using VI = vector<int>;

int power(int a, int b, int c, int ans=1) {
	for(; b; b>>=1, a=(LL)a*a%c) if(b&1) ans=(LL)ans*a%c;
	return ans;
}

const int NN = 1e3+10;
int g[NN][NN];

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif

	int n;
	cin>>n;
	for(int i=1; i<=n; i++) {
		for(int j=i; j<=n*n; j+=n) printf("%d ", j);
		puts("");
	}

	return 0;
}


#include<bits/stdc++.h>

#define x first
#define y second

using namespace std;

typedef long long INT;

#define NN 333

vector<int> res[NN];

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n;
	cin >> n;

	int fir = 1;
	int pos = 1;

	for(int i=1; i<=n*n; i++) {
		if(i % n == 1) {
			pos = fir;
			fir++;
		} else pos++;
		pos %= n; if(pos == 0) pos = n;
		res[pos].push_back(i);
	}

	int mn = n * n;

	for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) if(i != j) {
		int cnt = 0;
		for(auto x : res[i]) for(auto y : res[j]) {
			if(x > y) cnt++;
		}
		mn = min(mn, cnt);
	}

	cerr << mn << endl;

	for(int i=1; i<=n; i++) {
		for(auto x : res[i]) printf("%d ", x);
		puts("");
	}
	return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define mod 1000000007
#define x first
#define y second
using namespace std;
typedef long long INT;
typedef pair<int,int> pii;
int a[333][333];
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n;
	cin>>n;
	int e=0;
	for(int j=1;j<=n;j++){
		if(j%2) for(int i=1;i<=n;i++) a[i][j]=++e;
		else for(int i=n;i>=1;i--) a[i][j]=++e;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<n;j++) cout<<a[i][j]<<' ';
		cout<<a[i][n]<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#define NN 100000
using namespace std;
typedef long long INT;

const INT mod = 1e9 + 7;

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		for(int j = 0; j < n / 2; j++){
			cout<<i + j * (2 * n)<<" "<<2 * n + 1 - i + j * (2 * n)<<" ";
		}
		if(n & 1) cout<<i + (n / 2) * (2 * n);
		cout<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define x first
#define y second

using namespace std;
typedef long long INT;
typedef pair<int, int> pii;

#define NN 301
int n;
set<int> s;
vector<int> ans[NN];

int main () {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out","w",stdout);
#endif
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin>>n;
	for (int i=1; i<=n*n; i++) s.insert(i);
	int flag=1;
	for (int i=1; i<=n; i++) {
		if (flag) {
			for (int j=1; j<=n; j++) {
				ans[j].pb(*s.begin()); s.erase(s.begin());
			}
		}
		else {
			for (int j=1; j<=n; j++) {
				ans[j].pb(*--s.end()); s.erase(--s.end());
			}
		}
		flag^=1;
	}

	for (int i=1; i<=n; i++) {
		for (auto v : ans[i]) cout<<v<<" ";
		cout<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int a[333][333];
int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
//	freopen("out.out","w",stdout);
#endif

	int n,k=1,p=1,kk;
	cin>>n;
	kk=n*n;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(p++&1)a[i][j]=k++;
			else a[i][j]=kk--;
			cout<<a[i][j]<<' ';
		}
		cout<<endl;
	}

	return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define mod 1000000007
#define x first
#define y second
using namespace std;
typedef long long INT;
typedef pair<int,int> pii;
int a[333][333];
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		int d=0;
		for(int j=i;j<=n*n;j+=n) a[i][++d]=j;
	}
	int m=n/2;
	int k=n-m;
	int ans;
	if(m%2) ans=m;
	else if(k%2) ans=k;
	else ans=m-1;
	ans/=2;
	for(int i=1;i<=n/2;i++){
		swap(a[i][n-ans],a[n-i+1][n]);
	}
	for(int i=1;i<=n;i++) {
		for(int j=1;j<n;j++) cout<<a[i][j]<<' ';
		cout<<a[i][n]<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

using INT = long long;
const int mod = 1e9+7;

int power(int a, INT b, int c, int ans=1) {
	for (; b; b>>=1, a=(INT)a*a%c) if (b&1) ans=(INT)ans*a%c;
	return ans;
}

int a[333][333];
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif

	int n;
	cin>>n;
	for (int i=1; i<=n; i++) {
		for (int j=1; j<=n; j++) {
			int t=i+j-1;
			if (t>n) t-=n;
			a[t][i]=(i-1)*n+j;
		}
	}
	for (int i=1; i<=n; i++, puts("")) for (int j=1; j<=n; j++) printf("%d ", a[i][j]);

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int a[333][333];
int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
//	freopen("out.out","w",stdout);
#endif

	int n,k=1;
	cin>>n;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			a[i][j]=k++;
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cout<<a[j][i]<<' ';
		}
		cout<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define mod 1000000007
#define x first
#define y second
using namespace std;
typedef long long INT;
typedef pair<int,int> pii;
int a[333][333];
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		int d=0;
		for(int j=i;j<=n*n;j+=n) a[i][++d]=j;
	}
	int m=n/2;
	int k=n-m;
	int ans;
	if(m%2) ans=m;
	else if(k%2) ans=k;
	else ans=m-1;
	ans/=2;
	for(int i=1;i<=n/2;i++){
		swap(a[i][n-ans-i+1],a[n-i+1][n-i+1]);
	}
	for(int i=1;i<=n;i++) {
		for(int j=1;j<n;j++) cout<<a[i][j]<<' ';
		cout<<a[i][n]<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>

#define x first
#define y second

using namespace std;

typedef long long INT;

#define NN 333

vector<int> res[NN];

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n;
	cin >> n;

	int fir = 1;
	int pos = 1;

	for(int i=1; i<=n*n; i++) {
		if(i % n == 1) {
			pos = fir;
			fir++;
		} else pos++;
		pos %= n; if(pos == 0) pos = n;
		res[pos].push_back(i);
	}

//	int mn = n * n;
//
//	for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) if(i != j) {
//		int cnt = 0;
//		for(auto x : res[i]) for(auto y : res[j]) {
//			if(x > y) cnt++;
//		}
//		mn = min(mn, cnt);
//	}
//
//	cerr << mn << endl;

	for(int i=1; i<=n; i++) {
		for(auto x : res[i]) printf("%d ", x);
		puts("");
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int a[333][333];
int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
//	freopen("out.out","w",stdout);
#endif

	int n,k=1,p=1,kk;
	cin>>n;
	kk=n*n;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(p%4==0 or p%4==1)a[i][j]=k++;
			else a[i][j]=kk--;
			cout<<a[i][j]<<' ';
			p++;
		}
		cout<<endl;
	}

	return 0;
}


#include<bits/stdc++.h>

#define x first
#define y second

using namespace std;

typedef long long INT;

#define NN 333

vector<int> res[NN];

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n;
	cin >> n;

	for(int i=1; i<=n*n; i++) {
		int x = i % n;
		if(x == 0) x = n;
		if( ((i + n - 1) / n) % 2 == 1) res[x].push_back(i);
		else res[n-x+1].push_back(i);
	}

//	int mn = n * n;
//
//	for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) if(i != j) {
//		int cnt = 0;
//		for(auto x : res[i]) for(auto y : res[j]) {
//			if(x > y) cnt++;
//		}
//		mn = min(mn, cnt);
//	}
//
//	cerr << mn << endl;

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

	return 0;
}


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

		cout<<endl;
	}
}


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

		cout<<endl;
	}
}


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

int main()
{

	int n;
	cin>>n;
    vector<int>v[n+2];
    int f=1;
	for(int i=1;i<=n*n;)
	{

        if(f)
        for(int j=0;j<n;j++)
        {
        	v[j].push_back(i);
        	i++;
        }
        else
        {
	        for(int j=n-1;j>=0;j--)
	        {
	        	v[j].push_back(i);
	        	i++;
	        }
        }
        f=!f;
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<v[i].size();j++)
			cout<<v[i][j]<<" ";
		cout<<endl;
	}
	return 0;

}


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

int main()
{

	int n;
	cin>>n;

	for(int i=1;i<=n;i++)
	{
        int j=i;
        while(j<=n*n)
        {
        	cout<<j<<" ";
            j+=n;
        }
        cout<<endl;
	}
	return 0;

}


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

int main()
{

	int n;
	cin>>n;
    vector<int>v[n+2];
	for(int i=1;i<=n*n;)
	{

        if(i%2)
        for(int j=0;j<n;j++)
        {
        	v[j].push_back(i);
        	i++;
        }
        else
        {
	        for(int j=n-1;j>=0;j--)
	        {
	        	v[j].push_back(i);
	        	i++;
	        }
        }
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<v[i].size();j++)
			cout<<v[i][j]<<" ";
		cout<<endl;
	}
	return 0;

}


# cook your dish here
T=int(input())
for _ in range(T):
    n=int(input())
    s=list(map(int,input().split()))
    odd=[]
    even=[]
    for i in range(len(s)):
        if(s[i]%2!=0):
            odd.append(i+1)
        else:
            even.append(i+1)

    count=0
    for i in range(0,len(odd)-1,2):
        if(count<n-1):
            print(odd[i],odd[i+1])
            count+=1
        else:
            break
    for i in range(0,len(even)-1,2):
        if(count<n-1):
            print(even[i],even[i+1])
            count+=1
        else:
            break


t=int(input())
for T in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    b=[]
    for i in range(2*n):
        if(i not in b):
            b.append(i)
            for j in range(i+1,2*n):
                if((a[i]+a[j])%2==0):
                    if(j not in b):
                        b.append(j)
                        break
    for i in range(0,2*n-2,2):
        print(int(b[i])+1,int(b[i+1])+1)


t=int(input())
for T in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    b=[]
    for i in range(2*n):
        for j in range(i+1,2*n):
            if((a[i]+a[j])%2==0 and i not in b and j not in b):
                b.append(i)
                b.append(j)
                break
    for i in range(0,2*n-2,2):
        print(int(b[i])+1,int(b[i+1])+1)


t=int(input())
for T in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    b=[]
    for i in range(2*n):
        for j in range(i+1,2*n):
            if((a[i]+a[j])%2==0):
                if(i not in b and j not in b):
                    b.append(i)
                    b.append(j)
                    break
    print(b)
    for i in range(0,2*n-2,2):
        print(int(b[i])+1,int(b[i+1])+1)


t=int(input())
for T in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    b=[]
    for i in range(2*n):
        if i not in b:
            for j in range(i+1,2*n):
                if((a[i]+a[j])%2==0 and j not in b):
                    b.append(i)
                    b.append(j)
                    break
    for i in range(0,2*n-2,2):
        print(int(b[i])+1,int(b[i+1])+1)


t=int(input())
for T in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    b=[]
    for i in range(2*n):
        for j in range(i+1,2*n):
            if((a[i]+a[j])%2==0):
                if(i not in b and j not in b):
                    b.append(i)
                    b.append(j)
                    break
    for i in range(0,2*n-2,2):
        print(int(b[i])+1,int(b[i+1])+1)


t = int(input())
for _ in range(t):
    n = int(input())
    arr = list(map(int,input().split()))
    odd,even = [],[]
    for i in range(2*n):
        if arr[i]%2 == 0:
            even.append(i)
        else:
            odd.append(i)
    ans = []
    count = 0
    while(count!=(n-1)):
        if len(odd)>=2:
            ans.append([odd.pop(),odd.pop()])
            count += 1
        elif(len(even)>=2):
            ans.append([even.pop(),even.pop()])
            count += 1
    for u,v in ans:
        print(u,v)


t = int(input())
for _ in range(t):
    n = int(input())
    arr = list(map(int,input().split()))
    odd,even = [],[]
    for i in range(2*n):
        if arr[i]%2 == 0:
            even.append(i+1)
        else:
            odd.append(i+1)
    ans = []
    count = 0
    while(count!=(n-1)):
        if len(odd)>=2:
            ans.append([odd.pop(),odd.pop()])
            count += 1
        elif(len(even)>=2):
            ans.append([even.pop(),even.pop()])
            count += 1
    for u,v in ans:
        print(u,v)


t = int(input())
for _ in range(t):
    n = int(input())
    arr = list(map(int,input().split()))
    odd,even = [],[]
    for i in range(2*n):
        if arr[i]%2 == 0:
            even.append(i)
        else:
            odd.append(i)
    print(odd,even)
    ans = []
    count = 0
    while(count!=(n-1)):
        print(count,odd,even)
        if len(odd)>=2:
            ans.append([odd.pop(),odd.pop()])
            count += 1
        elif(len(even)>=2):
            ans.append([even.pop(),even.pop()])
            count += 1
    for u,v in ans:
        print(u,v)


t = int(input())
for _ in range(t):
    n = int(input())
    arr = list(map(int,input().split()))
    odd,even = [],[]
    for i in arr:
        if i%2 == 0:
            even.append(i)
        else:
            odd.append(i)
    ans = []
    count = 0
    while(count!=(n-1)):
        if len(odd)>=2:
            ans.append([odd.pop(),odd.pop()])
            count += 1
        elif(len(even)>=2):
            ans.append([even.pop(),even.pop()])
            count += 1
    for u,v in ans:
        print(u,v)


for _ in range(int(input())):
    input()
    a = list(enumerate(map(int, input().split()),1))
    odds = list(filter(lambda val: val[1]%2!=0, a))
    evens = list(filter(lambda val: val[1]%2==0, a))
    i = list(list(zip(*odds))[0]) if len(odds) > 0 else []
    j = list(list(zip(*evens))[0]) if len(evens) > 0 else []
    if len(i)%2==1:
        i.pop(), j.pop()
    elif len(j) > len(i):
        j.pop(), j.pop()
    else:
        i.pop(), i.pop()
    x = i+j
    while x != []:
        print(x.pop(), x.pop())


for _ in range(int(input())):
    input()
    a = list(enumerate(map(int, input().split()),1))
    odds = list(filter(lambda val: val[1]%2!=0, a))
    evens = list(filter(lambda val: val[1]%2==0, a))
    i = list(list(zip(*odds))[0]) if len(odds) > 0 else []
    j = list(list(zip(*evens))[0]) if len(evens) > 0 else []
    if len(i)%2==1:
        i.pop()
        j.pop()
    elif len(j) > len(i):
        j.pop()
        j.pop()
    else:
        i.pop()
        i.pop()
    x = i+j
    while x != []:
        print(x.pop(), x.pop())


for _ in range(int(input())):
    input()
    a = list(enumerate(map(int, input().split()),1))
    i = list(list(zip(*filter(lambda x: x[1]%2==0, a)))[0])
    j = list(list(zip(*filter(lambda x: x[1]%2!=0, a)))[0])
    if len(i)%2==1:
        i.pop()
        j.pop()
    elif len(j) > len(i):
        j.pop()
        j.pop()
    else:
        i.pop()
        i.pop()
    x = i+j
    x1 = [l for p,l in enumerate(x) if p%2==0]
    x2 = [l for p,l in enumerate(x) if p%2!=0]
    for (i, j) in zip(x1, x2):
        print(i, j)


for _ in range(int(input())):
    input()
    a = list(enumerate(map(int, input().split()),1))
    i = list(list(zip(*filter(lambda x: x[1]%2==0, a)))[0])
    j = list(list(zip(*filter(lambda x: x[1]%2!=0, a)))[0])
    if len(i)%2==1:
        i.pop()
        j.pop()
    elif len(j) > len(i):
        j.pop()
        j.pop()
    else:
        i.pop()
        i.pop()
    x = i+j
    q = []
    for t in x:
        if len(q) == 2:
            print(' '.join(map(str, q)))
            q = [t]
        else:
            q.append(t)
    print(' '.join(map(str, q))) if len(q) == 2 else None


for _ in range(int(input())):
    input()
    a = list(enumerate(map(int, input().split()),1))
    odds = list(filter(lambda val: val[1]%2!=0, a))
    evens = list(filter(lambda val: val[1]%2==0, a))
    i = list(list(zip(*odds))[0]) if len(odds) > 0 else []
    j = list(list(zip(*evens))[0]) if len(evens) > 0 else []
    if len(i)%2==1:
        i.pop()
        j.pop()
    elif len(j) > len(i):
        j.pop()
        j.pop()
    else:
        i.pop()
        i.pop()
    x = i+j
    x1 = [l for p,l in enumerate(x) if p%2==0]
    x2 = [l for p,l in enumerate(x) if p%2!=0]
    for (i, j) in zip(x1, x2):
        print(i, j)


t=int(input())
for i in range(t):
	n=int(input())
	a=list(map(int,input().split()))
	e=[]
	o=[]
	e1=0
	o1=0
	for i in range(len(a)):
		if(a[i]%2==0):
			e1=e1+1
			e.append(i)
		else:
			o1=o1+1
			o.append(i)
	if(e1==o1):
		e.pop(0)
		o.pop(0)
		e1=e1-1
		o1=o1-1
	elif(e1>o1):
		e.pop(0)
		e.pop(0)
		e1=e1-2
	else:
		o.pop(0)
		o.pop(0)
		o1=o1-2
	if(e1>=2):
		for j in range(0,o1,2):
			print(o[j]+1,o[j+1]+1)
		for j in range(0,e1,2):
			print(e[j]+1,e[j+1]+1)
	else:
		print(o[0]+1,e[0]+1)


#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase
from math import sqrt, floor, factorial, gcd, log
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations
from math import gcd
from bisect import bisect

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

# region fastio

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")
read = lambda: list(map(int, input().strip().split(" ")))

def solution():
    for i in range(int(input())):
        n=int(input())
        ar=list(map(int, input().split()))
        even=[]
        odd=[]

        #APPENDING ODD AND EVEN TO LISTS
        for i in range(len(ar)):
            if(ar[i]%2!=0):
                odd.append(i+1)
            else:
                even.append(i+1)

        #check the even odd index in list

        total_even=len(even)
        total_odd=len(odd)
        total=0

        for i in range(0,total_even,2):
            if total<n-1 and i+1<total_even:
                print(even[i], even[i+1])
                tota+=1

        for i in range(0,total_odd,2):
            if total<n-1 and i+1<total_odd:
                print(odd[i], odd[i+1])
                total+=1

if __name__ == "__main__":
	solution()


#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase
from math import sqrt, floor, factorial, gcd, log
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations
from math import gcd
from bisect import bisect

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

# region fastio

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")
read = lambda: list(map(int, input().strip().split(" ")))

def solution():
    for i in range(int(input())):
        n=int(input())
        ar=list(map(int, input().split()))
        even=[]
        odd=[]

        #APPENDING ODD AND EVEN TO LISTS
        for i in range(len(ar)):
            if(ar[i]%2!=0):
                odd.append(i+1)
            else:
                even.append(i+1)

        #check the even odd index in list
        print(even,odd)

        total_even=len(even)
        total_odd=len(odd)
        total=0

        for i in range(0,total_even,2):
            if total<n-1 and i+1<total_even:
                print(even[i],even[i+1])
                total+=1

        for i in range(0,total_odd,2):
            if total<n-1 and i+1<total_odd:
                print(odd[i],odd[i+1])
                total+=1

if __name__ == "__main__":
	solution()


#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase
from math import sqrt, floor, factorial, gcd, log
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations
from math import gcd
from bisect import bisect

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

# region fastio

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")
read = lambda: list(map(int, input().strip().split(" ")))

def solution():
    for i in range(int(input())):
        n=int(input())
        ar=list(map(int, input().split()))
        even=[]
        odd=[]

        #APPENDING ODD AND EVEN TO LISTS
        for i in range(len(ar)):
            if(ar[i]%2!=0):
                odd.append(i+1)
            else:
                even.append(i+1)

        #check the even odd index in list

        total_even=len(even)
        total_odd=len(odd)
        total=0

        for i in range(0,total_even,2):
            if total<n-1 and i+1<total_even:
                print(even[i],even[i+1])
                total+=1

        for i in range(0,total_odd,2):
            if total<n-1 and i+1<total_odd:
                print(odd[i],odd[i+1])
                total+=1

if __name__ == "__main__":
	solution()


def solution():
    for i in range(int(input())):
        n=int(input())
        ar=list(map(int, input().split()))
        even=[]
        odd=[]

        #APPENDING ODD AND EVEN TO LISTS
        for i in range(len(ar)):
            if(ar[i]%2!=0):
                odd.append(i+1)
            else:
                even.append(i+1)

        #check the even odd index in list

        total_even=len(even)
        total_odd=len(odd)
        total=0

        for i in range(0,total_even,2):
            if total<n-1 and i+1<total_even:
                print(even[i], even[i+1])
                total+=1

        for i in range(0,total_odd,2):
            if total<n-1 and i+1<total_odd:
                print(odd[i], odd[i+1])
                total+=1

if __name__ == "__main__":
	solution()


t=int(input())
def result(even,odd):
    for i in range(0,len(even),2):
        print(even[i],even[i+1])
    for i in range(0,len(odd),2):
        print(odd[i],odd[i+1])
for i in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    even,odd=[],[]
    for x in range(len(l)):
        if(l[x]%2==0):
            even.append(x+1)
        else:
            odd.append(x+1)
    if(len(even)%2==0 and len(odd)%2==0):
        even=even[:-2]
        result(even,odd)
    else:
        even=even[:-1]
        odd=odd[:-1]
        result(even,odd)


t=int(input())
def result(even,odd):
    for i in range(len(even)//2):
            print(even[i],even[i+1])
    for i in range(len(odd)//2):
        print(odd[i],odd[i+1])
for i in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    even,odd=[],[]
    for x in range(len(l)):
        if(l[x]%2==0):
            even.append(x+1)
        else:
            odd.append(x+1)
    if(len(even)%2==0 and len(odd)%2==0):
        even=even[:-2]
        result(even,odd)
    else:
        even=even[:-1]
        odd=odd[:-1]
        result(even,odd)


t=int(input())
def result(even,odd):
    for i in range(0,len(even),2):
        print(even[i],even[i+1])
    for i in range(0,len(odd),2):
        print(odd[i],odd[i+1])
for i in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    even,odd=[],[]
    for x in range(len(l)):
        if(l[x]%2==0):
            even.append(x+1)
        else:
            odd.append(x+1)
    if(len(even)%2==0 and len(odd)%2==0):
        if(len(even)>2):
            even=even[:-2]
        else:
            odd=odd[:-2]
        result(even,odd)
    else:
        even=even[:-1]
        odd=odd[:-1]
        result(even,odd)


t=int(input())
def result(even,odd):
    for i in range(len(even)//2):
            print(even[i],even[i+1])
    for i in range(len(odd)//2):
        print(odd[i],odd[i+1])
for i in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    even=[x for x in l if x%2==0]
    odd=[y for y in l if y%2!=0]
    if(len(even)%2==0 and len(odd)%2==0):
        even=even[:-2]
        result(even,odd)
    else:
        even=even[:-1]
        odd=odd[:-1]
        result(even,odd)


for _ in range(int(input())):
    n=int(input())
    arr=list(int(i) for i in input().split())
    odd,even=[],[]
    for i in arr:
        if i%2==0:
            even.append(i)
        else:
            odd.append(i)

    if len(even)==len(odd):
        if len(even)%2!=0:
            even.remove(even[0])
            odd.remove(odd[0])
        elif len(even)%2==0:
            even.remove(even[0])
            even.remove(even[0])

    elif len(even)>len(odd):
        if len(even)!=2*n:
            if len(even)%2==0 and len(odd)%2==0:
                even.remove(even[0])
                even.remove(even[0])

            elif len(even)%2!=0 and len(odd)%2!=0:
                even.remove(even[0])
                odd.remove(odd[0])

        else:
            even.remove(even[0])
            even.remove(even[0])

    elif len(odd)>len(even):
        if len(odd)!=2*n:
            if len(even)%2==0 and len(odd)%2==0:
                odd.remove(odd[0])
                odd.remove(odd[0])
            elif len(even)%2!=0 and len(odd)%2!=0:
                even.remove(even[0])
                odd.remove(odd[0])

        else:
            odd.remove(odd[0])
            odd.remove(odd[0])
    #print(even)
    #print(odd)
    i,j=0,0
    while i<len(even):
        print(arr.index(even[i])+1,arr.index(even[i+1])+1)
        arr.index[even[i]]=0
        arr.index[even[i+1]]=0
        i+=2
    while j<len(odd):
        print(arr.index(odd[j])+1,arr.index(odd[j+1])+1)
        arr.index[odd[i]]=0
        arr.index[odd[i+1]]=0
        j+=2


for _ in range(int(input())):
    n=int(input())
    arr=list(int(i) for i in input().split())
    odd,even=[],[]
    for i in arr:
        if i%2==0:
            even.append(i)
        else:
            odd.append(i)

    if len(even)==len(odd):
        if len(even)%2!=0:
            even.remove(even[0])
            odd.remove(odd[0])
        elif len(even)%2==0:
            even.remove(even[0])
            even.remove(even[0])

    elif len(even)>len(odd):
        if len(even)!=2*n:
            if len(even)%2==0 and len(odd)%2==0:
                even.remove(even[0])
                even.remove(even[0])

            elif len(even)%2!=0 and len(odd)%2!=0:
                even.remove(even[0])
                odd.remove(odd[0])

        else:
            even.remove(even[0])
            even.remove(even[0])

    elif len(odd)>len(even):
        if len(odd)!=2*n:
            if len(even)%2==0 and len(odd)%2==0:
                odd.remove(odd[0])
                odd.remove(odd[0])
            elif len(even)%2!=0 and len(odd)%2!=0:
                even.remove(even[0])
                odd.remove(odd[0])

        else:
            odd.remove(odd[0])
            odd.remove(odd[0])
    #print(even)
    #print(odd)
    i,j=0,0
    while i<len(even):
        print(arr.index(even[i])+1,arr.index(even[i+1])+1)
        i+=2
    while j<len(odd):
        print(arr.index(odd[j])+1,arr.index(odd[j+1])+1)
        j+=2


for _ in range(int(input())):
    n=int(input())
    arr=list(int(i) for i in input().split())
    odd,even=[],[]
    for i in arr:
        if i%2==0:
            even.append(i)
        else:
            odd.append(i)

    if len(even)==len(odd):
        if len(even)%2!=0:
            even.remove(even[0])
            odd.remove(odd[0])
        elif len(even)%2==0:
            even.remove(even[0])
            even.remove(even[0])

    elif len(even)>len(odd):
        if len(even)!=2*n:
            if len(even)%2==0 and len(odd)%2==0:
                even.remove(even[0])
                even.remove(even[0])

            elif len(even)%2!=0 and len(odd)%2!=0:
                even.remove(even[0])
                odd.remove(odd[0])

        else:
            even.remove(even[0])
            even.remove(even[0])

    elif len(odd)>len(even):
        if len(odd)!=2*n:
            if len(even)%2==0 and len(odd)%2==0:
                odd.remove(odd[0])
                odd.remove(odd[0])
            elif len(even)%2!=0 and len(odd)%2!=0:
                even.remove(even[0])
                odd.remove(odd[0])

        else:
            odd.remove(odd[0])
            odd.remove(odd[0])
    #print(even)
    #print(odd)
    i,j=0,0
    while i<len(even):
        print(arr.index(even[i])+1,arr.index(even[i+1])+1)
        arr.index[even[i]]=0
        arr.index[even[i]+1]=0
        i+=2
    while j<len(odd):
        print(arr.index(odd[j])+1,arr.index(odd[j+1])+1)
        arr.index[odd[i]]=0
        arr.index[odd[i]+1]=0
        j+=2


for _ in range(int(input())):
    n=int(input())
    arr=list(int(i) for i in input().split())
    odd,even=[],[]
    for i in arr:
        if i%2==0:
            even.append(i)
        else:
            odd.append(i)

    if len(even)==len(odd):
        if len(even)%2!=0:
            even.remove(even[0])
            odd.remove(odd[0])
        elif len(even)%2==0:
            even.remove(even[0])
            even.remove(even[0])

    elif len(even)>len(odd):
        if len(even)!=2*n:
            if len(even)%2==0 and len(odd)%2==0:
                even.remove(even[0])
                even.remove(even[0])

            elif len(even)%2!=0 and len(odd)%2!=0:
                even.remove(even[0])
                odd.remove(odd[0])

        else:
            even.remove(even[0])
            even.remove(even[0])

    elif len(odd)>len(even):
        if len(odd)!=2*n:
            if len(even)%2==0 and len(odd)%2==0:
                odd.remove(odd[0])
                odd.remove(odd[0])
            elif len(even)%2!=0 and len(odd)%2!=0:
                even.remove(even[0])
                odd.remove(odd[0])

        else:
            odd.remove(odd[0])
            odd.remove(odd[0])
    #print(even)
    #print(odd)
    i,j=0,0
    while i<len(even):
        print(arr.index(even[i])+1,arr.index(even[i+1])+1)
        #arr[arr.index[even[i]]]=0
        tmp1=arr.index(even[i])
        arr[tmp1]=0
        tmp2=arr.index(even[i+1])
        arr[tmp2]=0
        #arr[arr.index[even[i+1]]]=0
        i+=2
    while j<len(odd):
        print(arr.index(odd[j])+1,arr.index(odd[j+1])+1)
        #arr[arr.index[odd[i]]]=0
        tmp1=arr.index(odd[j])
        arr[tmp1]=0
        tmp2=arr.index(odd[j+1])
        arr[tmp2]=0
        #arr[arr.index[odd[i+1]]]=0
        j+=2


# from math import factorial as fac
from collections import defaultdict
# from copy import deepcopy
import sys, math
f = None
try:
	f = open('q1.input', 'r')
except IOError:
	f = sys.stdin
if 'xrange' in dir(__builtins__):
	range = xrange
# print(f.readline())
# sys.setrecursionlimit(10**5)

def print_case_iterable(case_num, iterable):
	print("Case #{}: {}".format(case_num," ".join(map(str,iterable))))

def print_case_number(case_num, iterable):
	print("Case #{}: {}".format(case_num,iterable))

def print_iterable(A):
	print (' '.join(A))

def ri():
	x = f.readline().strip()
	# print(x)
	return int(x)
	# return int(f.readline().strip())
def ria():
	return [int(x) for x in f.readline().strip().split(" ")]
def rns():
	a =  [x for x in f.readline().split(" ")]
	return int(a[0]), a[1].strip()
def read_string():
	return list(f.readline().strip())

import string
def solution(a,n):
	odds = []
	evens = []
	for x in a:
		if x%2:
			odds.append(x)
		else:
			evens.append(x)
	if len(odds) % 2:
		odds.pop()
		evens.pop()
	else:
		if odds:
			odds.pop();odds.pop()
		else:
			evens.pop(); evens.pop()
	for i in range(0,len(odds),2):
		print(odds[i],odds[i+1])
	for i in range(0,len(evens),2):
		print(evens[i],evens[i+1])

def main():
	t = ri()
	for _ in range(t):
		n = ri()
		a = ria()

		x = solution(a,n)
		continue
		if 'xrange' not in dir(__builtins__):
			print(x)
		else:
			print >>output, str(x)
	if 'xrange' in dir(__builtins__):
		print(output.getvalue())
		output.close()

if 'xrange' in dir(__builtins__):
	import cStringIO
	output = cStringIO.StringIO()
#example usage:
#    for l in res:
#       print >>output, str(len(l)) + ' ' +  ' '.join(l)

if __name__ == '__main__':
	main()


t = int(input())
for _ in range(t):
    n = int(input())
    a = [int(x) for x in input().split()]
    odds = []
    evens = []
    for x in a:
        if x%2:
            odds.append(x)
        else:
            evens.append(x)
    if len(odds) % 2:
        odds.pop()
        evens.pop()
    else:
        if odds:
            odds.pop();odds.pop()
        else:
            evens.pop(); evens.pop()
    for i in range(0,len(odds),2):
        print(odds[i],odds[i+1])
    for i in range(0,len(evens),2):
        print(evens[i],evens[i+1]


# from math import factorial as fac
from collections import defaultdict
# from copy import deepcopy
import sys, math
f = None
try:
	f = open('q1.input', 'r')
except IOError:
	f = sys.stdin
if 'xrange' in dir(__builtins__):
	range = xrange
# print(f.readline())
# sys.setrecursionlimit(10**5)

def print_case_iterable(case_num, iterable):
	print("Case #{}: {}".format(case_num," ".join(map(str,iterable))))

def print_case_number(case_num, iterable):
	print("Case #{}: {}".format(case_num,iterable))

def print_iterable(A):
	print (' '.join(A))

def ri():
	x = f.readline().strip()
	# print(x)
	return int(x)
	# return int(f.readline().strip())
def ria():
	return [int(x) for x in f.readline().strip().split(" ")]
def rns():
	a =  [x for x in f.readline().split(" ")]
	return int(a[0]), a[1].strip()
def read_string():
	return list(f.readline().strip())

import string
def solution(a,n):
	odds = []
	evens = []
	for i in range(2*n):
		x= a[i]
		if x%2:
			odds.append((x,i))
		else:
			evens.append((x,i))
	if len(odds) % 2:
		odds.pop()
		evens.pop()
	else:
		if odds:
			odds.pop();odds.pop()
		else:
			evens.pop(); evens.pop()
	for i in range(0,len(odds),2):
		print(odds[i][1]+1,odds[i+1][1]+1)
	for i in range(0,len(evens),2):
		print(evens[i][1]+1,evens[i+1][1]+1)

def main():
	t = ri()
	for _ in range(t):
		n = ri()
		a = ria()

		x = solution(a,n)
		continue
		if 'xrange' not in dir(__builtins__):
			print(x)
		else:
			print >>output, str(x)
	if 'xrange' in dir(__builtins__):
		print(output.getvalue())
		output.close()

if 'xrange' in dir(__builtins__):
	import cStringIO
	output = cStringIO.StringIO()
#example usage:
#    for l in res:
#       print >>output, str(len(l)) + ' ' +  ' '.join(l)

if __name__ == '__main__':
	main()


# from math import factorial as fac
from collections import defaultdict
# from copy import deepcopy
import sys, math
f = None
try:
	f = open('q1.input', 'r')
except IOError:
	f = sys.stdin
if 'xrange' in dir(__builtins__):
	range = xrange
# print(f.readline())
# sys.setrecursionlimit(10**5)

def print_case_iterable(case_num, iterable):
	print("Case #{}: {}".format(case_num," ".join(map(str,iterable))))

def print_case_number(case_num, iterable):
	print("Case #{}: {}".format(case_num,iterable))

def print_iterable(A):
	print (' '.join(A))

def ri():
	x = f.readline().strip()
	# print(x)
	return int(x)
	# return int(f.readline().strip())
def ria():
	return [int(x) for x in f.readline().strip().split(" ")]
def rns():
	a =  [x for x in f.readline().split(" ")]
	return int(a[0]), a[1].strip()
def read_string():
	return list(f.readline().strip())

import string
def solution(a,n):
	odds = []
	evens = []
	for i in range(2*n):
		x= a[i]
		if x%2:
			odds.append((x,i))
		else:
			evens.append((x,i))
	if len(odds) % 2:
		odds.pop()
		evens.pop()
	else:
		if odds:
			odds.pop();odds.pop()
		else:
			evens.pop(); evens.pop()
	for i in range(0,len(odds),2):
		print(odds[i][1],odds[i+1][1])
	for i in range(0,len(evens),2):
		print(evens[i][1],evens[i+1][1])

def main():
	t = ri()
	for _ in range(t):
		n = ri()
		a = ria()

		x = solution(a,n)
		continue
		if 'xrange' not in dir(__builtins__):
			print(x)
		else:
			print >>output, str(x)
	if 'xrange' in dir(__builtins__):
		print(output.getvalue())
		output.close()

if 'xrange' in dir(__builtins__):
	import cStringIO
	output = cStringIO.StringIO()
#example usage:
#    for l in res:
#       print >>output, str(len(l)) + ' ' +  ' '.join(l)

if __name__ == '__main__':
	main()


t=int(input())
l1=[]
for i in range(t):
    l=[]
    n=int(input())
    s=list(map(int,input().split()))
    for j in range(len(s)):
        l.append([s[j],j])
    l1.append(l)
for m in l1:
    odd=[]
    even=[]
    for k in m:
        if k[0]%2==0:
           even.append(k[1])
        else:
           odd.append(k[1])
    if len(odd)%2==0 and len(even)%2==0:
        if 0 in odd:
         for o in range(1,len(odd)-2,2):
            print(odd[o],odd[o+1])
         for e in range(0,len(even)-1,2):
            print(even[e],even[e+1])
        else:
         for o in range(0,len(odd)-1,2):
            print(odd[o],odd[o+1])
         for e in range(1,len(even)-2,2):
            print(even[e],even[e+1])
    elif len(odd)%2==1 and len(even)%2==1:
        for o in range(1,len(odd)-1,2):
            print(odd[o],odd[o+1])
        for e in range(1,len(even)-1,2):
            print(even[e],even[e+1])


t=int(input())
l1=[]
for i in range(t):
    l=[]
    n=int(input())
    s=list(map(int,input().split()))
    for j in range(len(s)):
        l.append([s[j],j])
    l1.append(l)
for m in l1:
    odd=[]
    even=[]
    for k in m:
        if k[0]%2==0:
           even.append(k[1])
        else:
           odd.append(k[1])
    if len(odd)%2==0 and len(even)%2==0:
         for o in range(0,len(odd)-1,2):
            print(odd[o]+1,odd[o+1]+1)
         if(len(even)>2):
          for e in range(0,len(even)-3,2):
            print(even[e]+1,even[e+1]+1)
    elif len(odd)%2==1 and len(even)%2==1:
         if len(odd)>1:
          for o in range(0,len(odd)-2,2):
            print(odd[o]+1,odd[o+1]+1)
         elif len(even)>1:
          for e in range(0,len(even)-2,2):
            print(even[e]+1,even[e+1]+1)


t=int(input())
l1=[]
for i in range(t):
    l=[]
    n=int(input())
    s=list(map(int,input().split()))
    for j in range(len(s)):
        l.append([s[j],j])
    l1.append(l)
for m in l1:
    odd=[]
    even=[]
    if len(m)==4:
      print(1,2)
    else:
      for k in m:
         if k[0]%2==0:
           even.append(k[1])
         else:
           odd.append(k[1])
      if len(odd)%2==0 and len(even)%2==0:
           if len(even)>2 and len(odd)>2:
             for o in range(0,len(odd)-3,2):
                print(odd[o]+1,odd[o+1]+1)
             for e in range(0,len(even)-1,2):
                print(even[e]+1,even[e+1]+1)
           elif len(odd)==0:
             for e in range(0,len(even)-3,2):
                print(even[e]+1,even[e+1]+1)
           elif len(even)==0:
             for o in range(0,len(odd)-3,2):
                print(odd[o]+1,odd[o+1]+1)
           elif len(even)==2:
             for o in range(0,len(odd)-1,2):
                print(odd[o]+1,odd[o+1]+1)
           elif len(odd)==2:
             for e in range(0,len(even)-1,2):
                print(even[e]+1,even[e+1]+1)
      elif len(odd)%2==1 and len(even)%2==1:
           if len(odd)>1:
             for o in range(0,len(odd)-2,2):
                print(odd[o]+1,odd[o+1]+1)
           if len(even)>1:
             for e in range(0,len(even)-2,2):
                print(even[e]+1,even[e+1]+1)


t=int(input())
l1=[]
for i in range(t):
    l=[]
    n=int(input())
    s=list(map(int,input().split()))
    for j in range(len(s)):
        l.append([s[j],j])
    l1.append(l)
for m in l1:
    odd=[]
    even=[]
    if len(m)==4:
      print(1,2)
    else:
      for k in m:
         if k[0]%2==0:
           even.append(k[1])
         else:
           odd.append(k[1])
      if len(odd)%2==0 and len(even)%2==0:
           if len(even)>2 and len(odd)>2:
             for o in range(0,len(odd)-3,2):
                print(odd[o]+1,odd[o+1]+1)
             for e in range(0,len(even)-3,2):
                print(even[e]+1,even[e+1]+1)
           elif len(odd)==0:
             for e in range(0,len(even)-3,2):
                print(even[e]+1,even[e+1]+1)
           elif len(even)==0:
             for o in range(0,len(odd)-3,2):
                print(odd[o]+1,odd[o+1]+1)
           elif len(even)==2:
             for o in range(0,len(odd)-1,2):
                print(odd[o]+1,odd[o+1]+1)
           elif len(odd)==2:
             for e in range(0,len(even)-1,2):
                print(even[e]+1,even[e+1]+1)
      elif len(odd)%2==1 and len(even)%2==1:
           if len(odd)>1:
             for o in range(0,len(odd)-2,2):
                print(odd[o]+1,odd[o+1]+1)
           if len(even)>1:
             for e in range(0,len(even)-2,2):
                print(even[e]+1,even[e+1]+1)


t=int(input())
l1=[]
for i in range(t):
    l=[]
    n=int(input())
    s=list(map(int,input().split()))
    for j in range(len(s)):
        l.append([s[j],j])
    l1.append(l)
for m in l1:
    odd=[]
    even=[]
    for k in m:
        if k[0]%2==0:
           even.append(k[1])
        else:
           odd.append(k[1])
    if len(odd)%2==0 and len(even)%2==0:
         for o in range(0,len(odd)-1,2):
            print(odd[o]+1,odd[o+1]+1)
         if(len(even)>2):
          for e in range(0,len(even)-3,2):
            print(even[e]+1,even[e+1]+1)
    elif len(odd)%2==1 and len(even)%2==1:
         if len(odd)>1:
          for o in range(0,len(odd)-2,2):
            print(odd[o]+1,odd[o+1]+1)
         if len(even)>1:
          for e in range(0,len(even)-2,2):
            print(even[e]+1,even[e+1]+1)


t=int(input())
l1=[]
for i in range(t):
    l=[]
    n=int(input())
    s=list(map(int,input().split()))
    for j in range(len(s)):
        l.append([s[j],j])
    l1.append(l)
for m in l1:
    odd=[]
    even=[]
    for k in m:
        if k[0]%2==0:
           even.append(k[1])
        else:
           odd.append(k[1])
    if len(odd)%2==0 and len(even)%2==0:
        for o in range(0,len(odd)-1,2):
            print(odd[o],odd[o+1])
        for e in range(0,len(even)-3,2):
            print(even[e],even[e+1])
    elif len(odd)%2==1 and len(even)%2==1:
        for o in range(0,len(odd)-2,2):
            print(odd[o],odd[o+1])
        for e in range(0,len(even)-2,2):
            print(even[e],even[e+1])


t=int(input())
for i in range(t):
    n=int(input())
    arr=list(map(int,input().strip().split()))
    c1=[]
    c2=[]
    for i in range(2*n):
        if(arr[i]%2==0):
            c1.append(i+1)
        else:
            c2.append(i+1)
    if(len(c2)%2==0):
        c1.pop()
        c1.pop()
    elif(len(c2)%2!=0):
        c1.pop()
        c2.pop()

    for i in range(0,len(c1),2):
        print(c1[i],c1[i+1])
    for j in range(0,len(c2),2):
        print(c2[j],c2[j+1])


t=int(input())
for i in range(t):
    n=int(input())
    arr=list(map(int,input().strip().split()))
    c1=[]
    c2=[]
    for i in range(2*n):
        if(arr[i]%2==0):
            c1.append(arr[i])
        else:
            c2.append(arr[i])
    if(len(c2)%2==0):
        c1.pop()
        c1.pop()
    elif(len(c2)%2!=0):
        c1.pop()
        c2.pop()
    for i in range(len(c2)):
        c1.append(c2[i])
    for j in range(0,len(c1),2):
        print(c1[j],c1[j+1])


t=int(input())
for i in range(t):
    n=int(input())
    arr=list(map(int,input().strip().split()))
    c1=[]
    c2=[]
    for i in range(2*n):
        if(arr[i]%2==0):
            c1.append(i+1)
        else:
            c2.append(i+1)
    if(len(c2)%2==0):
        c1.pop()
        c1.pop()
    else:
        c1.pop()
        c2.pop()

    for i in range(len(c1)):
        c2.append(c1[i])
    for i in range(0,len(c2),2):
        print(c2[i],end=" ")
        print(c2[i+1])


t=int(input())
for i in range(t):
    n=int(input())
    arr=list(map(int,input().strip().split()))
    c1=[]
    c2=[]
    for i in range(2*n):
        if(arr[i]%2==0):
            c1.append(i+1)
        else:
            c2.append(i+1)
    if(len(c2)%2==0):
        if(len(c1)>0):
            c1.pop()
            c1.pop()
        else:
            c2.pop()
            c2.pop()
    elif(len(c2)%2!=0):
        c1.pop()
        c2.pop()

    for i in range(0,len(c1),2):
        print(c1[i],c1[i+1])
    for j in range(0,len(c2),2):
        print(c2[j],c2[j+1])


t=int(input())
for i in range(t):
   p=int(input())
   l=list(map(int,input().split(" ")))
   a=[]
   b=[]
   for i in l:
      if i%2==0:
         a.append(i)
      else:
         b.append(i)
   if len(b)%2==0:
      if len(b)==0:
         a=a[:len(a)-2]
      else:
         b=b[:len(b)-2]
   else:
      a=a[:len(a)-1]
      b=b[:len(b)-1]
   if len(a)>0:
      for i in range(0,len(a)-1,2):
         print(a[i],a[i+1])
   if len(b)>0:
      for i in range(0,len(b)-1,2):
         print(b[i],b[i+1])


t=int(input())
l=list(map(int,input().split(" ")))
a=[]
b=[]
for i in l:
   if i%2==0:
      a.append(i)
   else:
      b.append(i)
if len(b)%2==0:
   if len(b)==0:
      a=a[:len(a)-2]
   else:
      b=b[:len(b)-2]
else:
   a=a[:len(a)-1]
   b=b[:len(b)-1]
if len(a)>0:
   for i in range(len(a)-2,2):
      print(a[i],a[i+1])
if len(b)>0:
   for i in range(len(b)-2,2):
      print(b[i],b[i+1])


t=int(input())
for i in range(t):
   p=int(input())
   l=list(map(int,input().split(" ")))
   a=[]
   b=[]
   for i in range(len(l)):
      if l[i]%2==0:
         a.append(i+1)
      else:
         b.append(i+1)
   if len(b)%2==0:
      if len(b)==0:
         a=a[:len(a)-2]
      else:
         b=b[:len(b)-2]
   else:
      a=a[:len(a)-1]
      b=b[:len(b)-1]
   if len(a)>0:
      for i in range(0,len(a)-1,2):
         print(a[i],a[i+1])
   if len(b)>0:
      for i in range(0,len(b)-1,2):
         print(b[i],b[i+1])


t=int(input())
for i in range(t):
   p=int(input())
   l=list(map(int,input().split(" ")))
   a=[]
   b=[]
   for i in range(len(l):
      if l[i]%2==0:
         a.append(i+1)
      else:
         b.append(i+1)
   if len(b)%2==0:
      if len(b)==0:
         a=a[:len(a)-2]
      else:
         b=b[:len(b)-2]
   else:
      a=a[:len(a)-1]
      b=b[:len(b)-1]
   if len(a)>0:
      for i in range(0,len(a)-1,2):
         print(a[i],a[i+1])
   if len(b)>0:
      for i in range(0,len(b)-1,2):
         print(b[i],b[i+1])


def getDropList(arr):
    evenNumber = len(list(filter(lambda x: x % 2 == 0, arr)))

    if evenNumber < 3:
        useCase = 1
    elif evenNumber == 3:
        useCase = 'mix'
    else:
        useCase = 0

    dropArray = []
    evenOddList = [a % 2 for a in arr]

    if useCase == 'mix':
        dropArray.append(evenOddList.index(1))
        useCase = 1

    while len(dropArray) < len(evenOddList):
        newIndex = -1
        for i in range(len(evenOddList)):
            if i not in dropArray and evenOddList[i] != useCase:
                newIndex = i
                break
        if newIndex == -1:
            for i in range(len(evenOddList)):
                if i not in dropArray:
                    newIndex = i
                    break
        dropArray.append(newIndex)

    dropWithoutFirst = [a + 1 for a in dropArray][2:]

    resultArray = []

    for i in range(len(dropWithoutFirst) // 2):
        resultArray.append(dropWithoutFirst[i * 2: i*2 + 2])

    return resultArray

a = int(input())
for i in range(a):
    input()
    arr = list(map(int, input().split()))
    resultArray = getDropList(arr)
    for el in resultArray:
        print(el[0], el[1])


def getDropList(arr):
    evenArray = []
    oddArray = []
    for i in range(len(arr)):
        if arr[i] % 2 == 0:
            evenArray.append(i)
        else:
            oddArray.append(i)

    firstArray = evenArray
    secondArray = oddArray

    if (len(evenArray) > len(oddArray)):
        firstArray, secondArray = secondArray, firstArray

    dropArray = firstArray[:(len(firstArray) // 2 ) * 2] + secondArray[:((len(secondArray) - 1) // 2 ) * 2]
    resultArray = []
    for i in range(len(dropArray) // 2):
        resultArray.append([dropArray[2 * i] + 1, dropArray[2 * i + 1] + 1])

    return resultArray

a = int(input())
for i in range(a):
    input()
    arr = list(map(int, input().split()))
    resultArray = getDropList(arr)
    for el in resultArray:
        print(el[0], el[1])


def getDropList(arr):
    evenArray = []
    oddArray = []
    for i in range(len(arr)):
        if arr[i] % 2 == 0:
            evenArray.append(i)
        else:
            oddArray.append(i)

    evenNumber = len(evenArray)
    print(evenNumber)

    firstArray = evenArray
    secondArray = oddArray

    if (len(evenArray) < len(oddArray)):
        firstArray, secondArray = secondArray, firstArray

    dropArray = firstArray[:(len(firstArray) // 2 ) * 2] + secondArray[:((len(secondArray) - 1) // 2 ) * 2]
    resultArray = []
    for i in range(len(dropArray) // 2):
        resultArray.append([dropArray[2 * i] + 1, dropArray[2 * i + 1] + 1])

    print(resultArray)
    return resultArray

a = int(input())
for i in range(a):
    input()
    arr = list(map(int, input().split()))
    print(arr)
    resultArray = getDropList(arr)
    for el in resultArray:
        print(el[0], el[1])


def getDropList(arr):
    evenArray = []
    oddArray = []
    for i in range(len(arr)):
        if arr[i] % 2 == 0:
            evenArray.append(i)
        else:
            oddArray.append(i)

    firstArray = evenArray
    secondArray = oddArray

    if (len(evenArray) < len(oddArray)):
        firstArray, secondArray = secondArray, firstArray

    dropArray = firstArray[:(len(firstArray) // 2 ) * 2] + secondArray[:((len(secondArray) - 1) // 2 ) * 2]
    resultArray = []
    for i in range(len(dropArray) // 2):
        resultArray.append([dropArray[2 * i] + 1, dropArray[2 * i + 1] + 1])

    return resultArray

a = int(input())
for i in range(a):
    input()
    arr = list(map(int, input().split()))
    resultArray = getDropList(arr)
    for el in resultArray:
        print(el[0], el[1])


def getDropList(arr):
    evenNumber = len(list(filter(lambda x: x % 2 == 0, arr)))

    if evenNumber < 3:
        useCase = 1
    elif evenNumber == 3:
        useCase = 'mix'
    else:
        useCase = 0

    dropArray = []
    evenOddList = [a % 2 for a in arr]

    if useCase == 'mix':
        dropArray.append(evenOddList.index(1))
        useCase = 1
    elif evenNumber %  2 == 1:
        dropArray.append(evenOddList.index(useCase))

    while len(dropArray) < len(evenOddList):
        newIndex = -1
        for i in range(len(evenOddList)):
            if i not in dropArray and evenOddList[i] != useCase:
                newIndex = i
                break
        if newIndex == -1:
            for i in range(len(evenOddList)):
                if i not in dropArray:
                    newIndex = i
                    break
        dropArray.append(newIndex)

    dropWithoutFirst = [a + 1 for a in dropArray][2:]

    resultArray = []

    for i in range(len(dropWithoutFirst) // 2):
        resultArray.append(dropWithoutFirst[i * 2: i*2 + 2])

    return resultArray

a = int(input())
for i in range(a):
    input()
    arr = list(map(int, input().split()))
    resultArray = getDropList(arr)
    for el in resultArray:
        print(el[0], el[1])
#        print(arr[el[0] - 1] + arr[el[1] - 1])


for s in[*open(0)][2::2]:
 a=s.split();b=[i+1for i,x in enumerate(a)if
int(x)%2];b=c,d=sorted((a,sorted({*range(1,len(a)+1)}-{*b})),key=len);d.pop();b[len(c)%2].pop();print(*c,*d)


for s in[*open(0)][2::2]:a=s.split();b=[i+1for i,x in enumerate(a)if
int(x)%2];b=c,d=sorted((b,sorted({*range(1,len(a)+1)}-{*b})),key=len);d.pop();b[len(d)%2].pop();print(*c,*d)


for s in[*open(0)][2::2]:
 a=s.split();n=len(a);a=[i+1for i,x in enumerate(a)if
int(x)%2];a=b,c=sorted((a,sorted({*range(1,n+1)}-{*a})),key=len);c.pop();a[len(c)%2].pop();print(*b,*c)


for s in[*open(0)][2::2]:a=s.split();b={i+1for i,x in enumerate(a)if
int(x)%2};b=c,d=sorted((b,{*range(1,len(a)+1)}-b),key=len);d.pop();b[len(d)%2].pop();print(*c,*d)


for s in[*open(0)][2::2]:
 a=s.split();b=[i+1for i,x in enumerate(a)if
int(x)%2];b=c,d=sorted((b,sorted({*range(1,len(a)+1)}-{*b})),key=len);d.pop();b[len(c)%2].pop();print(*c,*d)


for s in[*open(0)][2::2]:
 a=s.split();b=[i+1for i,x in enumerate(a)if
int(x)%2];b=c,d=sorted((b,sorted({*range(1,len(a)+1)}-{*b})),key=len);d.pop();b[len(d)%2].pop();print(*c,*d)


for s in[*open(0)][2::2]:a=s.split();b=[i+1for i,x in enumerate(a)if
int(x)%2];b=c,d=sorted((b,{*range(1,len(a)+1)}-{*b}),key=len);d.pop();b[len(d)%2].pop();print(*c,*d)


t = int(input())
while t > 0:
    t -= 1
    n = int(input())
    even = []
    odd = []
    arr = list(map(int, input().split()))

    for i in range(len(arr)):
        if arr[i] % 2:
            odd.append(i+1)
        else:
            even.append(i+1)

    for i in range(n-1):
        if len(odd) > 1:
            print(odd.pop(), odd.pop())
        else:
            print(even.pop(), even.pop())


# incompelete
t = int(input())
while t:
    t-=1
    n = int(input())
    arr = list(map(int,input().split()))


# incompelete
t = int(input())
while t:
    t-=1
    n = int(input())
    arr = list(map(int,input().split()))
    odd = []
    even = []
    for i in range(2*n):
        if arr[i]%2==0:
            even.append(i)
        else:
            odd.append(i)
    even = even[::-1]
    odd = odd[::-1]
    for i in range(n-1):
        print(even[i]+1,odd[i]+1)


# incompelete
t = int(input())
while t:
    t-=1
    n = int(input())
    arr = list(map(int,input().split()))
    odd = []
    even = []
    for i in range(2*n):
        if arr[i]%2==0:
            even.append(i)
        else:
            odd.append(i)
    for i in range(n-1):
        print(even[i]+1,odd[i]+1)
        print()


# incompelete
t = int(input())
while t:
    t-=1
    n = int(input())
    arr = list(map(int,input().split()))
    odd = []
    even = []
    for i in range(2*n):
        if arr[i]%2==0:
            even.append(i)
        else:
            odd.append(i)
    for i in range(n-1):
        print(even[i]+1,odd[i]+1)


t = int(input())
nlist = []
matrix = []
for i in range(t):
	n = int(input())
	nlist.append(n)
	array = [int(i) for i in input().split()]
	matrix.append(array)

for array in matrix:
	oddcount = 0
	evencount = 0
	for i in array:
		if i % 2 == 1:
			oddcount += 1
		elif i % 2 == 0:
			evencount += 1

	if max(evencount, oddcount) % 2 == 1:
		ind = 1
		ref = 0
		for i in array:
			if ref == oddcount - 1:
				break
			if i % 2 == 1:
				if ref % 2 == 1:
					print(ind)
				else:
					print(ind, end = ' ')
				ref += 1
			ind += 1

		ind = 1
		ref = 0
		for i in array:
			if ref == evencount - 1:
				break
			if i % 2 == 0:
				if ref % 2 == 1:
					print(ind)
				else:
					print(ind, end = ' ')
				ref += 1
			ind += 1

	elif oddcount == evencount:
		ind = 1
		ref = 0
		for i in array:
			if ref == evencount - 2:
				break
			if i % 2 == 0:
				if ref % 2 == 1:
					print(ind)
				else:
					print(ind, end = ' ')
				ref += 1
			ind += 1

		ind = 1
		ref = 0
		for i in array:
			if i % 2 == 1:
				if ref % 2 == 1:
					print(ind)
				else:
					print(ind, end = ' ')
				ref += 1
			ind += 1

	else:
		ind = 1
		ref = 0
		for i in array:
			if ref == max(oddcount, evencount) - 2:
				break
			elif i % 2 == 0:
				if ref % 2 == 1:
					print(ind)
				else:
					print(ind, end = ' ')
				ref += 1
			ind += 1

		ind = 1
		ref = 0
		for i in array:
			if ref == max(oddcount, evencount) - 2:
				break
			elif i % 2 == 1:
				if ref % 2 == 1:
					print(ind)
				else:
					print(ind, end = ' ')
				ref += 1
			ind += 1


t = int(input())
nlist = []
matrix = []
for i in range(t):
	n = int(input())
	nlist.append(n)
	array = [int(i) for i in input().split()]
	matrix.append(array)

for array in matrix:
	odds = []
	evens = []
	for i in array:
		if i % 2 == 0:
			evens.append(i)
		else:
			odds.append(i)
	if len(evens) % 2 == 0 and len(evens) > 0:
		array.pop(array.index(evens[0]))
		evens.pop(0)
		array.pop(array.index(evens[0]))
		evens.pop(0)
	elif len(odds) % 2 == 0:
		array.pop(array.index(odds[0]))
		odds.pop(0)
		array.pop(array.index(odds[0]))
		odds.pop(0)
	else:
		evens.pop(0)
		odds.pop(0)

	o = 1
	e = 1
	for i in range(len(array)):
		if array[i] in odds:
			if o % 2 == 0:
				print(i + 1)
			else:
				print(i + 1, end = ' ')
			o += 1
	o = 1
	e = 1
	for i in range(len(array)):
		if array[i] in evens:
			if e % 2 == 0:
				print(i + 1)
			else:
				print(i + 1, end = ' ')
			e += 1


t = int(input())
nlist = []
matrix = []
for i in range(t):
	n = int(input())
	nlist.append(n)
	array = [int(i) for i in input().split()]
	matrix.append(array)

for array in matrix:
	odds = []
	evens = []
	for i in array:
		if i % 2 == 0:
			evens.append(i)
		else:
			odds.append(i)
	if len(evens) % 2 == 0 and len(evens) > 0:
		evens.pop(0)
		evens.pop(0)
	elif len(odds) % 2 == 0:
		odds.pop(0)
		odds.pop(0)
	else:
		evens.pop(0)
		odds.pop(0)

	o = 1
	e = 1
	for i in range(len(array)):
		if array[i] in odds:
			if o % 2 == 0:
				print(i)
			else:
				print(i, end = ' ')
			o += 1
	o = 1
	e = 1
	for i in range(len(array)):
		if array[i] in evens:
			if e % 2 == 0:
				print(i)
			else:
				print(i, end = ' ')
			e += 1


t = int(input())
nlist = []
matrix = []
for i in range(t):
	n = int(input())
	nlist.append(n)
	array = [int(i) for i in input().split()]
	matrix.append(array)

for array in matrix:
	oddcount = 0
	evencount = 0
	for i in array:
		if i % 2 == 1:
			oddcount += 1
		elif i % 2 == 0:
			evencount += 1

	if max(evencount, oddcount) % 2 == 1:
		ind = 1
		ref = 0
		for i in array:
			if ref == oddcount - 1:
				break
			if i % 2 == 1:
				if ref % 2 == 1:
					print(ind)
				else:
					print(ind, end = ' ')
				ref += 1
			ind += 1

		ind = 1
		ref = 0
		for i in array:
			if ref == evencount - 1:
				break
			if i % 2 == 0:
				if ref % 2 == 1:
					print(ind)
				else:
					print(ind, end = ' ')
				ref += 1
			ind += 1

	else:
		ind = 1
		ref = 0
		for i in array:
			if ref == max(oddcount, evencount) - 2:
				break
			elif i % 2 == 0:
				if ref % 2 == 1:
					print(ind)
				else:
					print(ind, end = ' ')
				ref += 1
			ind += 1

		ind = 1
		ref = 0
		for i in array:
			if ref == max(oddcount, evencount) - 2:
				break
			elif i % 2 == 1:
				if ref % 2 == 1:
					print(ind)
				else:
					print(ind, end = ' ')
				ref += 1
			ind += 1


t = int(input())
nlist = []
matrix = []
for i in range(t):
	n = int(input())
	nlist.append(n)
	array = [int(i) for i in input().split()]
	matrix.append(array)

for array in matrix:
	odds = []
	evens = []
	for i in array:
		if i % 2 == 0:
			evens.append(i)
		else:
			odds.append(i)
	if len(evens) % 2 == 0 and len(evens) > 0:
		evens.pop(0)
		evens.pop(0)
	elif len(odds) % 2 == 0:
		odds.pop(0)
		odds.pop(0)
	else:
		evens.pop(0)
		odds.pop(0)

	o = 1
	e = 1
	for i in range(len(array)):
		if array[i] in odds:
			if o % 2 == 0:
				print(i + 1)
			else:
				print(i + 1, end = ' ')
			o += 1
	o = 1
	e = 1
	for i in range(len(array)):
		if array[i] in evens:
			if e % 2 == 0:
				print(i + 1)
			else:
				print(i + 1, end = ' ')
			e += 1