#include<bits/stdc++.h>
using namespace std;
class contest
{
    public:
        long index,count,i,j;
        char s[1000000];
        void segment(long n)
        {
            index=0;
            count=0;
            while(n>0)
            {
                if(n==0 || n==1)
                {
                    cout<<0;
                    break;
                }else
                {
                    if(n==7)
                {
                    s[index]='7';
                    index++;
                    s[index]='1';
                    index++;
                    s[index]='1';
                    index++;
                    n=n-7;
                    count=count+3;
                }
                else if(n>=6)
                {
                    s[index]='9';
                    index++;
                    n=n-6;
                    count++;
                }
                else if(n==5)
                {
                    s[index]='7';
                    index++;
                    n=n-3;
                    s[index]='1';
                    index++;
                    n=n-2;
                    count=count+2;
                }
                else if(n==4)
                {
                    s[index]='1';
                    index++;
                    n=n-2;
                    s[index]='1';
                    index++;
                    n=n-2;
                    count=count+2;
                }
                else if(n==3)
                {
                    s[index]='7';
                    index++;
                    n=n-3;
                    count++;
                }
                else if(n==2)
                {
                    s[index]='1';
                    index++;
                    n=n-2;
                    count++;
                }
            }
            s[index]='\0';
            for(j=0;j<count;j++)
            {
                cout<<s[j];
            }
                }
            cout<<" ";
        }
};
int main()
{
    long t,i,n;
    cin>>t;
    contest obj[t];
    for(i=0;i<t;i++)
    {
        cin>>n;
        obj[i].segment(n);
    }
}


#include<bits/stdc++.h>
using namespace std;
class contest
{
    public:
        long index,count,i,j;
        string s[1000000];
        void segment(long n)
        {
            index=0;
            count=0;
            while(n>0)
            {
                if(n>=6)
                {
                    s[index]='9';
                    index++;
                    n=n-6;
                    count++;
                }
                else if(n==5)
                {
                    s[index]='7';
                    index++;
                    n=n-3;
                    s[index]='1';
                    index++;
                    n=n-2;
                    count=count+2;
                }
                else if(n==4)
                {
                    s[index]='1';
                    index++;
                    n=n-2;
                    s[index]='1';
                    index++;
                    n=n-2;
                    count=count+2;
                }
                else if(n==3)
                {
                    s[index]='7';
                    index++;
                    n=n-3;
                    count++;
                }
                else if(n==2)
                {
                    s[index]='1';
                    index++;
                    n=n-2;
                    count++;
                }
                else
                {
                    break;
                }
            }
            s[index]='\0';
            for(j=0;j<count;j++)
            {
                cout<<s[j];
            }
            cout<<" ";
        }
};
int main()
{
    long t,i,n;
    cin>>t;
    contest obj[t];
    for(i=0;i<t;i++)
    {
        cin>>n;
        obj[i].segment(n);
    }
}


#include<bits/stdc++.h>
using namespace std;
class contest
{
    public:
        int index,count,j;
        char s[100];
        void segment(int n)
        {
            index=0;
            count=0;
            while(n>=6)
            {
                s[index]='9';
                index++;
                n=n-6;
                count++;
            }
            while(n>=5)
            {
                s[index]='7';
                index++;
                n=n-3;
                s[index]='1';
                index++;
                n=n-2;
                count=count+2;
            }
            while(n>=4)
            {
                s[index]='1';
                index++;
                n=n-2;
                s[index]='1';
                index++;
                n=n-2;
                count=count+2;
            }
            while(n>=3)
            {
                s[index]='7';
                index++;
                n=n-3;
                count++;
            }
            while(n>=2)
            {
                s[index]='1';
                index++;
                n=n-2;
                count++;
            }
            s[index]='\0';
            for(j=0;j<count;j++)
            {
                cout<<s[j];
            }
            cout<<" ";
        }
};
int main()
{
    int t,i,n;
    cin>>t;
    contest obj[t];
    for(i=0;i<t;i++)
    {
        cin>>n;
        obj[i].segment(n);
    }
}


#include<bits/stdc++.h>
using namespace std;
class contest
{
    public:
        long index,count,i,j;
        char s[1000000];
        void segment(long n)
        {
            index=0;
            count=0;
            while(n>0)
            {
                if(n==0 || n==1)
                {
                    s[index]='0';
                    break;
                }
                if(n==7)
                {
                    s[index]='7';
                    index++;
                    s[index]='1';
                    index++;
                    s[index]='1';
                    index++;
                    n=n-7;
                }
                else if(n>=6)
                {
                    s[index]='9';
                    index++;
                    n=n-6;
                    count++;
                }
                else if(n==5)
                {
                    s[index]='7';
                    index++;
                    n=n-3;
                    s[index]='1';
                    index++;
                    n=n-2;
                    count=count+2;
                }
                else if(n==4)
                {
                    s[index]='1';
                    index++;
                    n=n-2;
                    s[index]='1';
                    index++;
                    n=n-2;
                    count=count+2;
                }
                else if(n==3)
                {
                    s[index]='7';
                    index++;
                    n=n-3;
                    count++;
                }
                else if(n==2)
                {
                    s[index]='1';
                    index++;
                    n=n-2;
                    count++;
                }
            }
            s[index]='\0';
            for(j=0;j<count;j++)
            {
                cout<<s[j];
            }
            cout<<" ";
        }
};
int main()
{
    long t,i,n;
    cin>>t;
    contest obj[t];
    for(i=0;i<t;i++)
    {
        cin>>n;
        obj[i].segment(n);
    }
}


#include<bits/stdc++.h>
using namespace std;
class contest
{
    public:
        int index,count,j;
        char s[100];
        void segment(int n)
        {
            index=0;
            count=0;
            while(n>0)
            {
                if(n==6)
                {
                    s[index]='9';
                    index++;
                    n=n-6;
                    count++;
                }
                else if(n==5)
                {
                    s[index]='7';
                    index++;
                    n=n-3;
                    s[index]='1';
                    index++;
                    n=n-2;
                    count=count+2;
                }
                else if(n==4)
                {
                    s[index]='1';
                    index++;
                    n=n-2;
                    s[index]='1';
                    index++;
                    n=n-2;
                    count=count+2;
                }
                else if(n==3)
                {
                    s[index]='7';
                    index++;
                    n=n-3;
                    count++;
                }
                else if(n==2)
                {
                    s[index]='1';
                    index++;
                    n=n-2;
                    count++;
                }
            }
            s[index]='\0';
            for(j=0;j<count;j++)
            {
                cout<<s[j];
            }
            cout<<" ";
        }
};
int main()
{
    int t,i,n;
    cin>>t;
    contest obj[t];
    for(i=0;i<t;i++)
    {
        cin>>n;
        obj[i].segment(n);
    }
}


#include<bits/stdc++.h>
using namespace std;
class contest
{
    public:
        long index,count,i,j;
        char s[100];
        void segment(long n)
        {
            index=0;
            count=0;
            for(i=0;n>0;i++)
            {
                if(n>=6)
                {
                    s[index]='9';
                    index++;
                    n=n-6;
                    count++;
                }
                else if(n==5)
                {
                    s[index]='7';
                    index++;
                    n=n-3;
                    s[index]='1';
                    index++;
                    n=n-2;
                    count=count+2;
                }
                else if(n==4)
                {
                    s[index]='1';
                    index++;
                    n=n-2;
                    s[index]='1';
                    index++;
                    n=n-2;
                    count=count+2;
                }
                else if(n==3)
                {
                    s[index]='7';
                    index++;
                    n=n-3;
                    count++;
                }
                else if(n==2)
                {
                    s[index]='1';
                    index++;
                    n=n-2;
                    count++;
                }
                else
                {
                    break;
                }
            }
            s[index]='\0';
            for(j=0;j<count;j++)
            {
                cout<<s[j];
            }
            cout<<" ";
        }
};
int main()
{
    long t,i,n;
    cin>>t;
    contest obj[t];
    for(i=0;i<t;i++)
    {
        cin>>n;
        obj[i].segment(n);
    }
}


#include<bits/stdc++.h>
using namespace std;
class contest
{
    public:
        long index,count,i,j;
        string s[1000000];
        void segment(long n)
        {
            index=0;
            count=0;
            while(n>0)
            {
                if(n==7)
                {
                    s[index]='7';
                    index++;
                    s[index]='1';
                    index++;
                    s[index]='1';
                    index++;
                    n=n-7;
                }
                else if(n>=6)
                {
                    s[index]='9';
                    index++;
                    n=n-6;
                    count++;
                }
                else if(n==5)
                {
                    s[index]='7';
                    index++;
                    n=n-3;
                    s[index]='1';
                    index++;
                    n=n-2;
                    count=count+2;
                }
                else if(n==4)
                {
                    s[index]='1';
                    index++;
                    n=n-2;
                    s[index]='1';
                    index++;
                    n=n-2;
                    count=count+2;
                }
                else if(n==3)
                {
                    s[index]='7';
                    index++;
                    n=n-3;
                    count++;
                }
                else if(n==2)
                {
                    s[index]='1';
                    index++;
                    n=n-2;
                    count++;
                }
            }
            s[index]='\0';
            for(j=0;j<count;j++)
            {
                cout<<s[j];
            }
            cout<<" ";
        }
};
int main()
{
    long t,i,n;
    cin>>t;
    contest obj[t];
    for(i=0;i<t;i++)
    {
        cin>>n;
        obj[i].segment(n);
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,i,n,j,index,count;
    char s[100];
    cin>>t;
    for(i=0;i<t;i++)
    {
        index=0;
        count=0;
        cin>>n;
        while(n>=6)
        {
            s[index]='9';
            index++;
            n=n-6;
            count++;
        }
        while(n>=5)
        {
            s[index]='7';
            index++;
            n=n-3;
            s[index]='1';
            index++;
            n=n-2;
            count=count+2;
        }
        while(n>=4)
        {
            s[index]='1';
            index++;
            n=n-2;
            s[index]='1';
            index++;
            n=n-2;
            count=count+2;
        }
        while(n>=3)
        {
            s[index]='7';
            index++;
            n=n-3;
            count++;
        }
        while(n>=2)
        {
            s[index]='1';
            index++;
            n=n-2;
            count++;
        }
        s[index]='\0';
        for(j=0;j<count;j++)
        {
            cout<<s[j];
        }
        cout<<" ";
    }
}


#include<bits/stdc++.h>
using namespace std;
class contest
{
    public:
        int index,count,i,j;
        char s[100];
        void segment(int n)
        {
            index=0;
            count=0;
            for(i=0;n>0;i++)
            {
                if(n==6)
                {
                    s[index]='9';
                    index++;
                    n=n-6;
                    count++;
                }
                else if(n==5)
                {
                    s[index]='7';
                    index++;
                    n=n-3;
                    s[index]='1';
                    index++;
                    n=n-2;
                    count=count+2;
                }
                else if(n==4)
                {
                    s[index]='1';
                    index++;
                    n=n-2;
                    s[index]='1';
                    index++;
                    n=n-2;
                    count=count+2;
                }
                else if(n==3)
                {
                    s[index]='7';
                    index++;
                    n=n-3;
                    count++;
                }
                else if(n==2)
                {
                    s[index]='1';
                    index++;
                    n=n-2;
                    count++;
                }
            }
            s[index]='\0';
            for(j=0;j<count;j++)
            {
                cout<<s[j];
            }
            cout<<" ";
        }
};
int main()
{
    int t,i,n;
    cin>>t;
    contest obj[t];
    for(i=0;i<t;i++)
    {
        cin>>n;
        obj[i].segment(n);
    }
}


#include<bits/stdc++.h>
using namespace std;
class contest
{
    public:
        int index,count,j;
        char s[100];
        void segment(int n)
        {
            index=0;
            count=0;
            for(;n>0;)
            {
                if(n==6)
                {
                    s[index]='9';
                    index++;
                    n=n-6;
                    count++;
                }
                else if(n==5)
                {
                    s[index]='7';
                    index++;
                    n=n-3;
                    s[index]='1';
                    index++;
                    n=n-2;
                    count=count+2;
                }
                else if(n==4)
                {
                    s[index]='1';
                    index++;
                    n=n-2;
                    s[index]='1';
                    index++;
                    n=n-2;
                    count=count+2;
                }
                else if(n==3)
                {
                    s[index]='7';
                    index++;
                    n=n-3;
                    count++;
                }
                else if(n==2)
                {
                    s[index]='1';
                    index++;
                    n=n-2;
                    count++;
                }
            }
            s[index]='\0';
            for(j=0;j<count;j++)
            {
                cout<<s[j];
            }
            cout<<" ";
        }
};
int main()
{
    int t,i,n;
    cin>>t;
    contest obj[t];
    for(i=0;i<t;i++)
    {
        cin>>n;
        obj[i].segment(n);
    }
}


#include<bits/stdc++.h>
using namespace std;
class contest
{
    public:
        int index,count,j;
        char s[100];
        void segment(int n)
        {
            index=0;
            count=0;
            while(n>=6)
            {
                s[index]='9';
                index++;
                n=n-6;
                count++;
            }
            while(n>=5)
            {
                s[index]='7';
                index++;
                n=n-3;
                s[index]='1';
                index++;
                n=n-2;
                count=count+2;
            }
            while(n>=4)
            {
                s[index]='1';
                index++;
                n=n-2;
                s[index]='1';
                index++;
                n=n-2;
                count=count+2;
            }
            while(n>=3)
            {
                s[index]='7';
                index++;
                n=n-3;
                count++;
            }
            while(n>=2)
            {
                s[index]='1';
                index++;
                n=n-2;
                count++;
            }
            s[index]='\0';
            for(j=0;j<count;j++)
            {
                cout<<s[j];
            }
            cout<<" ";
        }
};
int main()
{
    int t,i,n;
    cin>>t;
    contest obj;
    for(i=0;i<t;i++)
    {
        cin>>n;
        obj.segment(n);
    }
}


#include <bits/stdc++.h>
using namespace std;
// To give an input string after a integer or double is taken input
//cin.ignore();			// better to use 2 times getline(cin,s);
#define pb push_back
#define mk make_pair
#define siz size()
#define endl "\n"
#define ll long long int
#define ld long double
void fast()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
}

int main(void)
{
    fast();
    ll n;
    cin>>n;
    while(n--)
    {
        ll a;
        cin>>a;
        if(a%2==0)
        {
            for(int i=1;i<=a/2;i++)
            {
            cout<<1;
            }
         cout<<endl;
        }

        else if(a%2!=0)
        {
            cout<<7;
            a=a-3;
            for(int i=0;i<(a/2);i++)
            {
             cout<<1;
            }
            cout<<endl;
        }
    }
}

            // ll sum=0;
            // for(ll i=0;i<a/2;i++)
            // {
            //     sum=(sum*10)+1;
            // }
            // cout<<sum<<endl;

            // int sum=0;
            // for(int i=1;i<=a/3;i++)
            // {
            //     sum=(sum*10)+7;
            // }
            // cout<<sum<<endl;


#include <bits/stdc++.h>
using namespace std;
// To give an input string after a integer or double is taken input
//cin.ignore();			// better to use 2 times getline(cin,s);
#define pb push_back
#define mk make_pair
#define siz size()
#define endl "\n"
#define ll long long int
#define ld long double
void fast()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
}

int main(void)
{
    fast();
    ll n;
    cin>>n;
    while(n--)
    {
        ll a;
        cin>>a;
        if(a%2==0)
        {
            for(int i=1;i<=a/2;i++)
            {
            cout<<1;
            }
         cout<<endl;
        }

        else if(a%2!=0)
        {
            cout<<7;
            for(int i=0;i<(a/3)-1;i++)
            {
             cout<<1;
            }
            cout<<endl;
        }
    }
}

            // ll sum=0;
            // for(ll i=0;i<a/2;i++)
            // {
            //     sum=(sum*10)+1;
            // }
            // cout<<sum<<endl;

            // int sum=0;
            // for(int i=1;i<=a/3;i++)
            // {
            //     sum=(sum*10)+7;
            // }
            // cout<<sum<<endl;


#include <bits/stdc++.h>
using namespace std;
// To give an input string after a integer or double is taken input
//cin.ignore();			// better to use 2 times getline(cin,s);
#define pb push_back
#define mk make_pair
#define siz size()
#define endl "\n"
#define ll long long int
#define ld long double
void fast()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
}

int main(void)
{
    fast();
    ll n;
    cin>>n;
    while(n--)
    {
        ll a;
        cin>>a;
        if(a%2==0)
        {
            for(int i=1;i<=a/2;i++)
            {
            cout<<1;
            }
         cout<<endl;
        }

        else if(a%2!=0)
        {
            cout<<7;
            for(int i=1;i<a/3;i++)
            {
             cout<<1;
            }
            cout<<endl;
        }
    }
}

            // ll sum=0;
            // for(ll i=0;i<a/2;i++)
            // {
            //     sum=(sum*10)+1;
            // }
            // cout<<sum<<endl;

            // int sum=0;
            // for(int i=1;i<=a/3;i++)
            // {
            //     sum=(sum*10)+7;
            // }
            // cout<<sum<<endl;


#include <bits/stdc++.h>
using namespace std;
// To give an input string after a integer or double is taken input
//cin.ignore();			// better to use 2 times getline(cin,s);
#define pb push_back
#define mk make_pair
#define siz size()
#define endl "\n"
#define ll long long int
#define ld long double
void fast()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
}

int main(void)
{
    fast();
    ll n;
    cin>>n;
    while(n--)
    {
        ll a;
        cin>>a;
        if(a%2==0)
        {
            for(int i=0;i<a/2;i++)
            {
            cout<<1;
            }
         cout<<endl;
        }

        else if(a%2!=0)
        {
            cout<<7;
            for(int i=0;i<a/3;i++)
            {
             cout<<1;
            }
            cout<<endl;
        }
    }
}

            // ll sum=0;
            // for(ll i=0;i<a/2;i++)
            // {
            //     sum=(sum*10)+1;
            // }
            // cout<<sum<<endl;

            // int sum=0;
            // for(int i=1;i<=a/3;i++)
            // {
            //     sum=(sum*10)+7;
            // }
            // cout<<sum<<endl;


#include <bits/stdc++.h>
using namespace std;
// To give an input string after a integer or double is taken input
//cin.ignore();			// better to use 2 times getline(cin,s);
#define pb push_back
#define mk make_pair
#define siz size()
#define endl "\n"
#define ll long long int
#define ld long double
void fast()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
}

int main(void)
{
    fast();
    ll n;
    cin>>n;
    while(n--)
    {
        ll a;
        cin>>a;
        if(a%2==0)
        {
            for(int i=0;i<a/2;i++)
            {
            cout<<1;
            }
         cout<<endl;
        }

        else
        {
            for(int i=0;i<a/3;i++)
            {
             cout<<7;
            }
            cout<<endl;
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
// To give an input string after a integer or double is taken input
//cin.ignore();			// better to use 2 times getline(cin,s);
#define pb push_back
#define mk make_pair
#define siz size()
#define endl "\n"
#define ll long long int
#define ld long double
void fast()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
}

int main(void)
{
    fast();
    ll n;
    cin>>n;
    while(n--)
    {
        ll a;
        cin>>a;
        if(a%2==0)
        {
            ll sum=0;
            for(ll i=0;i<a/2;i++)
            {
                sum=(sum*10)+1;
            }
            cout<<sum<<endl;
        }
        else
        {
            int sum=0;
            for(int i=1;i<=a/3;i++)
            {
                sum=(sum*10)+7;
            }
            cout<<sum<<endl;
        }
    }
}


#include<iostream>
using namespace std;

int main(){
    int t;
    cin>>t;

    while(t--){
        int n;
        cin>>n;
        unsigned int number =0 ;
        if(n%2==0){
            while(n)
            {
                number +=1;
                number = number * 10;
                n=n-2;
            }
        }
        else {
            number += 7;
            number = number * 10;
            n=n-3;
            while(n)
            {
                number +=1;
                number = number * 10;
                n=n-2;
            }
        }
        printf("%d",number/10);
        if(t!=0){
            printf("\n");
        }
    }
}


#include<iostream>
using namespace std;
//no of segements
/* start from beging
0 : 0
1 : 0
2 : 1
3 : 7
4 :
5 : 2, 3 ,5
6 : 6 , 9
7 : 0 , 8
greedy idea :  in each segment pick the number with the largest number of segments it can fit

*/

int arrange(int n ){
    return 1;
}
int n ;
int number;
void prob_A(){
    cin >> n;
    number =0;
    if(n%2==0){
        while(n){
            number = number +1;
            number *=10;
            n = n-2;
        }
    }
    else {
        n = n-3;
        number = number +7;
        number = number * 10;
        while(n){
            number = number +1;
            number *=10;
            n = n-2;
        }
    }
    cout<<number/10;
}

int main()
{
    int t;
    cin >> t;
    while(t--)
        prob_A();

return 0 ;
}


#include<iostream>
using namespace std;

int main(){
    int t;
    cin>>t;

    while(t--){
        int n;
        cin>>n;
        int number =0 ;
        if(n%2==0){
            while(n)
            {
                number +=1;
                number = number * 10;
                n=n-2;
            }
        }
        else {
            number += 7;
            number = number * 10;
            n=n-3;
            while(n)
            {
                number +=1;
                number = number * 10;
                n=n-2;
            }
        }
        printf("%d\n",number/10);
    }
}


#include<iostream>
using namespace std;

int main(){
    int t;
    cin>>t;

    while(t--){
        int n;
        cin>>n;
        int number =0 ;
        if(n%2==0){
            while(n)
            {
                number +=1;
                number = number * 10;
                n=n-2;
            }
        }
        else {
            number += 7;
            number = number * 10;
            n=n-3;
            while(n)
            {
                number +=1;
                number = number * 10;
                n=n-2;
            }
        }
        printf("%d",number/10);
        if(t!=0){
            printf("\n");
        }
    }
}


#include<iostream>
using namespace std;

int main(){
    int t;
    cin>>t;

    while(t--){
        int n;
        cin>>n;
        unsigned long long  number =0 ;
        if(n%2==0){
            while(n)
            {
                cout<<"1";
                n=n-2;
            }
        }
        else {
            cout<<"7";
            n=n-3;
            while(n)
            {
                cout<<"1";
                n=n-2;
            }
        }

        if(t!=0){
            printf("\n");
        }
    }
}


#include<iostream>
using namespace std;
//no of segements
/* start from beging
0 : 0
1 : 0
2 : 1
3 : 7
4 :
5 : 2, 3 ,5
6 : 6 , 9
7 : 0 , 8
greedy idea :  in each segment pick the number with the largest number of segments it can fit

*/

int arrange(int n ){
    return 1;
}
int n ;
int number;
void prob_A(){
    cin >> n;
    number =0;
    if(n%2==0){
        while(n){
            number = number +1;
            number *=10;
            n = n-2;
        }
    }
    else {
        n = n-3;
        number = number +7;
        number = number * 10;
        while(n){
            number = number +1;
            number *=10;
            n = n-2;
        }
    }
    cout<<number/10<<endl;
}

int main()
{
    int t;
    cin >> t;
    while(t--)
        prob_A();

return 0 ;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long int n;
    cin >> n;
    long long int i, j;
    for (i = 0; i < n; i++)
    {
        long long int m;
        long long int p = m;
        cin >> m;

        if (m % 2 == 0)
        {
            while (m >= 2)
            {
                cout << "1";
                m -= 2;
            }
            cout << endl;
        }
        else
        {
            cout << "7";
            m -= 3;
            while (m >= 2)
            {
                cout << "1";
                m - 2;
            }
            cout << endl;
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long int n;
    cin>>n;
    long long int i,j;
    for(i=0;i<n;i++){
        long long int m;
        long long int p=m;
        cin>>m;
        if(m>18){
            m-=18;
            long long int nine=0;
            long long int seven=0;
            while(m>0){
                nine++;
                m-=5;
            }
            if(m<0){
                nine--;
                m+=5;
                while(m>0){
                    seven++;
                    m-=2;
                }
                if(m<0){
                    seven--;
                    m+=2;
                }

            }
            long long int ans=0;
            for(j=0;j<nine;j++){
                ans=ans*10+9;
            }
            for(j=0;j<seven;j++){
                ans=ans*10+7;
            }
            p=9-seven+nine;
            for(j=0;j<p;j++){
                ans=ans*10+1;
            }
            // if(ans>998244353){
            //     cout<<998244353<<endl;
            // }
            // else{
                cout<<ans<<endl;
            // }
        }
        else{
            if(m%2==0){
                while(m>0){
                    cout<<"1";
                    m-=2;
                }
                cout<<endl;
            }
            else{
                cout<<"7";
                m-=3;
                while(m>0){
                    cout<<"1";
                    m-2;
                }
                cout<<endl;
            }
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long int n;
    cin>>n;
    long long int i,j;
    for(i=0;i<n;i++){
        long long int m;
        long long int p=m;
        cin>>m;
        if(m>18){
            m-=18;
            long long int nine=0;
            long long int seven=0;
            while(m>0){
                nine++;
                m-=5;
            }
            if(m<0){
                nine--;
                m+=5;
                while(m>0){
                    seven++;
                    m-=2;
                }
                if(m<0){
                    seven--;
                    m+=2;
                }

            }
            long long int ans=0;
            for(j=0;j<nine;j++){
                ans=ans*10+9;
            }
            for(j=0;j<seven;j++){
                ans=ans*10+7;
            }
            p=9-seven+nine;
            for(j=0;j<p;j++){
                ans=ans*10+1;
            }
            // if(ans>998244353){
            //     cout<<998244353<<endl;
            // }
            // else{
                cout<<ans<<endl;
            // }
        }
        else{
            if(m%2==0){
                while(m>2){
                    cout<<"1";
                    m-=2;
                }
                cout<<endl;
            }
            else{
                cout<<"7";
                m-=3;
                while(m>2){
                    cout<<"1";
                    m-2;
                }
                cout<<endl;
            }
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long int n;
    cin>>n;
    long long int i,j;
    for(i=0;i<n;i++){
        long long int m;
        long long int p=m;
        cin>>m;
        if(m>18){
            m-=18;
            long long int nine=0;
            long long int seven=0;
            while(m>0){
                nine++;
                m-=5;
            }
            if(m<0){
                nine--;
                m+=5;
                while(m>0){
                    seven++;
                    m-=2;
                }
                if(m<0){
                    seven--;
                    m+=2;
                }

            }
            long long int ans=0;
            for(j=0;j<nine;j++){
                ans=ans*10+9;
            }
            for(j=0;j<seven;j++){
                ans=ans*10+7;
            }
            p=9-seven+nine;
            for(j=0;j<p;j++){
                ans=ans*10+1;
            }
            if(ans>998244353){
                cout<<998244353<<endl;
            }
            else{
                cout<<ans<<endl;
            }
        }
        else{
            if(m%2==0){
                while(m>0){
                    cout<<"1";
                    m-=2;
                }
                cout<<endl;
            }
            else{
                cout<<"7";
                m-=3;
                while(m>0){
                    cout<<"1";
                    m--;
                }
                cout<<endl;
            }
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long int n;
    cin >> n;
    long long int i, j;
    for (i = 0; i < n; i++)
    {
        long long int m;
        long long int p = m;
        cin >> m;

        if (m % 2 == 0)
        {
            for(j=0;j<m/2;j++){
                cout<<"1";
            }
            cout << endl;
        }
        else
        {
            cout << "7";
            m -= 3;
            for(j=0;j<m/2;j++){
                cout<<"1";
            }
            cout << endl;
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long int n;
    cin>>n;
    long long int i,j;
    for(i=0;i<n;i++){
        long long int m;
        long long int p=m;
        cin>>m;
        if(m>18){
            m-=18;
            long long int nine=0;
            long long int seven=0;
            while(m>0){
                nine++;
                m-=5;
            }
            if(m<0){
                nine--;
                m+=5;
                while(m>0){
                    seven++;
                    m-=2;
                }
                if(m<0){
                    seven--;
                    m+=2;
                }

            }
            long long int ans=0;
            for(j=0;j<nine;j++){
                ans=ans*10+9;
            }
            for(j=0;j<seven;j++){
                ans=ans*10+7;
            }
            p=9-seven+nine;
            for(j=0;j<p;j++){
                ans=ans*10+1;
            }
            // if(ans>998244353){
            //     cout<<998244353<<endl;
            // }
            // else{
                cout<<ans<<endl;
            // }
        }
        else{
            if(m%2==0){
                while(m>0){
                    cout<<"1";
                    m-=2;
                }
                cout<<endl;
            }
            else{
                cout<<"7";
                m-=3;
                while(m>0){
                    cout<<"1";
                    m--;
                }
                cout<<endl;
            }
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int i,j;
    for(i=0;i<n;i++){
        int m;
        int p=m;
        cin>>m;
        if(m>18){
            m-=18;
            int nine=0;
            int seven=0;
            while(m>0){
                nine++;
                m-=5;
            }
            if(m<0){
                nine--;
                m+=5;
                while(m>0){
                    seven++;
                    m-=2;
                }
                if(m<0){
                    seven--;
                    m+=2;
                }

            }
            int ans=0;
            for(j=0;j<nine;j++){
                ans=ans*10+9;
            }
            for(j=0;j<seven;j++){
                ans=ans*10+7;
            }
            p-=seven+nine;
            for(j=0;j<p;j++){
                ans=ans*10+1;
            }
            if(ans>998244353){
                cout<<998244353<<endl;
            }
            else{
                cout<<ans<<endl;
            }
        }
        else{
            if(m%2==0){
                while(m>0){
                    cout<<"1";
                    m-=2;
                }
                cout<<endl;
            }
            else{
                cout<<"7";
                m-=3;
                while(m>0){
                    cout<<"1";
                    m--;
                }
                cout<<endl;
            }
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long int n;
    cin>>n;
    long long int i,j;
    for(i=0;i<n;i++){
        long long int m;
        long long int p=m;
        cin>>m;
        if(m>18){
            m-=18;
            long long int nine=0;
            long long int seven=0;
            while(m>0){
                nine++;
                m-=5;
            }
            if(m<0){
                nine--;
                m+=5;
                while(m>0){
                    seven++;
                    m-=2;
                }
                if(m<0){
                    seven--;
                    m+=2;
                }

            }
            long long int ans=0;
            for(j=0;j<nine;j++){
                ans=ans*10+9;
            }
            for(j=0;j<seven;j++){
                ans=ans*10+7;
            }
            p=9-seven+nine;
            for(j=0;j<p;j++){
                ans=ans*10+1;
            }
            // if(ans>998244353){
            //     cout<<998244353<<endl;
            // }
            // else{
                cout<<ans<<endl;
            // }
        }
        else{
            if(m%2==0){
                while(m>=2){
                    cout<<"1";
                    m-=2;
                }
                cout<<endl;
            }
            else{
                cout<<"7";
                m-=3;
                while(m>=2){
                    cout<<"1";
                    m-2;
                }
                cout<<endl;
            }
        }
    }
}


#import<iostream>
using namespace std;main(int n){for(cin>>n;cin>>n;)cout<<"71"[n&1]+string(n/2-1,49)+" ";}


#import<iostream>
using namespace std;main(int n){for(cin>>n;cin>>n;)cout<<(n&1?"7\n":"1\n")+(n>3?string(n/2-1,'1'):"");}


#import<iostream>
using namespace std;main(int n){for(cin>>n;cin>>n;)cout<<"17"[n&1]+string(n/2-1,49)+" ";}


#import<iostream>
using namespace std;main(int n){for(cin>>n;cin>>n;)cout<<(n>3?string(n/2-1,'1'):"")+(n&1?"7\n":"1\n");}


#import<iostream>
using namespace std;main(int n){for(cin>>n;cin>>n;)cout<<(n&1?"7":"1")+string(n/2-1,'1')+" ";}


#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define danon ios_base::sync_with_stdio(false); cin.tie(); cout.tie();
#define ll long long
#define ld long double
#define pb push_back
typedef vector<int> vi;
typedef vector<string> vs;
const int inf=(int)1e9;
const int lyam=(int)1e6;
const int N=(int)1e5;
ll n,a[lyam],mx1,sum=1,res,d[lyam];
	vs v;
int main() {
	cin>>n;
	v.pb("0");
	v.pb("0");
	v.pb("1");
	v.pb("7");
	v.pb("11");
	string s="7",s1="1";
	for(int i=4;i<=N;i+=2)
	{  s=s+s1;
	   v.pb(s);
	   v.pb(s);
	  // v[i+1]=s;
	}
	for(int i=1;i<=n;i++)
	{ cin>>a[i];
	    cout<<v[a[i]]<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define danon ios_base::sync_with_stdio(false); cin.tie(); cout.tie();
#define ll long long
#define ld long double
#define pb push_back
typedef vector<int> vi;
typedef vector<string> vs;
const int inf=(int)1e9;
const int lyam=(int)1e6;
const int N=(int)1e5;
ll n,a[lyam],mx1,d[lyam];
	vs v;
int main() {
	cin>>n;
	string s="7",s1="1",s2="1";
	for(int i=1;i<=n;i++)
	{ cin>>a[i];

	ll sum=3;
	   if(a[i]%2!=0 ){
	   	if (a[i]==3)
	   	cout<<7<<endl;
	   	else {
	   while(sum+2<=a[i]) {
	   s=s+s1;
	   sum+=2;}
	   cout<<s<<endl;
       }
   }
       else if(a[i]%2==0){
       	sum=2;
	  while (sum+2<=a[i]){
	   s2+=s1;
	   sum+=2;

       }cout<<s2<<endl;}
       s="7";
       s2="1";	}
}


#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define danon ios_base::sync_with_stdio(false); cin.tie(); cout.tie();
#define ll long long
#define ld long double
#define pb push_back
typedef vector<int> vi;
typedef vector<string> vs;
const int inf=(int)1e9;
const int lyam=(int)1e6;
const int N=(int)1e5;
ll n,a[lyam],mx1,sum=1,res,d[lyam];
	vs v;
int main() {
	cin>>n;
	//v.pb("0");
	//v.pb("0");
	//v.pb("1");
	//v.pb("7");
	//v.pb("11");
	string s="71",s1="1";
/*	for(int i=4;i<=N;i+=2)
	{  s=s+s1;
	   v.pb(s);
	   v.pb(s);
	  // v[i+1]=s;
	}*/
	for(int i=1;i<=n;i++)
	{ cin>>a[i];
	if (a[i]==2)
	cout<<1<<endl;
	else if (a[i]==3)
	cout<<7<<endl;
	else if (a[i]==4)
	cout<<11<<endl;
	else if (a[i]-6<=0)
	cout<<71<<endl;

	 else if(a[i]%2!=0 ){
	   for(int j=1;j<=(a[i]-4)/2;j++)
	   s=s+s1;
	   cout<<s<<endl;
       }
       else if(a[i]%2==0){
	   for(int j=1;j<=a[i]-6;j++)
	   s=s+s1;
	   cout<<s<<endl;
       }
       s="71";
	}
}


#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define danon ios_base::sync_with_stdio(false); cin.tie(); cout.tie();
#define ll long long
#define ld long double
#define pb push_back
typedef vector<int> vi;
typedef vector<string> vs;
const int inf=(int)1e9;
const int lyam=(int)1e6;
const int N=(int)1e5;
ll n,a[lyam],mx1,d[lyam];
	vs v;
int main() {
	cin>>n;
	string s="7",s1="1",s2="1";
	for(int i=1;i<=n;i++)
	{ cin>>a[i];

	ll sum=3;
	   if(a[i]%2!=0 ){
	   	if (a[i]==3)
	   	cout<<7<<endl;
	   	else {
	   while(sum+2<=a[i]) {
	   s=s+s1;
	   sum+=2;}
	   cout<<s<<endl;
       }
   }
       else if(a[i]%2==0){
       	sum=2;
	  while (sum+2<=a[i]){
	   s2+=s1;
	   sum+=2;

       }cout<<s2<<endl;}
       s="71";
       s2="1";	}
}


#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define danon ios_base::sync_with_stdio(false); cin.tie(); cout.tie();
#define ll long long
#define ld long double
#define pb push_back
typedef vector<int> vi;
typedef vector<string> vs;
const int inf=(int)1e9;
const int lyam=(int)1e6;
const int N=(int)1e5;
ll n,a[lyam],mx1,sum=1,res,d[lyam];
	vector<pair<ll,ll> > v;
int main() {
	cin>>n;
	d[2]=1;
	for(int i=3;i<=N;i++)
	{if (i%2==1)
	  d[i]=d[i-1]+6;
	  else d[i]=d[i-1]+4;
	}
	for(int i=1;i<=n;i++)
	{ cin>>a[i];
	   cout<<d[a[i]]<<endl;
    }

}


#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define danon ios_base::sync_with_stdio(false); cin.tie(); cout.tie();
#define ll long long
#define ld long double
#define pb push_back
typedef vector<int> vi;
typedef vector<string> vs;
const int inf=(int)1e9;
const int lyam=(int)1e6;
const int N=(int)1e5;
ll n,a[lyam],mx1,sum=1,res,d[lyam];
	vs v;
int main() {
	cin>>n;
	string s="71",s1="1",s2="1";
	for(int i=1;i<=n;i++)
	{ cin>>a[i];
	if (a[i]==2)
	cout<<1<<endl;
	else if (a[i]==3)
	cout<<7<<endl;
	else if (a[i]==4)
	cout<<11<<endl;
	else if (a[i]-6<=0)
	cout<<71<<endl;

	 else if(a[i]%2!=0 ){
	   for(int j=1;j<=(a[i]-4)/2;j++)
	   s=s+s1;
	   cout<<s<<endl;
       }
       else if(a[i]%2==0){
	   for(int j=1;j<=a[i]-4;j++)
	   s2+=s1;
	   cout<<s2<<endl;
       }
       s="71";
       s2="1";	}
}


#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define danon ios_base::sync_with_stdio(false); cin.tie(); cout.tie();
#define ll long long
#define ld long double
#define pb push_back
typedef vector<int> vi;
typedef vector<string> vs;
const int inf=(int)1e9;
const int lyam=(int)1e6;
const int N=(int)1e5;
ll n,a[lyam],mx1,d[lyam];
	vs v;
int main() {
	cin>>n;
	string s="7",s1="1",s2="1";
	for(int i=1;i<=n;i++)
	{ cin>>a[i];

	ll sum=3;
	   if(a[i]%2!=0 ){
	   	if (a[i]==3)
	   	cout<<7;
	   	else {
	   while(sum+2<=a[i]) {
	   s=s+s1;
	   sum+=2;}
	   cout<<s<<endl;
       }
   }
       else if(a[i]%2==0){
       	sum=2;
	  while (sum+2<=a[i]){
	   s2+=s1;
	   sum+=2;

       }cout<<s2<<endl;}
       s="71";
       s2="1";	}
}


#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define danon ios_base::sync_with_stdio(false); cin.tie(); cout.tie();
#define ll long long
#define ld long double
#define pb push_back
typedef vector<int> vi;
typedef vector<string> vs;
const int inf=(int)1e9;
const int lyam=(int)1e6;
const int N=(int)1e5;
ll n,a[lyam],mx1,d[lyam];
	vs v;
int main() {
	cin>>n;
	string s="7",s1="1",s2="1";
	for(int i=1;i<=n;i++)
	{ cin>>a[i];

	ll sum=3;
	   if(a[i]%2!=0 ){

	   while(sum+2<=a[i]) {
	   s=s+s1;
	   sum+=2;}
	   cout<<s<<endl;
       }
       else if(a[i]%2==0){
       	sum=2;
	  while (sum+2<=a[i]){
	   s2+=s1;
	   sum+=2;

       }cout<<s2<<endl;}
       s="71";
       s2="1";	}
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define debug(x) cout<<#x<<" "<<x<<endl
typedef pair<int,int> pi;
#define F first
#define S second
inline void solve()
{
   int n;
   cin >> n;
   int num = 0;
   if(n == 3)
   {cout << 7 << '\n'; return;}
   while(n % 2 == 0 && num <= 998244353)
    n /= 2 , num = num*10 + 1;

  cout << num << '\n';

}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int TestCases = 1;
    cin >> TestCases;
    while(TestCases--)
       solve();
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define debug(x) cout<<#x<<" "<<x<<endl
typedef pair<int,int> pi;
#define F first
#define S second
inline void solve()
{
   int n;
   cin >> n;
   int num = 0;
   if(n == 3)
   {cout << 7 << '\n'; return;}
   while(n > 0 && num <= 998244353)
    n /= 2 , num = num*10 + 1;

  cout << num << '\n';

}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int TestCases = 1;
    cin >> TestCases;
    while(TestCases--)
       solve();
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define debug(x) cout<<#x<<" "<<x<<endl
typedef pair<int,int> pi;
#define F first
#define S second
inline void solve()
{
   int n;
   cin >> n;
   string num = "";
   if(n == 3)
   {cout << 7 << '\n'; return;}
   while(n > 1 && num.size() <= 998244353)
    n /= 2 , num += '1';

  cout << num << '\n';

}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int TestCases = 1;
    cin >> TestCases;
    while(TestCases--)
       solve();
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define debug(x) cout<<#x<<" "<<x<<endl
typedef pair<int,int> pi;
#define F first
#define S second
inline void solve()
{
   int n;
   cin >> n;
   if(n == 3)
   {cout << 7 << '\n'; return;}
   while(n % 2 == 0)
    n /= 2 , cout << "1";
  cout << '\n';

}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int TestCases = 1;
    cin >> TestCases;
    while(TestCases--)
       solve();
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define debug(x) cout<<#x<<" "<<x<<endl
typedef pair<int,int> pi;
#define F first
#define S second
inline void solve()
{
   int n;
   cin >> n;
   string num = "";
   if(n & 1)
    num += '7' , n -= 3;
   /// n is even at this line -> full utilization of n -> maximum number
   while(n > 0)
    num += '1' , n -= 2;

  cout << num << '\n';

}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int TestCases = 1;
    cin >> TestCases;
    while(TestCases--)
       solve();
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define debug(x) cout<<#x<<" "<<x<<endl
typedef pair<int,int> pi;
#define F first
#define S second
inline void solve()
{
   int n;
   cin >> n;
   string num = "";
   if(n == 3)
   {cout << 7 << '\n'; return;}
   while(n > 1 && num.size() <= 998244353)
    n -= 2 , num += '1';

  cout << num << '\n';

}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int TestCases = 1;
    cin >> TestCases;
    while(TestCases--)
       solve();
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define debug(x) cout<<#x<<" "<<x<<endl
typedef pair<int,int> pi;
#define F first
#define S second
inline void solve()
{
   int n;
   cin >> n;
   int num = 0;
   if(n == 3)
   {cout << 7 << '\n'; return;}
   while(n > 1 && num <= 998244353)
    n /= 2 , num = num*10 + 1;

  cout << num << '\n';

}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int TestCases = 1;
    cin >> TestCases;
    while(TestCases--)
       solve();
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b,i,s=0,k;
    cin>>n;
    for(i=1; i<=n; i++)
    {
        s=0;
        cin>>a;
        if(a%2==0)
        {
            k=a/2;
            for(int y=0; y<k; y++)
            {
                cout<<"1";
            }
        }
        else
        {
            if(a%2!=0)
                k = (a-3)/2;
            if(k==0)
                cout<<"7"<<endl;
            else
            {
                for(b=1; b<=a; b++)
                {
                    cout<<"1";
                }
            }

        }

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b,i,s=0;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        s=0;
        cin>>a;
        for(b=1;b<=a;b++)
        {
            cout<<"1"<<endl;
        }

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b,i,s=0,k;
    cin>>n;
    for(i=1; i<=n; i++)
    {
        s=0;
        cin>>a;
        if(a%2==0)
        {
            k=a/2;
            for(int y=0; y<k; y++)
            {
                cout<<"1";
            }
        }
        else if(a%2!=0)
        {
            k = (a-3)/2;
            cout<<"7"<<endl;
            for(b=1; b<=k; b++)
            {
                cout<<"1";
            }
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b,i,s=0,k;
    cin>>n;
    for(i=1; i<=n; i++)
    {
        s=0;
        cin>>a;
        if(a%2==0)
        {
            k=a/2;
            for(int y=0; y<k; y++)
            {
                cout<<"1";
            }
        }
        else
        {
            if(a%2!=0)
                k = (a-3)/2;
                cout<<"7"<<endl;
                for(b=1; b<=a; b++)
                {
                    cout<<"1";
                }
            }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b,i,s=0,k;
    cin>>n;
    for(i=1; i<=n; i++)
    {
        s=0;
        cin>>a;
        if(a%2==0)
        {
            k=a/2;
            for(int y=0; y<k; y++)
            {
                cout<<"1";
            }
        }
        else if(a%2!=0)
        {
            k = (a-3)/2;
            cout<<"7";
            for(b=1; b<=k; b++)
            {
                cout<<"1";
            }
        }
        cout<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b,i,s=0;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        s=0;
        cin>>a;
        for(b=1;b<=a;b++)
        {
            s+=b;
        }
        cout<<s+1<<endl;

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b,i,s=0,k;
    cin>>n;
    for(i=1; i<=n; i++)
    {
        s=0;
        cin>>a;
        if(a%2==0)
        {
            k=a/2;
            for(int y=0; y<k; y++)
            {
                cout<<"1";
            }
        }
        else if(a%2!=0)
        {
            k = (a-3)/2;
            cout<<"7";
            for(b=1; b<=k; b++)
            {
                cout<<"1";
            }
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b,i,s=0,k;
    cin>>n;
    for(i=1; i<=n; i++)
    {
        s=0;
        cin>>a;
        if(a%2==0)
        {
            k=a/2;
            for(int y=0; y<k; y++)
            {
                cout<<"1";
            }
        }
        elseif(a%2!=0)
        {
            k = (a-3)/2;
            cout<<"7"<<endl;
            for(b=1; b<=k; b++)
            {
                cout<<"1";
            }
        }
    }
    return 0;
}


//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define l long
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<int,int>
#define maxn 100005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;

signed main()
{
    fast;
    #ifndef ONLINE_JUDGE
	freopen("input.txt","r", stdin);
    freopen("output.txt","w",stdout);
    #endif
    int t;
    cin>>t;
    while(t--)
    {
    	ll n,i,j;
    	cin>>n;
    	if(n<4) cout<<"7"<<"\n";
    	else
    	{
    		if(n%2==1) cout<<"7";
    		for(i=0;i<(n/2 - n%2);i++) cout<<"1";
    		cout<<"\n";
    	}
    }
}


//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define l long
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<int,int>
#define maxn 100005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;

signed main()
{
    fast;
    #ifndef ONLINE_JUDGE
	freopen("input.txt","r", stdin);
    freopen("output.txt","w",stdout);
    #endif
    int t;
    cin>>t;
    while(t--)
    {
    	ll n,i,j;
    	cin>>n;
    	if(n<4) cout<<"7"<<"\n";
    	else
    	{
    		for(i=0;i<(n - n%2);i++) cout<<"1";
    		cout<<"\n";
    	}
    }
}


//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define l long
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<int,int>
#define maxn 100005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;

signed main()
{
    fast;
    #ifndef ONLINE_JUDGE
	freopen("input.txt","r", stdin);
    freopen("output.txt","w",stdout);
    #endif
    int t;
    cin>>t;
    while(t--)
    {
    	ll n,i,j;
    	cin>>n;
    	if(n<4) cout<<"7"<<"\n";
    	else
    	{
    		for(i=0;i<n/2;i++) cout<<"1";
    		cout<<"\n";
    	}
    }
}


//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define l long
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<int,int>
#define maxn 100005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;

signed main()
{
    fast;
    #ifndef ONLINE_JUDGE
	freopen("input.txt","r", stdin);
    freopen("output.txt","w",stdout);
    #endif
    int t;
    cin>>t;
    while(t--)
    {
    	ll n,i,j;
    	cin>>n;
    	if(n==2) cout<<"1"<<"\n";
    	else if(n<4) cout<<"7"<<"\n";
    	else
    	{
    		if(n%2==1) cout<<"7";
    		for(i=0;i<(n/2 - n%2);i++) cout<<"1";
    		cout<<"\n";
    	}
    }
}


//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define l long
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<int,int>
#define maxn 100005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;

signed main()
{
    fast;
    #ifndef ONLINE_JUDGE
	freopen("input.txt","r", stdin);
    freopen("output.txt","w",stdout);
    #endif
    int t;
    cin>>t;
    while(t--)
    {
    	ll ma[100],n,i,j;
    	ma[0] = 6;
    	ma[1] = 2;
    	ma[2] = 5;
    	ma[3] = 5;
    	ma[4] = 4;
    	ma[5] = 5;
    	ma[6] = 6;
    	ma[7] = 3;
    	ma[8] = 7;
    	ma[9] = 6;
    	cin>>n;
    	string ans;
    	while(n>0) {
    	bool ok = false;
    	for(i=9;i>=1;i--)
    	{
    		for(j=9;j>=1;j--)
    		{
    			if(ma[i]+ma[j]<=n)
    			{
    				ll gr = max(i,j);
    				ll sm = min(i,j);
    				n -= ma[i]+ma[j];
    				ok = true;
    				ans.pb('0'+gr);
    				ans.pb('0'+sm);
    				break;
    			}
    		}
    		if(ok) break;
    	}
    	if(!ok) break;
        }
    	for(i=9;i>=1;i--)
    	{
    		if(ma[i]<=n)
    		{
    			ans.pb(i+'0');
    			break;
    		}
    	}
    	cout<<ans<<"\n";
    }
}


//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define l long
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<int,int>
#define maxn 100005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;

signed main()
{
    fast;
    #ifndef ONLINE_JUDGE
	freopen("input.txt","r", stdin);
    freopen("output.txt","w",stdout);
    #endif
    int t;
    cin>>t;
    while(t--)
    {
    	ll n,i,j;
    	cin>>n;
    	if(n==2) cout<<"1"<<"\n";
    	if(n<4) cout<<"7"<<"\n";
    	else
    	{
    		if(n%2==1) cout<<"7";
    		for(i=0;i<(n/2 - n%2);i++) cout<<"1";
    		cout<<"\n";
    	}
    }
}


#include <iostream>
using namespace std;

int main() {
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		if(n>19)
		cout<<998244353<<endl;
		else{
			if(n%2==0)cout<<1; else cout<<7;
			for(int i=0;i<n/2-1;i++)
			cout<<1;
			cout<<endl;
		}

	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long hey;
#define hi string
#define PI 3.14
#define f first
#define mod 1000000007
#define s second
#define pb push_back
#define pop pop_back
#define bs binary_search
#define mp make_pair
#define vi vector < hey >
#define all(v) v.begin(),v.end()
#define q priority_queue< hey >
#define endl '\n'
#define forn(i, n) for (hey i = 0; i <hey(n); ++i)
#define yorn(i, n) for (hey i = 1; i <hey(n); ++i)
#define vp vector< pair<hey,hey> >
void sabmohmayahei()
{
    hey aa;
    cin>>aa;
    if(aa%2==0)
    {
        forn(i,aa/2)
        cout<<1;
    }
    else
    {
        cout<<7;
        forn(i,aa/2-1)
        cout<<1;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t=1;
	cin>>t;
	while(t--)
	{
	    sabmohmayahei();
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long hey;
#define hi string
#define PI 3.14
#define f first
#define mod 1000000007
#define s second
#define pb push_back
#define pop pop_back
#define bs binary_search
#define mp make_pair
#define vi vector < hey >
#define all(v) v.begin(),v.end()
#define q priority_queue< hey >
#define endl '\n'
#define forn(i, n) for (hey i = 0; i <hey(n); ++i)
#define yorn(i, n) for (hey i = 1; i <hey(n); ++i)
#define vp vector< pair<hey,hey> >
void sabmohmayahei()
{
    hey aa;
    cin>>aa;
    if(aa%2==0)
    {
        forn(i,aa/2)
        cout<<1;
    }
    else
    {
        cout<<7;
        forn(i,aa/2-1)
        cout<<1;
    }
    cout<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t=1;
	cin>>t;
	while(t--)
	{
	    sabmohmayahei();
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long int       lint;
typedef vector<int>         vi;
typedef vector<lint>        vl;
typedef pair<int, int>      pii;
typedef vector<pii>         vii;
typedef set<int>            si;
typedef map<string, int>    msi;

#define pb(n)           push_back(n)
#define ALL(n)          (n.begin(), n.end())
#define db(a)           cout<<#a<<" = "<<a<<endl;
#define FIN             freopen("in.txt","r",stdin);
#define FOUT            freopen("out.txt","w",stdout);
#define M               10000000
#define MOD             10000007
#define INF             1e9+7
#define REP(i,a,b)      for(int i = int(a); i <= int(b); i++)
#define REPL(i,a,b)     for(lint i = lint(a); i <= lint(b); i++)
#define fastIO()        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main()
{
	fastIO();

	int seg, n;
	cin>>seg;

	if(seg == 2) cout<<1<<endl;
	else if(seg == 3) cout<<7<<endl;
	else{
		seg /= 4;
		REP(i, 1, seg){
			cout<<11;
		}
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long int       lint;
typedef vector<int>         vi;
typedef vector<lint>        vl;
typedef pair<int, int>      pii;
typedef vector<pii>         vii;
typedef set<int>            si;
typedef map<string, int>    msi;

#define pb(n)           push_back(n)
#define ALL(n)          (n.begin(), n.end())
#define db(a)           cout<<#a<<" = "<<a<<endl;
#define FIN             freopen("in.txt","r",stdin);
#define FOUT            freopen("out.txt","w",stdout);
#define M               10000000
#define MOD             10000007
#define INF             1e9+7
#define REP(i,a,b)      for(int i = int(a); i <= int(b); i++)
#define REPL(i,a,b)     for(lint i = lint(a); i <= lint(b); i++)

int main()
{
	int seg, kase;
	cin>>kase;
	while(kase--){

		cin>>seg;

		if(seg == 2) cout<<1<<endl;
		else if(seg == 3) cout<<7<<endl;
		else{
			if(seg % 4 == 2) cout<<1;
			else if(seg % 4 == 3) cout<<7;
			seg /= 4;
			REP(i, 1, seg){
				cout<<11;
			}
			cout<<endl;
		}
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long int       lint;
typedef vector<int>         vi;
typedef vector<lint>        vl;
typedef pair<int, int>      pii;
typedef vector<pii>         vii;
typedef set<int>            si;
typedef map<string, int>    msi;

#define pb(n)           push_back(n)
#define ALL(n)          (n.begin(), n.end())
#define db(a)           cout<<#a<<" = "<<a<<endl;
#define FIN             freopen("in.txt","r",stdin);
#define FOUT            freopen("out.txt","w",stdout);
#define M               10000000
#define MOD             10000007
#define INF             1e9+7
#define REP(i,a,b)      for(int i = int(a); i <= int(b); i++)
#define REPL(i,a,b)     for(lint i = lint(a); i <= lint(b); i++)

int main()
{
	int seg, kase;
	cin>>kase;
	while(kase--){

		cin>>seg;

		if(seg == 2) cout<<1<<endl;
		else if(seg == 3) cout<<7<<endl;
		else{
			if(seg % 2 == 0) cout<<1;
			else if(seg % 3 == 0) cout<<7;
			seg /= 4;
			REP(i, 1, seg){
				cout<<11;
			}
			cout<<endl;
		}
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long int       lint;
typedef vector<int>         vi;
typedef vector<lint>        vl;
typedef pair<int, int>      pii;
typedef vector<pii>         vii;
typedef set<int>            si;
typedef map<string, int>    msi;

#define pb(n)           push_back(n)
#define ALL(n)          (n.begin(), n.end())
#define db(a)           cout<<#a<<" = "<<a<<endl;
#define FIN             freopen("in.txt","r",stdin);
#define FOUT            freopen("out.txt","w",stdout);
#define M               10000000
#define MOD             10000007
#define INF             1e9+7
#define REP(i,a,b)      for(int i = int(a); i <= int(b); i++)
#define REPL(i,a,b)     for(lint i = lint(a); i <= lint(b); i++)
#define fastIO()        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main()
{
	int seg, kase;
	cin>>kase;
	while(kase--){

		cin>>seg;

		if(seg == 3) cout<<7<<endl;
		else{
			if(seg % 2 == 1){
				seg -= 3;
				cout<<7;
			}
			for(int i = 1; i <= seg; i += 2){
				cout<<1;
			}
			cout<<endl;
		}
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long int       lint;
typedef vector<int>         vi;
typedef vector<lint>        vl;
typedef pair<int, int>      pii;
typedef vector<pii>         vii;
typedef set<int>            si;
typedef map<string, int>    msi;

#define pb(n)           push_back(n)
#define ALL(n)          (n.begin(), n.end())
#define db(a)           cout<<#a<<" = "<<a<<endl;
#define FIN             freopen("in.txt","r",stdin);
#define FOUT            freopen("out.txt","w",stdout);
#define M               10000000
#define MOD             10000007
#define INF             1e9+7
#define REP(i,a,b)      for(int i = int(a); i <= int(b); i++)
#define REPL(i,a,b)     for(lint i = lint(a); i <= lint(b); i++)
#define fastIO()        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main()
{
	int seg, kase;
	cin>>kase;
	while(kase--){

		cin>>seg;

		int n = seg % 4;

		if(n == 0){
			while(seg){
				cout<<11;
				seg -= 4;
			}
			printf("\n");
		}
		else if(n == 1){
			cout<<5;
			seg -= 5;
			while(seg){
				cout<<11;
				seg -= 4;
			}
			printf("\n");
		}
		else if(n == 2){
			cout<<1;
			seg -= 2;
			while(seg){
				cout<<11;
				seg -= 4;
			}
			printf("\n");
		}
		else if(n == 3){
			cout<<7;
			seg -= 3;
			while(seg){
				cout<<11;
				seg -= 4;
			}
			printf("\n");
		}
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long int       lint;
typedef vector<int>         vi;
typedef vector<lint>        vl;
typedef pair<int, int>      pii;
typedef vector<pii>         vii;
typedef set<int>            si;
typedef map<string, int>    msi;

#define pb(n)           push_back(n)
#define ALL(n)          (n.begin(), n.end())
#define db(a)           cout<<#a<<" = "<<a<<endl;
#define FIN             freopen("in.txt","r",stdin);
#define FOUT            freopen("out.txt","w",stdout);
#define M               10000000
#define MOD             10000007
#define INF             1e9+7
#define REP(i,a,b)      for(int i = int(a); i <= int(b); i++)
#define REPL(i,a,b)     for(lint i = lint(a); i <= lint(b); i++)
#define fastIO()        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main()
{
	int seg, kase;
	cin>>kase;
	while(kase--){

		cin>>seg;

		int n = seg % 4;

		if(n == 0){
			for(int i = seg; i >= 0; i -= 4){
				cout<<1;
			}
			printf("\n");
		}
		else if(n == 1){
			cout<<5;
			seg -= 5;
			for(int i = seg; i >= 0; i -= 4){
				cout<<1;
			}
			printf("\n");
		}
		else if(n == 2){
			cout<<1;
			seg -= 2;
			for(int i = seg; i >= 0; i -= 4){
				cout<<1;
			}
			printf("\n");
		}
		else if(n == 3){
			cout<<7;
			seg -= 3;
			for(int i = seg; i >= 0; i -= 4){
				cout<<1;
			}
			printf("\n");
		}
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long int       lint;
typedef vector<int>         vi;
typedef vector<lint>        vl;
typedef pair<int, int>      pii;
typedef vector<pii>         vii;
typedef set<int>            si;
typedef map<string, int>    msi;

#define pb(n)           push_back(n)
#define ALL(n)          (n.begin(), n.end())
#define db(a)           cout<<#a<<" = "<<a<<endl;
#define FIN             freopen("in.txt","r",stdin);
#define FOUT            freopen("out.txt","w",stdout);
#define M               10000000
#define MOD             10000007
#define INF             1e9+7
#define REP(i,a,b)      for(int i = int(a); i <= int(b); i++)
#define REPL(i,a,b)     for(lint i = lint(a); i <= lint(b); i++)
#define fastIO()        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main()
{
	int seg, kase;
	cin>>kase;
	while(kase--){

		cin>>seg;

		if(seg == 3) cout<<7<<endl;
		else{
			if(seg % 2 == 1){
				seg -= 3;
				cout<<7;
			}
			for(int i = 1; i <= seg; i++){
				cout<<1;
			}
			cout<<endl;
		}
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long int       lint;
typedef vector<int>         vi;
typedef vector<lint>        vl;
typedef pair<int, int>      pii;
typedef vector<pii>         vii;
typedef set<int>            si;
typedef map<string, int>    msi;

#define pb(n)           push_back(n)
#define ALL(n)          (n.begin(), n.end())
#define db(a)           cout<<#a<<" = "<<a<<endl;
#define FIN             freopen("in.txt","r",stdin);
#define FOUT            freopen("out.txt","w",stdout);
#define M               10000000
#define MOD             10000007
#define INF             1e9+7
#define REP(i,a,b)      for(int i = int(a); i <= int(b); i++)
#define REPL(i,a,b)     for(lint i = lint(a); i <= lint(b); i++)
#define fastIO()        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main()
{
	int seg, kase;
	cin>>kase;
	while(kase--){

		cin>>seg;

		int n = seg % 4;

		if(n == 0){
			while(seg){
				cout<<1;
				seg -= 4;
			}
			printf("\n");
		}
		else if(n == 1){
			cout<<5;
			seg -= 5;
			while(seg){
				cout<<1;
				seg -= 4;
			}
			printf("\n");
		}
		else if(n == 2){
			cout<<1;
			seg -= 2;
			while(seg){
				cout<<1;
				seg -= 4;
			}
			printf("\n");
		}
		else if(n == 3){
			cout<<7;
			seg -= 3;
			while(seg){
				cout<<1;
				seg -= 4;
			}
			printf("\n");
		}
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long int       lint;
typedef vector<int>         vi;
typedef vector<lint>        vl;
typedef pair<int, int>      pii;
typedef vector<pii>         vii;
typedef set<int>            si;
typedef map<string, int>    msi;

#define pb(n)           push_back(n)
#define ALL(n)          (n.begin(), n.end())
#define db(a)           cout<<#a<<" = "<<a<<endl;
#define FIN             freopen("in.txt","r",stdin);
#define FOUT            freopen("out.txt","w",stdout);
#define M               10000000
#define MOD             10000007
#define INF             1e9+7
#define REP(i,a,b)      for(int i = int(a); i <= int(b); i++)
#define REPL(i,a,b)     for(lint i = lint(a); i <= lint(b); i++)
#define fastIO()        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main()
{
	fastIO();

	int seg, kase;
	cin>>kase;
	while(kase--){

		cin>>seg;

		if(seg == 2) cout<<1<<endl;
		else if(seg == 3) cout<<7<<endl;
		else{
			seg /= 4;
			REP(i, 1, seg){
				cout<<11;
			}
			cout<<endl;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long t,n,;
    cin>>t;
    long long d;
    long long i=0,k=0,j=0,f;
    while(i<t)
    {
        cin>>n;
        k=0,j=0;
        if(n&1){
            d=n/2;
            while(d>0 )
            {
                if(d==0)
                    cout<<"7";
                else
                cout<<"1";
                d--;
            }
        }
        else{
            f=n/2-1;
            while(f>0 ||f==0)
            {
                cout<<"1";
                f--;
            }
        }
        cout<<endl;
        i++;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,n,s=0;
    cin>>t;
    int d;
    int i=0,k=0,j=0,f;
    while(i<t)
    {
        cin>>n;
        k=0,j=0;
        if(n&1){
            d=n/2;
            while(d>0 )
            {
                if(k==0){
                s=s+7;
                }
                else
                {
                    s=s+pow(10,k);
                }
                k++;
                d--;
            }
        }
        else{
            s=0;
            f=n/2-1;
            while(f>0 ||f==0)
            {
                if(j==0)
                    s=s+1;
                else{
                    s=s+pow(10,j);
                }
                j++;
                f--;
            }
        }
        cout<<s<<endl;
        s=0;
        i++;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long t,n;
    cin>>t;
    long long d;
    long long i=0,k=0,j=0,f;
    while(i<t)
    {
        cin>>n;
        k=0,j=0;
        if(n&1){
            d=n/2-1;
            while(d>0 ||d==0 )
            {
                if(d==0)
                    cout<<"7";
                else
                cout<<"1";
                d--;
            }
        }
        else{
            f=n/2-1;
            while(f>0 ||f==0)
            {
                cout<<"1";
                f--;
            }
        }
        cout<<endl ;
        i++;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,n,s=0;
    cin>>t;
    int d;
    int i=0,k=0,j=0,f;
    while(i<t)
    {
        cin>>n;
        k=0,j=0;
        if(n&1){
            d=n/2;
            while(d>0 )
            {
                if(k==0){
                s=s+7;
                }
                else
                {
                    s=s+pow(10,k);
                }
                k++;
                d--;
            }
        }
        else{
            s=0;
            f=n/2-1;
            while(f>0 ||f==0)
            {
                if(j==0)
                    s=s+1;
                else{
                    s=s+pow(10,j);
                }
                j++;
                f--;
            }
        }
        cout<<s;
        s=0;
        i++;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long t,n;
    cin>>t;
    long long d;
    long long p=1,i=0,k=0,j=0,f;
    while(i<t)
    {
        cin>>n;
        k=0,j=0;
        if(n&1){
            d=n/2-1;
            while(d>0 ||d==0 )
            {
                if(p){
                    cout<<"7";
                    p=0;}
                else
                cout<<"1";
                d--;
            }
        }
        else{
            f=n/2-1;
            while(f>0 ||f==0)
            {
                cout<<"1";
                f--;
            }
        }
        cout<<endl;
        p=1;
        i++;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long t,n;
    cin>>t;
    long long d;
    long long i=0,k=0,j=0,f;
    while(i<t)
    {
        cin>>n;
        k=0,j=0;
        if(n&1){
            d=n/2;
            while(d>0 )
            {
                if(d==0)
                    cout<<"7";
                else
                cout<<"1";
                d--;
            }
        }
        else{
            f=n/2-1;
            while(f>0 ||f==0)
            {
                cout<<"1";
                f--;
            }
        }
        cout<<endl;
        i++;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long t,n,s=0;
    cin>>t;
    long d;
    long i=0,k=0,j=0,f;
    while(i<t)
    {
        cin>>n;
        k=0,j=0;
        if(n&1){
            d=n/2;
            while(d>0 )
            {
                if(k==0){
                s=s+7;
                }
                else
                {
                    s=s+pow(10,k);
                }
                k++;
                d--;
            }
        }
        else{
            s=0;
            f=n/2-1;
            while(f>0 ||f==0)
            {
                if(j==0)
                    s=s+1;
                else{
                    s=s+pow(10,j);
                }
                j++;
                f--;
            }
        }
        cout<<s<<endl;
        s=0;
        i++;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long t,n;
    cin>>t;
    long long d;
    long long i=0,k=0,j=0,f;
    while(i<t)
    {
        cin>>n;
        k=0,j=0;
        if(n&1){
            d=n/2-1;
            while(d>0 ||d==0 )
            {
                if(d==0)
                    cout<<"7";
                else
                cout<<"1";
                d--;
            }
        }
        else{
            f=n/2-1;
            while(f>0 ||f==0)
            {
                cout<<"1";
                f--;
            }
        }
        cout<<endl;
        i++;
    }
    return 0;
}


from math import *
from collections import *
from operator import itemgetter
import bisect
from heapq import *
i = lambda: input()
ii = lambda: int(input())
iia = lambda: list(map(int,input().split()))
isa = lambda: list(input().split())
I = lambda:list(map(int,input().split()))
chrIdx = lambda x: ord(x)-96
idxChr = lambda x: chr(96+x)

t = ii()

for _ in range(t):
	n = ii()
	a = iia()
	b = [i+1 for i in range(n)]
	#print(b)
	c = []
	for i in range(n):
		c.append(a[i]-(i+1))
	cnt = 0
	nz = 0
	nnz = 0
	ans = 0
	j = 0
	#print(c)
	while j<n:
		i = j
		nz = 0
		nnz = 0
		while i<n:
			cnt+=c[i]
			if c[i]==0:
				nz+=1
			else:
				nnz+=1
			if cnt==0:
				break
			i+=1
		if nnz>0:
			ans+=(nz+1)
		j = i+1
	print(ans)


from math import *
from collections import *
from operator import itemgetter
import bisect
from heapq import *
i = lambda: input()
ii = lambda: int(input())
iia = lambda: list(map(int,input().split()))
isa = lambda: list(input().split())
I = lambda:list(map(int,input().split()))
chrIdx = lambda x: ord(x)-96
idxChr = lambda x: chr(96+x)

t = ii()

for _ in range(t):
	n = ii()
	a = iia()
	b = [i+1 for i in range(n)]
	#print(b)
	c = []
	#arr = []
	for i in range(n):
		c.append(a[i]-(i+1))
		#arr.append(a[i])
	i = 0
	cnt = 0
	while i<n:
		if c[i]==0:
			j = i+1
			while j<n:
				if c[j]==0:
					j+=1
				else:
					break
			i = j
		else:
			cnt+=1
			j = i+1
			while j<n:
				if c[j]!=0:
					j+=1
				else:
					break
			i = j

	cnt = c.count(0)
	if cnt==0 or cnt<=1:
		print(1)
	elif cnt==n:
		print(0)
	else:
		print(2)


from math import *
from collections import *
from operator import itemgetter
import bisect
from heapq import *
i = lambda: input()
ii = lambda: int(input())
iia = lambda: list(map(int,input().split()))
isa = lambda: list(input().split())
I = lambda:list(map(int,input().split()))
chrIdx = lambda x: ord(x)-96
idxChr = lambda x: chr(96+x)

t = ii()

for _ in range(t):
	n = ii()
	a = iia()
	b = [i+1 for i in range(n)]
	#print(b)
	c = []
	for i in range(n):
		c.append(a[i]-(i+1))
	cnt = 0
	nz = 0
	nnz = 0
	ans = 0
	j = 0
	#print(c)
	while j<n:
		i = j
		nz = 0
		nnz = 0
		cz = 0
		while i<n:
			cnt+=c[i]
			if c[i]==0:
				nz+=1
				k = i+1
				while k<n:
					if c[k]==0:
						k+=1
					else:
						break
				i = k-1
			else:
				nnz+=1
			if cnt==0:
				break
			i+=1
		if nnz>0:
			ans+=(nz+1)
		j = i+1
	print(min(ans,2))


from math import *
from collections import *
from operator import itemgetter
import bisect
from heapq import *
i = lambda: input()
ii = lambda: int(input())
iia = lambda: list(map(int,input().split()))
isa = lambda: list(input().split())
I = lambda:list(map(int,input().split()))
chrIdx = lambda x: ord(x)-96
idxChr = lambda x: chr(96+x)

t = ii()

for _ in range(t):
	n = ii()
	a = iia()
	b = [i+1 for i in range(n)]
	#print(b)
	c = []
	for i in range(n):
		c.append(a[i]-(i+1))
	cnt = c.count(0)
	if cnt==0:
		print(1)
	elif cnt==n:
		print(0)
	else:
		print(2)


from math import *
from collections import *
from operator import itemgetter
import bisect
from heapq import *
i = lambda: input()
ii = lambda: int(input())
iia = lambda: list(map(int,input().split()))
isa = lambda: list(input().split())
I = lambda:list(map(int,input().split()))
chrIdx = lambda x: ord(x)-96
idxChr = lambda x: chr(96+x)

t = ii()

for _ in range(t):
	n = ii()
	a = iia()
	b = [i+1 for i in range(n)]
	#print(b)
	c = []
	#arr = []
	for i in range(n):
		c.append(a[i]-(i+1))
		#arr.append(a[i])
	i = 0
	cnt1 = 0
	#print(*c)
	while i<n:
		if c[i]==0:
			j = i+1
			#cnt+=1
			while j<n:
				if c[j]==0:
					j+=1
				else:
					break
			i = j
		else:
			cnt1+=1
			j = i+1
			while j<n:
				if c[j]!=0:
					j+=1
				else:
					break
			i = j

	cnt = c.count(0)
	if cnt==n:
		print(0)
	elif cnt==0 or cnt1<=1:
		print(1)
	else:
		print(2)


from math import *
from collections import *
from operator import itemgetter
import bisect
from heapq import *
i = lambda: input()
ii = lambda: int(input())
iia = lambda: list(map(int,input().split()))
isa = lambda: list(input().split())
I = lambda:list(map(int,input().split()))
chrIdx = lambda x: ord(x)-96
idxChr = lambda x: chr(96+x)

t = ii()

for _ in range(t):
	n = ii()
	a = iia()
	b = [i+1 for i in range(n)]
	#print(b)
	c = []
	for i in range(n):
		c.append(a[i]-(i+1))
	cnt = 0
	nz = 0
	nnz = 0
	ans = 0
	j = 0
	#print(c)
	while j<n:
		i = j
		nz = 0
		nnz = 0
		cz = 0
		while i<n:
			cnt+=c[i]
			if c[i]==0:
				nz+=1
				k = i+1
				while k<n:
					if c[k]==0:
						k+=1
					else:
						break
				i = k-1
			else:
				nnz+=1
			if cnt==0:
				break
			i+=1
		if nnz>0:
			ans+=(nz+1)
		j = i+1
	print(ans)


# cook your dish here
for _ in range(int(input())):
    s=input()
    t=input()
    dict={}
    check={}
    for i in 'abcdefghijklmnopqrstuvwxyz':
        dict[i]=[]
        check[i]=0
    j=0
    for i in s:
        dict[i].append(j)
        check[i]=1
        j+=1
    i=0
    l=len(t)
    ans=True
    count=0
    while i<l:
        ini=-1
        if check[t[i]]==1:
            count+=1
            while check[t[i]]==1:
                k=t[i]
                c=False
                for p in dict[k]:
                    if p>ini:
                        ini=p
                        c=True
                        break
                if c:
                    i+=1
                    if i==l:
                        break
                else:
                    break

        else:
            ans=False
            break
    if ans:
        print(count)
    else:
        print(-1)


for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    a=[0]+a
    check1=0
    l,r=0,0
    ind=0
    check2=0
    for i in range(1,n+1):
        if a[i]!=i:
            check1=1
        else:
            if ind%2==0:
                l=i
            else:
                r=i
                if r-l>1:
                    check2=1
            ind=(ind+1)%2
    if check1==0:
        print(0)
    elif check2==0:
        print(1)
    else:
        print(2)


for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    a=[0]+a
    k=[]
    check1=0
    check2=0
    l=0
    for i in range(1,n+1):
        if a[i]!=i:
            check1=1
        else:
            l+=1
            k.append(i)
    if check1==0:
        print(0)
    else:
        if l>0:
            num=0
            if k[0]==1 or k[l-1]==n:
                for i in range(1,l):
                    if k[i]-k[i-1]>1:
                        num+=1
                        if num>1:
                            check2=1
            else:
                check2=1
        if check2==1:
            print(2)
        else:
            print(1)


# cook your dish here
for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    a=[0]+a
    k=[]
    check1=0
    check2=0
    l=0
    for i in range(1,n+1):
        if a[i]!=i:
            check1=1
        else:
            l+=1
            k.append(i)
    if check1==0:
        print(0)
    else:
        if k[0]==1 and k[l-1]==n:
            for i in range(1,l):
                if k[i]-k[i-1]>1:
                    j=i
                    break
            for i in range(j+1,l):
                if k[i]-k[i-1]>1:
                    check2=1
                    break
        elif k[0]==1 or k[l-1]==n:
            for i in range(1,l):
                if k[i]-k[i-1]>1:
                    check2=1
                    break
        else:
            check2=1
        if check2==0:
            print(1)
        else:
            print(2)


for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    a=[0]+a
    k=[]
    check1=0
    check2=0
    l=0
    for i in range(1,n+1):
        if a[i]!=i:
            check1=1
        else:
            l+=1
            k.append(i)
    if check1==0:
        print(0)
    else:
        if l>0:
            if k[0]==1 or k[l-1]==n:
                for i in range(1,l):
                    if k[i]-k[i-1]>1:
                        check2=1
            else:
                check2=1
        else:
            check2=1
        if check2==1:
            print(2)
        else:
            print(1)


# cook your dish here
for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    a=[0]+a
    k=[]
    check1=0
    check2=0
    l=0
    for i in range(1,n+1):
        if a[i]!=i:
            check1=1
        else:
            l+=1
            k.append(i)
    if check1==0:
        print(0)
    else:
        if l>0:
            if k[0]==1 and k[l-1]==n:
                for i in range(1,l):
                    if k[i]-k[i-1]>1:
                        j=i
                        break
                for i in range(j+1,l):
                    if k[i]-k[i-1]>1:
                        check2=1
                        break
            elif k[0]==1 or k[l-1]==n:
                for i in range(1,l):
                    if k[i]-k[i-1]>1:
                        check2=1
                        break
            else:
                check2=1
        if check2==0:
            print(1)
        else:
            print(2)


for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    a=[0]+a
    k=[]
    check1=0
    check2=0
    l=0
    for i in range(1,n+1):
        if a[i]!=i:
            check1=1
        else:
            l+=1
            k.append(i)
    if check1==0:
        print(0)
    else:
        if l>0:
            if k[0]==1 or k[l-1]==n:
                for i in range(1,l):
                    if k[i]-k[i-1]>1:
                        check2=1
            else:
                check2=1
        if check2==1:
            print(2)
        else:
            print(1)


for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    a=[0]+a
    check1=0
    l,r=0,0
    ind=0
    check2=0
    for i in range(1,n+1):
        if a[i]!=i:
            check1=1
    if check1==0:
        print(0)
    else:
        j=0
        for i in range(1,n+1):
            if a[i]!=i:
                j=i
                break
        if j==1:
            for i in range(n,0,-1):
                if a[i]!=i:
                    j=i
                    break
            if j==n:
                check2=1
            else:
                for i in range(j-1,0,-1):
                    if a[i]==i:
                        check2=1
                        break
        else:
            for i in range(j+1,n+1):
                if a[i]==i:
                    check2=1
                    break
        if check2==0:
            print(1)
        else:
            print(2)


t = int(input())
for i in range(t):
    n = int(input())
    a = [int(i) for i in input().split()]
    sorteda = [i for i in a]
    sorteda.sort()
    acheck = [1 if a[i]==sorteda[i] else 0 for i in range(n)]
    a1check = [i for i in acheck]
    a1check.reverse()
    if a == sorteda:
        print(0)
    elif 1 not in acheck:
        print(1)
    else:
        if n ==2:
            print(1)
        else:

            for i in range(n):
                if acheck[i] == 0:
                    s = i
                    break
            for i in range(n):
                if a1check[i]==0:
                    end = n-i
                    break
            a2 = acheck[s:end]

            if 1 in a2:
                print(2)
            else:
                print(1)


t = int(input())
for i in range(t):
    n = int(input())
    a = [int(i) for i in input().split()]
    sorteda = [i for i in a]
    sorteda.sort()
    if a == sorteda:
        print(0)
    else:
        if n ==2:
            print(1)
        else:
            print(2)


t = int(input())
for i in range(t):
    n = int(input())
    a = [int(i) for i in input().split()]
    sorteda = [i for i in a]
    sorteda.sort()
    if a == sorteda:
        print(0)
    else:
        if n ==2:
            print(1)
        else:
            acheck = [1 if a[i]==sorteda[i] else 0 for i in range(n)]
            a1check = [i for i in acheck]
            a1check.reverse()
            for i in range(n):
                if acheck[i] == 0:
                    s = i
                    break
            for i in range(n):
                if a1check[i]==0:
                    end = n-i
                    break
            a2 = a1check[s:end]
            if 1 in a2:
                print(2)
            else:
                print(1)


t = int(input())
for i in range(t):
    n = int(input())
    a = [int(i) for i in input().split()]
    sorteda = [i for i in a]
    sorteda.sort()
    acheck = [1 if a[i]==sorteda[i] else 0 for i in range(n)]
    a1check = [i for i in acheck]
    a1check.reverse()
    if a == sorteda:
        print(0)
    elif 1 not in acheck:
        print(1)
    else:
        if n ==2:
            print(1)
        else:

            for i in range(n):
                if acheck[i] == 0:
                    s = i
                    break
            for i in range(n):
                if a1check[i]==0:
                    end = n-i
                    break
            a2 = a1check[s:end]
            if 1 in a2:
                print(2)
            else:
                print(1)


t = int(input())
for i in range(t):
    n = int(input())
    a = [int(i) for i in input().split()]
    sorteda = [i for i in a]
    sorteda.sort()
    if a == sorteda:
        print(0)
    else:
        if n ==2:
            print(1)
        else:
            acheck = [1 if a[i]==sorteda[i] else 0 for i in range(n)]
            a1check = [i for i in acheck]
            a1check.reverse()
            for i in range(n):
                if acheck[i] == 0:
                    s = i
                    break
            for i in range(n):
                if a1check[i]==0:
                    end = n-i
                    break
            a2 = a1check[s:end]
            if 1 in a2:
                print(2)
            else:
                print(0)


import sys
import bisect as bi
import math
from collections import defaultdict as dd
import heapq
input=sys.stdin.readline
#sys.setrecursionlimit(10**7)
mo=10**9+7
def cin():
    return map(int,sin().split())
def ain():
    return list(map(int,sin().split()))
def sin():
    return input()
def inin():
    return int(input())
def pref(a,n,f):
    pre=[0]*n
    if(f==0):         ##from beginning
        pre[0]=a[0]
        for i in range(1,n):
            pre[i]=a[i]+pre[i-1]
    else:              ##from end
        pre[-1]=a[-1]
        for i in range(n-2,-1,-1):
            pre[i]=pre[i+1]+a[i]
    return pre
maxint=10**24
def kadane(a,size):
    max_so_far = -maxint - 1
    max_ending_here = 0

    for i in range(0, size):
        max_ending_here = max_ending_here + a[i]
        if (max_so_far < max_ending_here):
            max_so_far = max_ending_here

        if max_ending_here < 0:
            max_ending_here = 0
    return max_so_far
##def maxPrimeFactors (n):
##    maxPrime = -1
##    while n % 2 == 0:
##        maxPrime = 2
##        n >>= 1     # equivalent to n /= 2
##    for i in range(3, int(math.sqrt(n)) + 1, 2):
##        while n % i == 0:
##            maxPrime = i
##            n = n / i
##    if n > 2:
##        maxPrime = n
##    return int(maxPrime)
##dp=[0]*64
##dp[0]=1
##for i in range(1,64):
##    dp[i]=dp[i-1]*2
for _ in range(inin()):
    n=inin()
    l=ain()
    a=sorted(l)
    c=0
    grp=f=0
    cg=''
    for i in range(n):
        if(a[i]==l[i]):
            cg+='1'
            c+=1
            if(f==0):
                grp+=1
            f=1
        else:
            f=0
            cg+='0'
##    print(grp)
    if(c==n):
        ans=0
    elif(c==0):
        ans=1
    else:
        if(grp==1):
            if(cg.count('10')==1 and cg.count('01')==0):
                ans=1
            elif(cg.count('01')==1 and cg.count('10')==0):
                ans=1
            else:
                ans=2
        else:
            ans=2
    print(ans)

##    maxa=[0]*n
##    maxa[0]=l[0]
##    for i in range(1,n):
##        maxa[i]=max(l[i],maxa[i-1])
##    d=dd(int)
##    co=dd(int)
##    for i in range(n):
##        d[l[i]]=i+1
##        co[l[i]]+=1
##    mi=min(l)
##    cmi=l.count(mi)
##    ma=max(l)
##    so=sorted(l)
##    winpo=ma-so.index(ma)
##    for i in range(winpo,ma):
##        p=b.bisect_right(


import sys
import bisect as bi
import math
from collections import defaultdict as dd
import heapq
input=sys.stdin.readline
#sys.setrecursionlimit(10**7)
mo=10**9+7
def cin():
    return map(int,sin().split())
def ain():
    return list(map(int,sin().split()))
def sin():
    return input()
def inin():
    return int(input())
def pref(a,n,f):
    pre=[0]*n
    if(f==0):         ##from beginning
        pre[0]=a[0]
        for i in range(1,n):
            pre[i]=a[i]+pre[i-1]
    else:              ##from end
        pre[-1]=a[-1]
        for i in range(n-2,-1,-1):
            pre[i]=pre[i+1]+a[i]
    return pre
maxint=10**24
def kadane(a,size):
    max_so_far = -maxint - 1
    max_ending_here = 0

    for i in range(0, size):
        max_ending_here = max_ending_here + a[i]
        if (max_so_far < max_ending_here):
            max_so_far = max_ending_here

        if max_ending_here < 0:
            max_ending_here = 0
    return max_so_far
##def maxPrimeFactors (n):
##    maxPrime = -1
##    while n % 2 == 0:
##        maxPrime = 2
##        n >>= 1     # equivalent to n /= 2
##    for i in range(3, int(math.sqrt(n)) + 1, 2):
##        while n % i == 0:
##            maxPrime = i
##            n = n / i
##    if n > 2:
##        maxPrime = n
##    return int(maxPrime)
##dp=[0]*64
##dp[0]=1
##for i in range(1,64):
##    dp[i]=dp[i-1]*2
for _ in range(inin()):
    n=inin()
    l=ain()
    a=sorted(l)
    c=0
    grp=f=0
    cg=[0]*n
    for i in range(n):
        if(a[i]==l[i]):
            cg[i]=1
            c+=1
            if(f==0):
                grp+=1
            f=1
        else:
            f=0
    if(c==n):
        ans=0
    elif(c==0):
        ans=1
    else:
        if(grp==1):
            fi=cg.index(1)
            li=n-cg[::-1].index(1)-1
            if(li-fi+1==c):
                ans=1
            else:
                ans=2
        else:
            ans=2
    print(ans)

##    maxa=[0]*n
##    maxa[0]=l[0]
##    for i in range(1,n):
##        maxa[i]=max(l[i],maxa[i-1])
##    d=dd(int)
##    co=dd(int)
##    for i in range(n):
##        d[l[i]]=i+1
##        co[l[i]]+=1
##    mi=min(l)
##    cmi=l.count(mi)
##    ma=max(l)
##    so=sorted(l)
##    winpo=ma-so.index(ma)
##    for i in range(winpo,ma):
##        p=b.bisect_right(