#include <bits/stdc++.h>
#define f(i, a, n) for (i = a; i < n; i++)
#define fd(i, n, a) for (i = n; i >= a; i--)
#define rep(i,n) f(i,0,n)
#define repd(i,n) f(i, n, 0)
#define pb push_back
#define MOD 1000000007

#define s(x) scanf("%lld", &x); //s(x) is for long long int.
#define si(x) scanf("%d", &x);
#define sf(x) scanf("%f", &x);
#define sd(x) scanf("%lf", &x);
#define ss(x) scanf("%s", x);

#define psp printf(" "); //Print space - psp;
#define pnl printf("\n"); //Print new line - pnl;

#define p(x) printf("%lld", x);  //p(x) is for long long int.
#define pn(x) printf("%lld\n", x);  //..n(x) is for printing with New Line.
#define ps(x) printf("%lld ", x);  //..s(x) is for printing with Space.

#define pi(x) printf("%d", x);
#define pin(x) printf("%d\n", x);
#define pis(x) printf("%d ", x);
#define pf(x) printf("%f", x);
#define pfn(x) printf("%f\n", x);
#define pfs(x) printf("%f ", x);
#define pd(x) printf("%lf", x);
#define pdn(x) printf("%lf\n", x);
#define pds(x) printf("%lf ", x);

typedef long long int LL;
using namespace std;
int n;
string a[305];
int b[305];
int sum[305][400];
int checker = 0;

string solve(int num) {
    string tmp = "";

    while (num > 9) {
        tmp += "9";
        num -= 9;

    }
    if (num > 0 and num < 10) {
        tmp += (num + '0');
    }
    else if (num >= 10) {
        return "lol";
    }
    if (tmp.size() != 0) {
    reverse(tmp.begin(),tmp.end());
    }
    if (checker == 0) {
        if (tmp.size() != 0) {

    sum[0][1] = (tmp[0] - '0');
    int i;
    f (i, 1, (tmp.size())) {
        sum[0][i+1] = (tmp[i] - '0');
        sum[0][i+1]  += sum[0][i];
    }
    }
    checker = 1;
    }

    return tmp;
}
string supersolve(int len, int sum)
{
    string s = "";
    if (len == 1) {
        s += (sum + '0');
        return s;
    }
    if (sum < 9*len) {
        for (int i = 1; i <= 9; i++) {
            if (9*(len-1) >= (sum-i)) {
                s += (i + '0');
                sum -= i;
                len--;

                break;
            }
        }
        int j = 0;
        while (j < len) {
            if (j == len-1) {
                s += (sum + '0');

                break;
            }
            for (int i = 0; i <= 9; i++) {
                if (9*(len-1) >= (sum-i)) {
                    s += (i + '0');
                    len--;
                    sum -= i;

                    break;
                }
            }
        }
        return s;
    }
    else {
        return solve(sum);
    }
}
string compute (string ps, int num, int idx) {
    //cout << "*" << idx << endl;
    int len = ps.size();
    string s = "";
     //cout << "*" << s.size() << endl;
    //int flag = 0;
    int t;
    int i;
    //cout << len << endl;
    for (i = len-1; i >=0; i--) {

        int tmp = ps[i] - '0';

        //cout << i << endl;

        while (tmp < 9) {
            if ((num - (tmp+1) - sum[idx-1][i]) < 0){
                //flag = 1;
                //cout << "*";
                break;
            }
            //if (idx == 3 and i == 2)
            //cout << "#" << tmp << endl;
            if ((num - (tmp+1) - sum[idx-1][i]) > 9*(len-1-i)) {
                tmp++;
                //cout << "#";
                continue;
            }
            //cout << "#" << (num - (1+tmp) - sum[idx-1][i]) << endl;
            //cout << "#" << tmp << endl;
            s = solve ((num - (tmp+1) - sum[idx-1][i]));
        //  if (idx == 1 and i == 0)
            //  cout << "*" << tmp << endl;

                //cout << "*" << idx << endl;
                if (s.size() + i + 1 > len) {
                    tmp++;

                }
                else if (s.size() + i + 1<= len) {

                    //cout << "*";
                    //cout << "*" << idx << endl;
                     t = (len - (s.size()+i+1));
                    // cout << t << "*" <<  endl;
                     if (s.size() != 0)
                         reverse(s.begin(), s.end());
                    while (t--){
                        s += "0";
                    }

                tmp++;
                //cout << "*" << tmp << endl;

                s += (tmp + '0');
                t = i-1;
                while (t >= 0) {
                    s += char(ps[t]);
                    t--;
                }
                reverse(s.begin(),s.end());
                return s;
                }

        }
    }

    //if (flag == 1) {
        //cout << "#" << len <<" " << num<< endl;;
        s = supersolve(len+1, num);
        return s;
    //}

}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("/home/spharish/input.txt", "r", stdin);
    #endif
    cin >> n;

    int i;
    rep (i,n)  {
        cin >> b[i];
    }

    a[0] = solve(b[0]);
    cout << a[0] << endl;
    int j;
    f(i, 1, n) {
        a[i] = compute(a[i-1], b[i], i);
        cout << a[i] << endl;
        sum[i][1] = a[i][0] - '0';
        for (j = 2; j <= n; j++) {
            sum[i][j] = sum[i][j-1];
            sum[i][j] += a[i][j-1] - '0';

        }
        //cout << a[i];
    }

    /*rep (i,n) {
        cout << a[i] << endl;
    }*/

    return 0;
}


#include <bits/stdc++.h>

#define f(i, a, n) for (i = a; i < n; i++)
#define fd(i, n, a) for (i = n; i >= a; i--)
#define rep(i,n) f(i,0,n)
#define repd(i,n) f(i, n, 0)
#define pb push_back
#define MOD 1000000007

#define s(x) scanf("%lld", &x); //s(x) is for long long LL.
#define si(x) scanf("%d", &x);
#define sf(x) scanf("%f", &x);
#define sd(x) scanf("%lf", &x);
#define ss(x) scanf("%s", x);

#define psp prLLf(" "); //PrLL space - psp;
#define pnl prLLf("\n"); //PrLL new line - pnl;

#define p(x) prLLf("%lld", x);  //p(x) is for long long LL.
#define pn(x) prLLf("%lld\n", x);  //..n(x) is for prLLing with New Line.
#define ps(x) prLLf("%lld ", x);  //..s(x) is for prLLing with Space.

#define pi(x) prLLf("%d", x);
#define pin(x) prLLf("%d\n", x);
#define pis(x) prLLf("%d ", x);
#define pf(x) prLLf("%f", x);
#define pfn(x) prLLf("%f\n", x);
#define pfs(x) prLLf("%f ", x);
#define pd(x) prLLf("%lf", x);
#define pdn(x) prLLf("%lf\n", x);
#define pds(x) prLLf("%lf ", x);

typedef long long int LL;
using namespace std;
LL n;
string a[305];
LL b[305];
LL sum[305][400];
int checker = 0;

string solve(LL num) {
    string tmp = "";

    while (num > 9) {
        tmp += "9";
        num -= 9;

    }
    if (num > 0 and num < 10) {
        tmp += char(num + '0');
    }
    else if (num >= 10) {
        return "lol";
    }
    if (tmp.size() != 0) {
    reverse(tmp.begin(),tmp.end());
    }
    if (checker == 0 and tmp.size() != 0) {
    sum[0][1] = (tmp[0] - '0');
    LL i;
    f (i, 1, (tmp.size())) {
        sum[0][i+1] = (tmp[i] - '0');
        sum[0][i+1]  += sum[0][i];
    }
    checker = 1;
    }

    return tmp;
}
string supersolve(LL len, LL sum)
{
    string s = "";
    if (len == 1) {
        s += char(sum + '0');
        return s;
    }
    if (sum < 9*len) {
        for (LL i = 1; i <= 9; i++) {
            if (9*(len-1) >= (sum-i)) {
                s += (i + '0');
                sum -= i;
                len--;

                break;
            }
        }
        LL j = 0;
        while (j < len) {
            if (j == len-1) {
                s += (sum + '0');

                break;
            }
            for (LL i = 0; i <= 9; i++) {
                if (9*(len-1) >= (sum-i)) {
                    s += (i + '0');
                    len--;
                    sum -= i;

                    break;
                }
            }
        }
        return s;
    }
    else {
        return solve(sum);
    }
}
string compute (string ps, LL num, LL idx) {
    //cout << "*" << idx << endl;
    LL len = ps.size();
    string s = "";
     //cout << "*" << s.size() << endl;
    //int flag = 0;
    LL t;
    LL i;
    //cout << len << endl;
    for (i = len-1; i >=0; i--) {

        LL tmp = ps[i] - '0';

        //cout << i << endl;

        while (tmp < 9) {
            if ((num - (tmp+1) - sum[idx-1][i]) < 0){
                //flag = 1;
                //cout << "*";
                break;
            }
            //if (idx == 3 and i == 2)
            //cout << "#" << tmp << endl;
            if ((num - (tmp+1) - sum[idx-1][i]) > 9*(len-1-i)) {
                tmp++;
                //cout << "#";
                continue;
            }
            //cout << "#" << (num - (1+tmp) - sum[idx-1][i]) << endl;
            //cout << "#" << tmp << endl;
            s = solve ((num - (tmp+1) - sum[idx-1][i]));
        //  if (idx == 1 and i == 0)
            //  cout << "*" << tmp << endl;

                //cout << "*" << idx << endl;
                if (s.size() + i + 1 > len) {
                    tmp++;

                }
                else if (s.size() + i + 1<= len) {

                    //cout << "*";
                    //cout << "*" << idx << endl;
                     t = (len - (s.size()+i+1));
                    // cout << t << "*" <<  endl;
                     if (s.size() != 0)
                         reverse(s.begin(), s.end());
                    while (t--){
                        s += ('0');
                    }

                tmp++;
                //cout << "*" << tmp << endl;

                s += (tmp + '0');
                t = i-1;
                while (t >= 0) {
                    s += ps[t];
                    t--;
                }
                reverse(s.begin(),s.end());
                return s;
                }

        }
    }

    //if (flag == 1) {
        //cout << "#" << len <<" " << num<< endl;;
        s = supersolve(len+1, num);
        return s;
    //}

}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("/home/spharish/input.txt", "r", stdin);
    #endif
    cin >> n;

    LL i;
    rep (i,n)  {
        cin >> b[i];
    }

    a[0] = solve(b[0]);
    cout << a[0] << endl;
    LL j;
    f(i, 1, n) {
        a[i] = compute(a[i-1], b[i], i);
        cout << a[i] << endl;
        sum[i][1] = a[i][0] - '0';
        for (j = 2; j <= n; j++) {
            sum[i][j] = sum[i][j-1];
            sum[i][j] += a[i][j-1] - '0';

        }
        //cout << a[i];
    }

    /*rep (i,n) {
        cout << a[i] << endl;
    }*/

    return 0;
}


#include <bits/stdc++.h>

#define f(i, a, n) for (i = a; i < n; i++)
#define fd(i, n, a) for (i = n; i >= a; i--)
#define rep(i,n) f(i,0,n)
#define repd(i,n) f(i, n, 0)
#define pb push_back
#define MOD 1000000007

#define s(x) scanf("%lld", &x); //s(x) is for long long LL.
#define si(x) scanf("%d", &x);
#define sf(x) scanf("%f", &x);
#define sd(x) scanf("%lf", &x);
#define ss(x) scanf("%s", x);

#define psp prLLf(" "); //PrLL space - psp;
#define pnl prLLf("\n"); //PrLL new line - pnl;

#define p(x) prLLf("%lld", x);  //p(x) is for long long LL.
#define pn(x) prLLf("%lld\n", x);  //..n(x) is for prLLing with New Line.
#define ps(x) prLLf("%lld ", x);  //..s(x) is for prLLing with Space.

#define pi(x) prLLf("%d", x);
#define pin(x) prLLf("%d\n", x);
#define pis(x) prLLf("%d ", x);
#define pf(x) prLLf("%f", x);
#define pfn(x) prLLf("%f\n", x);
#define pfs(x) prLLf("%f ", x);
#define pd(x) prLLf("%lf", x);
#define pdn(x) prLLf("%lf\n", x);
#define pds(x) prLLf("%lf ", x);

typedef long long int LL;
using namespace std;
LL n;
string a[305];
LL b[305];
LL sum[305][400];
int checker = 0;

string solve(LL num) {
    string tmp = "";

    while (num > 9) {
        tmp += "9";
        num -= 9;

    }
    if (num > 0 and num < 10) {
        tmp += char(num + '0');
    }
    else if (num >= 10) {
        return "lol";
    }
    if (tmp.size() != 0) {
    reverse(tmp.begin(),tmp.end());
    }
    if (checker == 0 and tmp.size() != 0) {
    sum[0][1] = tmp[0] - '0';
    LL i;
    f (i, 1, (tmp.size())) {
        sum[0][i+1] = tmp[i] - '0' + sum[0][i];
    }
    checker = 1;
    }

    return tmp;
}
string supersolve(LL len, LL sum)
{
    string s = "";
    if (len == 1) {
        s += char(sum + '0');
        return s;
    }
    if (sum < 9*len) {
        for (LL i = 1; i <= 9; i++) {
            if (9*(len-1) >= (sum-i)) {
                s += char(i + '0');
                sum -= i;
                len--;

                break;
            }
        }
        LL j = 0;
        while (j < len) {
            if (j == len-1) {
                s += char(sum + '0');
                j++;

                break;
            }
            for (LL i = 0; i <= 9; i++) {
                if (9*(len-1) >= (sum-i)) {
                    s += char(i + '0');

                    sum -= i;
                    len--;

                    break;
                }
            }
        }
        return s;
    }
    else {
        return solve(sum);
    }
}
string compute (string ps, LL num, LL idx) {
    //cout << "*" << idx << endl;
    LL len = ps.size();
    string s = "";
     //cout << "*" << s.size() << endl;
    //int flag = 0;
    LL t;
    LL i;
    //cout << len << endl;
    //if (idx == 46) {
    //  cout << "*" << ps << endl;
    //}
    for (i = len-1; i >=0; i--) {

        LL tmp = ps[i] - '0';

        //cout << tmp << endl;
        //cout << i << endl;

        while (tmp < 9) {
            if ((num - (tmp+1) - sum[idx-1][i]) < 0){
                //flag = 1;
                //cout << "*";
                break;
            }
            //if (idx == 3 and i == 2)
            //cout << "#" << tmp << endl;
            if ((num - (tmp+1) - sum[idx-1][i]) > 9*(len-1-i)) {
                tmp++;
                //cout << "#";
                continue;
            }
            //cout << "#" << (num - (1+tmp) - sum[idx-1][i]) << endl;
            //cout << "#" << tmp << endl;
            s = solve ((num - (tmp+1) - sum[idx-1][i]));
        //  if (idx == 1 and i == 0)
            //  cout << "*" << tmp << endl;

                //cout << "*" << idx << endl;
                if (s.size() + i + 1 > len) {
                    tmp++;

                }
                else if (s.size() + i + 1<= len) {

                    //cout << "*";
                    //cout << "*" << idx << endl;
                     t = (len - (s.size()+i+1));
                    // cout << t << "*" <<  endl;
                    while (t--){
                        s += '0';
                    }
                //if (s.size() != 0)
                    //reverse(s.begin(), s.end());
                tmp++;
                //cout << "*" << tmp << endl;

                s += tmp + '0';
                t = i-1;
                while (t >= 0) {
                    s += ps[t];
                    t--;
                }
                if (s.size() != 0)
                reverse(s.begin(),s.end());
                return s;
                }

        }
    }

    //if (flag == 1) {
        //if (idx == 46)
        //cout << "#" << len <<" " << num<< endl;;
        s = supersolve(len+1, num);
        return s;
    //}

}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("/home/spharish/input.txt", "r", stdin);
    #endif
    cin >> n;

    LL i;
    rep (i,n)  {
        cin >> b[i];
    }

    a[0] = solve(b[0]);
    cout << a[0] << endl;
    LL j;
    f(i, 1, n) {
        a[i] = compute(a[i-1], b[i], i);
        cout << a[i] << endl;
        sum[i][1] = a[i][0] - '0';
        for (j = 2; j <= n; j++) {
            sum[i][j] = sum[i][j-1] + a[i][j-1] - '0';

        }
        //cout << a[i];
    }

    //rep (i,n) {
    //  cout << a[i] << endl;
    //}

    return 0;
}


#include <bits/stdc++.h>

#define f(i, a, n) for (i = a; i < n; i++)
#define fd(i, n, a) for (i = n; i >= a; i--)
#define rep(i,n) f(i,0,n)
#define repd(i,n) f(i, n, 0)
#define pb push_back
#define MOD 1000000007

#define s(x) scanf("%lld", &x); //s(x) is for long long LL.
#define si(x) scanf("%d", &x);
#define sf(x) scanf("%f", &x);
#define sd(x) scanf("%lf", &x);
#define ss(x) scanf("%s", x);

#define psp prLLf(" "); //PrLL space - psp;
#define pnl prLLf("\n"); //PrLL new line - pnl;

#define p(x) prLLf("%lld", x);  //p(x) is for long long LL.
#define pn(x) prLLf("%lld\n", x);  //..n(x) is for prLLing with New Line.
#define ps(x) prLLf("%lld ", x);  //..s(x) is for prLLing with Space.

#define pi(x) prLLf("%d", x);
#define pin(x) prLLf("%d\n", x);
#define pis(x) prLLf("%d ", x);
#define pf(x) prLLf("%f", x);
#define pfn(x) prLLf("%f\n", x);
#define pfs(x) prLLf("%f ", x);
#define pd(x) prLLf("%lf", x);
#define pdn(x) prLLf("%lf\n", x);
#define pds(x) prLLf("%lf ", x);

typedef long long int LL;
using namespace std;
LL n;
string a[305];
LL b[305];
LL sum[305][400];
int checker = 0;

string solve(LL num) {
    string tmp = "";

    while (num > 9) {
        tmp += "9";
        num -= 9;

    }
    if (num > 0 and num < 10) {
        tmp += char(num + '0');
    }
    else if (num >= 10) {
        return "lol";
    }
    if (tmp.size() != 0) {
    reverse(tmp.begin(),tmp.end());
    }
    if (checker == 0 and tmp.size() != 0) {
    sum[0][1] = tmp[0] - '0';
    LL i;
    f (i, 1, (tmp.size())) {
        sum[0][i+1] = tmp[i] - '0' + sum[0][i];
    }
    checker = 1;
    }

    return tmp;
}
string supersolve(LL len, LL sum)
{
    string s = "";
    if (len == 1) {
        s += sum + '0';
        return s;
    }
    if (sum < 9*len) {
        for (LL i = 1; i <= 9; i++) {
            if (9*(len-1) >= (sum-i)) {
                s += i + '0';
                sum -= i;
                len--;

                break;
            }
        }
        LL j = 0;
        while (j < len) {
            if (j == len-1) {
                s += sum + '0';

                break;
            }
            for (LL i = 0; i <= 9; i++) {
                if (9*(len-1) >= (sum-i)) {
                    s += i + '0';
                    len--;
                    sum -= i;

                    break;
                }
            }
        }
        return s;
    }
    else {
        return solve(sum);
    }
}
string compute (string ps, LL num, LL idx) {
    //cout << "*" << idx << endl;
    LL len = ps.size();
    string s = "";
     //cout << "*" << s.size() << endl;
    //int flag = 0;
    LL t;
    LL i;
    //cout << len << endl;
    for (i = len-1; i >=0; i--) {

        LL tmp = ps[i] - '0';

        //cout << i << endl;

        while (tmp < 9) {
            if ((num - (tmp+1) - sum[idx-1][i]) < 0){
                //flag = 1;
                //cout << "*";
                break;
            }
            //if (idx == 3 and i == 2)
            //cout << "#" << tmp << endl;
            if ((num - (tmp+1) - sum[idx-1][i]) > 9*(len-1-i)) {
                tmp++;
                //cout << "#";
                continue;
            }
            //cout << "#" << (num - (1+tmp) - sum[idx-1][i]) << endl;
            //cout << "#" << tmp << endl;
            s = solve ((num - (tmp+1) - sum[idx-1][i]));
        //  if (idx == 1 and i == 0)
            //  cout << "*" << tmp << endl;

                //cout << "*" << idx << endl;
                if (s.size() + i + 1 > len) {
                    tmp++;

                }
                else if (s.size() + i + 1<= len) {

                    //cout << "*";
                    //cout << "*" << idx << endl;
                     t = (len - (s.size()+i+1));
                    // cout << t << "*" <<  endl;
                     if (s.size() != 0)
                         reverse(s.begin(), s.end());
                    while (t--){
                        s += '0';
                    }

                tmp++;
                //cout << "*" << tmp << endl;

                s += tmp + '0';
                t = i-1;
                while (t >= 0) {
                    s += ps[t];
                    t--;
                }
                reverse(s.begin(),s.end());
                return s;
                }

        }
    }

    //if (flag == 1) {
        //cout << "#" << len <<" " << num<< endl;;
        s = supersolve(len+1, num);
        return s;
    //}

}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("/home/spharish/input.txt", "r", stdin);
    #endif
    cin >> n;

    LL i;
    rep (i,n)  {
        cin >> b[i];
    }

    a[0] = solve(b[0]);
    cout << a[0] << endl;
    LL j;
    f(i, 1, n) {
        a[i] = compute(a[i-1], b[i], i);
        cout << a[i] << endl;
        sum[i][1] = a[i][0] - '0';
        for (j = 2; j <= n; j++) {
            sum[i][j] = sum[i][j-1] + a[i][j-1] - '0';

        }
        //cout << a[i];
    }

    /*rep (i,n) {
        cout << a[i] << endl;
    }*/

    return 0;
}


#include <bits/stdc++.h>
#define f(i, a, n) for (i = a; i < n; i++)
#define fd(i, n, a) for (i = n; i >= a; i--)
#define rep(i,n) f(i,0,n)
#define repd(i,n) f(i, n, 0)
#define pb push_back
#define MOD 1000000007

#define s(x) scanf("%lld", &x); //s(x) is for long long int.
#define si(x) scanf("%d", &x);
#define sf(x) scanf("%f", &x);
#define sd(x) scanf("%lf", &x);
#define ss(x) scanf("%s", x);

#define psp printf(" "); //Print space - psp;
#define pnl printf("\n"); //Print new line - pnl;

#define p(x) printf("%lld", x);  //p(x) is for long long int.
#define pn(x) printf("%lld\n", x);  //..n(x) is for printing with New Line.
#define ps(x) printf("%lld ", x);  //..s(x) is for printing with Space.

#define pi(x) printf("%d", x);
#define pin(x) printf("%d\n", x);
#define pis(x) printf("%d ", x);
#define pf(x) printf("%f", x);
#define pfn(x) printf("%f\n", x);
#define pfs(x) printf("%f ", x);
#define pd(x) printf("%lf", x);
#define pdn(x) printf("%lf\n", x);
#define pds(x) printf("%lf ", x);

typedef long long int LL;
using namespace std;
int n;
string a[305];
int b[305];
int sum[306][400];
int checker = 0;

string solve(int num) {
    string tmp = "";

    while (num > 9) {
        tmp += "9";
        num -= 9;

    }
    if (num > 0 and num < 10) {
        tmp += num + '0';
    }
    else if (num >= 10) {
        return "lol";
    }
    if (tmp.size() != 0) {
    reverse(tmp.begin(),tmp.end());
    }
    if (checker == 0) {
        if (tmp.size() != 0) {

    sum[0][1] = tmp[0] - '0';
    int i;
    f (i, 1, (tmp.size())) {
        sum[0][i+1] = tmp[i] - '0';
        sum[0][i+1]  += sum[0][i];
    }
    }
    checker = 1;
    }

    return tmp;
}
string supersolve(int len, int sum)
{
    string s = "";
    if (len == 1) {
        s += sum + '0';
        return s;
    }
    if (sum < 9*len) {
        for (int i = 1; i <= 9; i++) {
            if (9*(len-1) >= (sum-i)) {
                s += i + '0';
                sum -= i;
                len--;

                break;
            }
        }
        int j = 0;
        while (j < len) {
            if (j == len-1) {
                s += sum + '0';

                break;
            }
            for (int i = 0; i <= 9; i++) {
                if (9*(len-1) >= (sum-i)) {
                    s += i + '0';
                    len--;
                    sum -= i;

                    break;
                }
            }
        }
        return s;
    }
    else {
        return solve(sum);
    }
}
string compute (string ps, int num, int idx) {
    //cout << "*" << idx << endl;
    int len = ps.size();
    string s = "";
     //cout << "*" << s.size() << endl;
    //int flag = 0;
    int t;
    int i;
    //cout << len << endl;
    for (i = len-1; i >=0; i--) {

        int tmp = ps[i] - '0';

        //cout << i << endl;

        while (tmp < 9) {
            if ((num - (tmp+1) - sum[idx-1][i]) < 0){
                //flag = 1;
                //cout << "*";
                break;
            }
            //if (idx == 3 and i == 2)
            //cout << "#" << tmp << endl;
            if ((num - (tmp+1) - sum[idx-1][i]) > 9*(len-1-i)) {
                tmp++;
                //cout << "#";
                continue;
            }
            //cout << "#" << (num - (1+tmp) - sum[idx-1][i]) << endl;
            //cout << "#" << tmp << endl;
            s = solve ((num - (tmp+1) - sum[idx-1][i]));
        //  if (idx == 1 and i == 0)
            //  cout << "*" << tmp << endl;

                //cout << "*" << idx << endl;
                if (s.size() + i + 1 > len) {
                    tmp++;

                }
                else if (s.size() + i + 1<= len) {

                    //cout << "*";
                    //cout << "*" << idx << endl;
                     t = (len - (s.size()+i+1));
                    // cout << t << "*" <<  endl;
                     if (s.size() != 0)
                         reverse(s.begin(), s.end());
                    while (t--){
                        s += "0";
                    }

                tmp++;
                //cout << "*" << tmp << endl;

                s += tmp + '0';
                t = i-1;
                while (t >= 0) {
                    s += ps[t];
                    t--;
                }
                reverse(s.begin(),s.end());
                return s;
                }

        }
    }

    //if (flag == 1) {
        //cout << "#" << len <<" " << num<< endl;;
        s = supersolve(len+1, num);
        return s;
    //}

}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("/home/spharish/input.txt", "r", stdin);
    #endif
    cin >> n;

    int i;
    rep (i,n)  {
        cin >> b[i];
    }

    a[0] = solve(b[0]);
    cout << a[0] << endl;
    int j;
    f(i, 1, n) {
        a[i] = compute(a[i-1], b[i], i);
        cout << a[i] << endl;
        sum[i][1] = a[i][0] - '0';
        for (j = 2; j <= n; j++) {
            sum[i][j] = sum[i][j-1];
            sum[i][j] += a[i][j-1] - '0';

        }
        //cout << a[i];
    }

    /*rep (i,n) {
        cout << a[i] << endl;
    }*/

    return 0;
}


#include <bits/stdc++.h>
#define f(i, a, n) for (i = a; i < n; i++)
#define fd(i, n, a) for (i = n; i >= a; i--)
#define rep(i,n) f(i,0,n)
#define repd(i,n) f(i, n, 0)
#define pb push_back
#define MOD 1000000007

#define s(x) scanf("%lld", &x); //s(x) is for long long int.
#define si(x) scanf("%d", &x);
#define sf(x) scanf("%f", &x);
#define sd(x) scanf("%lf", &x);
#define ss(x) scanf("%s", x);

#define psp printf(" "); //Print space - psp;
#define pnl printf("\n"); //Print new line - pnl;

#define p(x) printf("%lld", x);  //p(x) is for long long int.
#define pn(x) printf("%lld\n", x);  //..n(x) is for printing with New Line.
#define ps(x) printf("%lld ", x);  //..s(x) is for printing with Space.

#define pi(x) printf("%d", x);
#define pin(x) printf("%d\n", x);
#define pis(x) printf("%d ", x);
#define pf(x) printf("%f", x);
#define pfn(x) printf("%f\n", x);
#define pfs(x) printf("%f ", x);
#define pd(x) printf("%lf", x);
#define pdn(x) printf("%lf\n", x);
#define pds(x) printf("%lf ", x);

typedef long long int LL;
using namespace std;
int n;
string a[305];
int b[305];
int sum[305][400];
int checker = 0;

string solve(int num) {
    string tmp = "";

    while (num > 9) {
        tmp += "9";
        num -= 9;

    }
    if (num > 0 and num < 10) {
        tmp += char(num + '0');
    }
    else if (num >= 10) {
        return "lol";
    }
    if (tmp.size() != 0) {
    reverse(tmp.begin(),tmp.end());
    }
    if (checker == 0) {
        if (tmp.size() != 0) {

    sum[0][1] = tmp[0] - '0';
    int i;
    f (i, 1, (tmp.size())) {
        sum[0][i+1] = tmp[i] - '0';
        sum[0][i+1]  += sum[0][i];
    }
    }
    checker = 1;
    }

    return tmp;
}
string supersolve(int len, int sum)
{
    string s = "";
    if (len == 1) {
        s += char(sum + '0');
        return s;
    }
    if (sum < 9*len) {
        for (int i = 1; i <= 9; i++) {
            if (9*(len-1) >= (sum-i)) {
                s += char(i + '0');
                sum -= i;
                len--;

                break;
            }
        }
        int j = 0;
        while (j < len) {
            if (j == len-1) {
                s += char(sum + '0');

                break;
            }
            for (int i = 0; i <= 9; i++) {
                if (9*(len-1) >= (sum-i)) {
                    s += char(i + '0');
                    len--;
                    sum -= i;

                    break;
                }
            }
        }
        return s;
    }
    else {
        return solve(sum);
    }
}
string compute (string ps, int num, int idx) {
    //cout << "*" << idx << endl;
    int len = ps.size();
    string s = "";
     //cout << "*" << s.size() << endl;
    //int flag = 0;
    int t;
    int i;
    //cout << len << endl;
    for (i = len-1; i >=0; i--) {

        int tmp = ps[i] - '0';

        //cout << i << endl;

        while (tmp < 9) {
            if ((num - (tmp+1) - sum[idx-1][i]) < 0){
                //flag = 1;
                //cout << "*";
                break;
            }
            //if (idx == 3 and i == 2)
            //cout << "#" << tmp << endl;
            if ((num - (tmp+1) - sum[idx-1][i]) > 9*(len-1-i)) {
                tmp++;
                //cout << "#";
                continue;
            }
            //cout << "#" << (num - (1+tmp) - sum[idx-1][i]) << endl;
            //cout << "#" << tmp << endl;
            s = solve ((num - (tmp+1) - sum[idx-1][i]));
        //  if (idx == 1 and i == 0)
            //  cout << "*" << tmp << endl;

                //cout << "*" << idx << endl;
                if (s.size() + i + 1 > len) {
                    tmp++;

                }
                else if (s.size() + i + 1<= len) {

                    //cout << "*";
                    //cout << "*" << idx << endl;
                     t = (len - (s.size()+i+1));
                    // cout << t << "*" <<  endl;
                     if (s.size() != 0)
                         reverse(s.begin(), s.end());
                    while (t--){
                        s += "0";
                    }

                tmp++;
                //cout << "*" << tmp << endl;

                s += char(tmp + '0');
                t = i-1;
                while (t >= 0) {
                    s += ps[t];
                    t--;
                }
                reverse(s.begin(),s.end());
                return s;
                }

        }
    }

    //if (flag == 1) {
        //cout << "#" << len <<" " << num<< endl;;
        s = supersolve(len+1, num);
        return s;
    //}

}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("/home/spharish/input.txt", "r", stdin);
    #endif
    cin >> n;

    int i;
    rep (i,n)  {
        cin >> b[i];
    }

    a[0] = solve(b[0]);
    cout << a[0] << endl;
    int j;
    f(i, 1, n) {
        a[i] = compute(a[i-1], b[i], i);
        cout << a[i] << endl;
        sum[i][1] = a[i][0] - '0';
        for (j = 2; j <= n; j++) {
            sum[i][j] = sum[i][j-1];
            sum[i][j] += a[i][j-1] - '0';

        }
        //cout << a[i];
    }

    /*rep (i,n) {
        cout << a[i] << endl;
    }*/

    return 0;
}


#include <bits/stdc++.h>

#define f(i, a, n) for (i = a; i < n; i++)
#define fd(i, n, a) for (i = n; i >= a; i--)
#define rep(i,n) f(i,0,n)
#define repd(i,n) f(i, n, 0)
#define pb push_back
#define MOD 1000000007

#define s(x) scanf("%lld", &x); //s(x) is for long long LL.
#define si(x) scanf("%d", &x);
#define sf(x) scanf("%f", &x);
#define sd(x) scanf("%lf", &x);
#define ss(x) scanf("%s", x);

#define psp prLLf(" "); //PrLL space - psp;
#define pnl prLLf("\n"); //PrLL new line - pnl;

#define p(x) prLLf("%lld", x);  //p(x) is for long long LL.
#define pn(x) prLLf("%lld\n", x);  //..n(x) is for prLLing with New Line.
#define ps(x) prLLf("%lld ", x);  //..s(x) is for prLLing with Space.

#define pi(x) prLLf("%d", x);
#define pin(x) prLLf("%d\n", x);
#define pis(x) prLLf("%d ", x);
#define pf(x) prLLf("%f", x);
#define pfn(x) prLLf("%f\n", x);
#define pfs(x) prLLf("%f ", x);
#define pd(x) prLLf("%lf", x);
#define pdn(x) prLLf("%lf\n", x);
#define pds(x) prLLf("%lf ", x);

typedef long long int LL;
using namespace std;
LL n;
string a[305];
LL b[305];
LL sum[305][400];
int checker = 0;

string solve(LL num) {
    string tmp = "";

    while (num > 9) {
        tmp += "9";
        num -= 9;

    }
    if (num > 0 and num < 10) {
        tmp += char(num + '0');
    }
    else if (num >= 10) {
        return "lol";
    }
    if (tmp.size() != 0) {
    reverse(tmp.begin(),tmp.end());
    }
    if (checker == 0 and tmp.size() != 0) {
    sum[0][1] = tmp[0] - '0';
    LL i;
    f (i, 1, (tmp.size())) {
        sum[0][i+1] = tmp[i] - '0' + sum[0][i];
    }
    checker = 1;
    }

    return tmp;
}
string supersolve(LL len, LL sum)
{
    string s = "";
    if (len == 1) {
        s += char(sum + '0');
        return s;
    }
    if (sum < 9*len) {
        for (LL i = 1; i <= 9; i++) {
            if (9*(len-1) >= (sum-i)) {
                s += char(i + '0');
                sum -= i;
                len--;

                break;
            }
        }
        LL j = 0;
        while (j < len) {
            if (j == len-1) {
                s += char(sum + '0');

                break;
            }
            for (LL i = 0; i <= 9; i++) {
                if (9*(len-1) >= (sum-i)) {
                    s += char(i + '0');
                    len--;
                    sum -= i;

                    break;
                }
            }
        }
        return s;
    }
    else {
        return solve(sum);
    }
}
string compute (string ps, LL num, LL idx) {
    //cout << "*" << idx << endl;
    LL len = ps.size();
    string s = "";
     //cout << "*" << s.size() << endl;
    //int flag = 0;
    LL t;
    LL i;
    //cout << len << endl;
    for (i = len-1; i >=0; i--) {

        LL tmp = ps[i] - '0';

        //cout << i << endl;

        while (tmp < 9) {
            if ((num - (tmp+1) - sum[idx-1][i]) < 0){
                //flag = 1;
                //cout << "*";
                break;
            }
            //if (idx == 3 and i == 2)
            //cout << "#" << tmp << endl;
            if ((num - (tmp+1) - sum[idx-1][i]) > 9*(len-1-i)) {
                tmp++;
                //cout << "#";
                continue;
            }
            //cout << "#" << (num - (1+tmp) - sum[idx-1][i]) << endl;
            //cout << "#" << tmp << endl;
            s = solve ((num - (tmp+1) - sum[idx-1][i]));
        //  if (idx == 1 and i == 0)
            //  cout << "*" << tmp << endl;

                //cout << "*" << idx << endl;
                if (s.size() + i + 1 > len) {
                    tmp++;

                }
                else if (s.size() + i + 1<= len) {

                    //cout << "*";
                    //cout << "*" << idx << endl;
                     t = (len - (s.size()+i+1));
                    // cout << t << "*" <<  endl;
                     if (s.size() != 0)
                         reverse(s.begin(), s.end());
                    while (t--){
                        s += char('0');
                    }

                tmp++;
                //cout << "*" << tmp << endl;

                s += char(tmp + '0');
                t = i-1;
                while (t >= 0) {
                    s += ps[t];
                    t--;
                }
                reverse(s.begin(),s.end());
                return s;
                }

        }
    }

    //if (flag == 1) {
        //cout << "#" << len <<" " << num<< endl;;
        s = supersolve(len+1, num);
        return s;
    //}

}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("/home/spharish/input.txt", "r", stdin);
    #endif
    cin >> n;

    LL i;
    rep (i,n)  {
        cin >> b[i];
    }

    a[0] = solve(b[0]);
    cout << a[0] << endl;
    LL j;
    f(i, 1, n) {
        a[i] = compute(a[i-1], b[i], i);
        cout << a[i] << endl;
        sum[i][1] = a[i][0] - '0';
        for (j = 2; j <= n; j++) {
            sum[i][j] = sum[i][j-1] + a[i][j-1] - '0';

        }
        //cout << a[i];
    }

    /*rep (i,n) {
        cout << a[i] << endl;
    }*/

    return 0;
}


#include <bits/stdc++.h>

#define f(i, a, n) for (i = a; i < n; i++)
#define fd(i, n, a) for (i = n; i >= a; i--)
#define rep(i,n) f(i,0,n)
#define repd(i,n) f(i, n, 0)
#define pb push_back
#define MOD 1000000007

#define s(x) scanf("%lld", &x); //s(x) is for long long LL.
#define si(x) scanf("%d", &x);
#define sf(x) scanf("%f", &x);
#define sd(x) scanf("%lf", &x);
#define ss(x) scanf("%s", x);

#define psp prLLf(" "); //PrLL space - psp;
#define pnl prLLf("\n"); //PrLL new line - pnl;

#define p(x) prLLf("%lld", x);  //p(x) is for long long LL.
#define pn(x) prLLf("%lld\n", x);  //..n(x) is for prLLing with New Line.
#define ps(x) prLLf("%lld ", x);  //..s(x) is for prLLing with Space.

#define pi(x) prLLf("%d", x);
#define pin(x) prLLf("%d\n", x);
#define pis(x) prLLf("%d ", x);
#define pf(x) prLLf("%f", x);
#define pfn(x) prLLf("%f\n", x);
#define pfs(x) prLLf("%f ", x);
#define pd(x) prLLf("%lf", x);
#define pdn(x) prLLf("%lf\n", x);
#define pds(x) prLLf("%lf ", x);

typedef long long int LL;
using namespace std;
LL n;
string a[305];
LL b[305];
LL sum[305][400];
int checker = 0;

string solve(LL num) {
    string tmp = "";

    while (num > 9) {
        tmp += "9";
        num -= 9;

    }
    if (num > 0 and num < 10) {

        tmp += char(num + '0');
    }
    else if (num >= 10) {
        return "lol";
    }
    if (tmp.size() != 0) {
    reverse(tmp.begin(),tmp.end());
    }
    if (checker == 0 and tmp.size() != 0) {
    sum[0][1] = tmp[0] - '0';
    LL i;
    f (i, 1, (tmp.size())) {
        sum[0][i+1] = tmp[i] - '0' + sum[0][i];
    }
    checker = 1;
    }

    return tmp;
}
string supersolve(LL len, LL sum)
{
    string s = "";
    if (len == 1) {
        s += sum + '0';
        return s;
    }
    if (sum < 9*len) {
        for (LL i = 1; i <= 9; i++) {
            if (9*(len-1) >= (sum-i)) {
                s += i + '0';
                sum -= i;
                len--;

                break;
            }
        }
        LL j = 0;
        while (j < len) {
            if (j == len-1) {
                s += sum + '0';

                break;
            }
            for (LL i = 0; i <= 9; i++) {
                if (9*(len-1) >= (sum-i)) {
                    s += i + '0';
                    j++;
                    sum -= i;

                    break;
                }
            }
        }
        return s;
    }
    else {
        return solve(sum);
    }
}
string compute (string ps, LL num, LL idx) {
    //cout << "*" << idx << endl;
    LL len = ps.size();
    string s = "";
     //cout << "*" << s.size() << endl;
    //int flag = 0;
    LL t;
    LL i;
    //cout << len << endl;
    for (i = len-1; i >=0; i--) {

        LL tmp = ps[i] - '0';
        //cout << i << endl;
        while (tmp < 9) {
            if ((num - (1+tmp) - sum[idx-1][i]) < 0){
                //flag = 1;
                //cout << "*";
                break;
            }
            if ((num - (1+tmp) - sum[idx-1][i]) > 9*(len-1-i)) {
                tmp++;
                //cout << "#";
                continue;
            }
            //cout << "#" << (num - (1+tmp) - sum[idx-1][i]) << endl;
            s = solve ((num - (1+tmp) - sum[idx-1][i]));
            //cout << "*" << s << endl;

                //cout << "*" << idx << endl;
                if (s.size() + i + 1 > len) {
                    tmp++;
                    //cout << "sp" << endl;

                }
                else if (s.size() + i + 1<= len) {
                    //cout << "vi" << endl;
                    //cout << "*";
                    //cout << "*" << idx << endl;
                     t = (len - (s.size()+i+1));
                    // cout << t << "*" <<  endl;
                    while (t--){
                        s += '0';
                    }
                if (s.size() != 0)
                    reverse(s.begin(), s.end());
                tmp++;
                //cout << "*" << tmp << endl;
                s += tmp + '0';
                t = i-1;
                while (t >= 0) {
                    s += ps[t];
                    t--;
                }
                reverse(s.begin(),s.end());
                return s;
                }

        }
    }

    //if (flag == 1) {
        //cout << "#" << len <<" " << num<< endl;;
        s = supersolve(len+1, num);
        return s;
    //}

}

int main()
{
    #ifndef ONLINE_JUDGE
    //freopen("/home/spharish/input.txt", "r", stdin);
    #endif
    cin >> n;
    LL i;
    rep (i,n)  {
        cin >> b[i];
    }

    a[0] = solve(b[0]);
    //cout << a[0] << endl;
    LL j;
    f(i, 1, n) {
        a[i] = compute(a[i-1], b[i], i);
        sum[i][1] = a[i][0] - '0';
        for (j = 2; j <= n; j++) {
            sum[i][j] = sum[i][j] + a[i][j-1] - '0';

        }
        //cout << a[i];
    }

    rep (i,n) {
        cout << a[i] << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
#define f(i, a, n) for (i = a; i < n; i++)
#define fd(i, n, a) for (i = n; i >= a; i--)
#define rep(i,n) f(i,0,n)
#define repd(i,n) f(i, n, 0)
#define pb push_back
#define MOD 1000000007

#define s(x) scanf("%lld", &x); //s(x) is for long long int.
#define si(x) scanf("%d", &x);
#define sf(x) scanf("%f", &x);
#define sd(x) scanf("%lf", &x);
#define ss(x) scanf("%s", x);

#define psp printf(" "); //Print space - psp;
#define pnl printf("\n"); //Print new line - pnl;

#define p(x) printf("%lld", x);  //p(x) is for long long int.
#define pn(x) printf("%lld\n", x);  //..n(x) is for printing with New Line.
#define ps(x) printf("%lld ", x);  //..s(x) is for printing with Space.

#define pi(x) printf("%d", x);
#define pin(x) printf("%d\n", x);
#define pis(x) printf("%d ", x);
#define pf(x) printf("%f", x);
#define pfn(x) printf("%f\n", x);
#define pfs(x) printf("%f ", x);
#define pd(x) printf("%lf", x);
#define pdn(x) printf("%lf\n", x);
#define pds(x) printf("%lf ", x);

typedef long long int LL;
using namespace std;
int n;
string a[305];
int b[305];
int sum[305][400];
int checker = 0;

string solve(int num) {
    string tmp = "";

    while (num > 9) {
        tmp += "9";
        num -= 9;

    }
    if (num > 0 and num < 10) {
        tmp += (num + '0');
    }
    else if (num >= 10) {
        return "lol";
    }
    if (tmp.size() != 0) {
    reverse(tmp.begin(),tmp.end());
    }
    if (checker == 0) {
        if (tmp.size() != 0) {

    sum[0][1] = (tmp[0] - '0');
    int i;
    f (i, 1, (tmp.size())) {
        sum[0][i+1] = (tmp[i] - '0');
        sum[0][i+1]  += sum[0][i];
    }
    }
    checker = 1;
    }

    return tmp;
}
string supersolve(int len, int sum)
{
    string s = "";
    if (len == 1) {
        s += (sum + '0');
        return s;
    }
    if (sum < 9*len) {
        for (int i = 1; i <= 9; i++) {
            if (9*(len-1) >= (sum-i)) {
                s += (i + '0');
                sum -= i;
                len--;

                break;
            }
        }
        int j = 0;
        while (j < len) {
            if (j == len-1) {
                s += (sum + '0');

                break;
            }
            for (int i = 0; i <= 9; i++) {
                if (9*(len-1) >= (sum-i)) {
                    s += (i + '0');
                    len--;
                    sum -= i;

                    break;
                }
            }
        }
        return s;
    }
    else {
        return solve(sum);
    }
}
string compute (string ps, int num, int idx) {
    //cout << "*" << idx << endl;
    int len = ps.size();
    string s = "";
     //cout << "*" << s.size() << endl;
    //int flag = 0;
    int t;
    int i;
    //cout << len << endl;
    for (i = len-1; i >=0; i--) {

        int tmp = ps[i] - '0';

        //cout << i << endl;

        while (tmp < 9) {
            if ((num - (tmp+1) - sum[idx-1][i]) < 0){
                //flag = 1;
                //cout << "*";
                break;
            }
            //if (idx == 3 and i == 2)
            //cout << "#" << tmp << endl;
            if ((num - (tmp+1) - sum[idx-1][i]) > 9*(len-1-i)) {
                tmp++;
                //cout << "#";
                continue;
            }
            //cout << "#" << (num - (1+tmp) - sum[idx-1][i]) << endl;
            //cout << "#" << tmp << endl;
            s = solve ((num - (tmp+1) - sum[idx-1][i]));
        //  if (idx == 1 and i == 0)
            //  cout << "*" << tmp << endl;

                //cout << "*" << idx << endl;
                if (s.size() + i + 1 > len) {
                    tmp++;

                }
                else if (s.size() + i + 1<= len) {

                    //cout << "*";
                    //cout << "*" << idx << endl;
                     t = (len - (s.size()+i+1));
                    // cout << t << "*" <<  endl;
                     if (s.size() != 0)
                         reverse(s.begin(), s.end());
                    while (t--){
                        s += "0";
                    }

                tmp++;
                //cout << "*" << tmp << endl;

                s += (tmp + '0');
                t = i-1;
                while (t >= 0) {
                    s += (ps[t]);
                    t--;
                }
                reverse(s.begin(),s.end());
                return s;
                }

        }
    }

    //if (flag == 1) {
        //cout << "#" << len <<" " << num<< endl;;
        s = supersolve(len+1, num);
        return s;
    //}

}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("/home/spharish/input.txt", "r", stdin);
    #endif
    cin >> n;

    int i;
    rep (i,n)  {
        cin >> b[i];
    }

    a[0] = solve(b[0]);
    cout << a[0] << endl;
    int j;
    f(i, 1, n) {
        a[i] = compute(a[i-1], b[i], i);
        cout << a[i] << endl;
        sum[i][1] = a[i][0] - '0';
        for (j = 2; j <= n; j++) {
            sum[i][j] = sum[i][j-1];
            sum[i][j] += a[i][j-1] - '0';

        }
        //cout << a[i];
    }

    /*rep (i,n) {
        cout << a[i] << endl;
    }*/

    return 0;
}


#include <bits/stdc++.h>
#define f(i, a, n) for (i = a; i < n; i++)
#define fd(i, n, a) for (i = n; i >= a; i--)
#define rep(i,n) f(i,0,n)
#define repd(i,n) f(i, n, 0)
#define pb push_back
#define MOD 1000000007

#define s(x) scanf("%lld", &x); //s(x) is for long long int.
#define si(x) scanf("%d", &x);
#define sf(x) scanf("%f", &x);
#define sd(x) scanf("%lf", &x);
#define ss(x) scanf("%s", x);

#define psp printf(" "); //Print space - psp;
#define pnl printf("\n"); //Print new line - pnl;

#define p(x) printf("%lld", x);  //p(x) is for long long int.
#define pn(x) printf("%lld\n", x);  //..n(x) is for printing with New Line.
#define ps(x) printf("%lld ", x);  //..s(x) is for printing with Space.

#define pi(x) printf("%d", x);
#define pin(x) printf("%d\n", x);
#define pis(x) printf("%d ", x);
#define pf(x) printf("%f", x);
#define pfn(x) printf("%f\n", x);
#define pfs(x) printf("%f ", x);
#define pd(x) printf("%lf", x);
#define pdn(x) printf("%lf\n", x);
#define pds(x) printf("%lf ", x);

typedef long long int LL;
using namespace std;
int n;
string a[305];
int b[305];
int sum[305][400];
int checker = 0;

string solve(int num) {
    string tmp = "";

    while (num > 9) {
        tmp += "9";
        num -= 9;

    }
    if (num > 0 and num < 10) {
        tmp += (num + '0');
    }
    else if (num >= 10) {
        return "lol";
    }
    if (tmp.size() != 0) {
    reverse(tmp.begin(),tmp.end());
    }
    if (checker == 0) {
        if (tmp.size() != 0) {

    sum[0][1] = (tmp[0] - '0');
    int i;
    f (i, 1, (tmp.size())) {
        sum[0][i+1] = (tmp[i] - '0');
        sum[0][i+1]  += sum[0][i];
    }
    }
    checker = 1;
    }

    return tmp;
}
string supersolve(int len, int sum)
{
    string s = "";
    if (len == 1) {
        s += (sum + '0');
        return s;
    }
    if (sum < 9*len) {
        for (int i = 1; i <= 9; i++) {
            if (9*(len-1) >= (sum-i)) {
                s += (i + '0');
                sum -= i;
                len--;

                break;
            }
        }
        int j = 0;
        while (j < len) {
            if (j == len-1) {
                s += (sum + '0');

                break;
            }
            for (int i = 0; i <= 9; i++) {
                if (9*(len-1) >= (sum-i)) {
                    s += (i + '0');
                    len--;
                    sum -= i;

                    break;
                }
            }
        }
        return s;
    }
    else {
        return solve(sum);
    }
}
string compute (string ps, int num, int idx) {
    //cout << "*" << idx << endl;
    int len = ps.size();
    string s = "";
     //cout << "*" << s.size() << endl;
    //int flag = 0;
    int t;
    int i;
    //cout << len << endl;
    for (i = len-1; i >=0; i--) {

        int tmp = ps[i] - '0';

        //cout << i << endl;

        while (tmp < 9) {
            if ((num - (tmp+1) - sum[idx-1][i]) < 0){
                //flag = 1;
                //cout << "*";
                break;
            }
            //if (idx == 3 and i == 2)
            //cout << "#" << tmp << endl;
            if ((num - (tmp+1) - sum[idx-1][i]) > 9*(len-1-i)) {
                tmp++;

                continue;
            }
            //cout << "#" << (num - (1+tmp) - sum[idx-1][i]) << endl;
            //cout << "#" << tmp << endl;
            s = solve ((num - (tmp+1) - sum[idx-1][i]));
        //  if (idx == 1 and i == 0)
            //  cout << "*" << tmp << endl;

                //cout << "*" << idx << endl;
                if (s.size() + i + 1 > len) {
                    tmp++;

                }
                else if (s.size() + i + 1<= len) {

                    //cout << "*";
                    //cout << "*" << idx << endl;
                     t = (len - (s.size()+i+1));
                    // cout << t << "*" <<  endl;

                     if (s.size() != 0)
                         reverse(s.begin(), s.end());
                    while (t--){
                        s += "0";
                    }

                tmp++;
                //cout << "*" << tmp << endl;

                s += (tmp + '0');

                t = i-1;
                while (t >= 0) {
                    s += ps[t];
                    t--;
                }

                reverse(s.begin(),s.end());
                return s;
                }

        }
    }

    //if (flag == 1) {
        //cout << "#" << len <<" " << num<< endl;;
        s = supersolve(len+1, num);
        return s;
    //}

}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("/home/spharish/input.txt", "r", stdin);
    #endif
    cin >> n;

    int i;
    rep (i,n)  {
        cin >> b[i];
    }

    a[0] = solve(b[0]);
    cout << a[0] << endl;
    int j;
    f(i, 1, n) {
        a[i] = compute(a[i-1], b[i], i);
        cout << a[i] << endl;
        sum[i][1] = a[i][0] - '0';
        for (j = 2; j <= n; j++) {
            sum[i][j] = sum[i][j-1];
            sum[i][j] += a[i][j-1] - '0';

        }
        //cout << a[i];
    }

    /*rep (i,n) {
        cout << a[i] << endl;
    }*/

    return 0;
}


#include <bits/stdc++.h>
//NEVER USE DANGEROUS TEMPLATES !!!!!!!!!!
#define f(i, a, n) for (i = a; i < n; i++)
#define fd(i, n, a) for (i = n; i >= a; i--)
#define rep(i,n) f(i,0,n)
#define repd(i,n) f(i, n, 0)
#define pb push_back
#define MOD 1000000007

#define s(x) scanf("%lld", &x); //s(x) is for long long int.
#define si(x) scanf("%d", &x);
#define sf(x) scanf("%f", &x);
#define sd(x) scanf("%lf", &x);
#define ss(x) scanf("%s", x);

#define psp printf(" "); //Print space - psp;
#define pnl printf("\n"); //Print new line - pnl;

#define p(x) printf("%lld", x);  //p(x) is for long long int.
#define pn(x) printf("%lld\n", x);  //..n(x) is for printing with New Line.
#define ps(x) printf("%lld ", x);  //..s(x) is for printing with Space.

#define pi(x) printf("%d", x);
#define pin(x) printf("%d\n", x);
#define pis(x) printf("%d ", x);
#define pf(x) printf("%f", x);
#define pfn(x) printf("%f\n", x);
#define pfs(x) printf("%f ", x);
#define pd(x) printf("%lf", x);
#define pdn(x) printf("%lf\n", x);
#define pds(x) printf("%lf ", x);

typedef long long int LL;
using namespace std;

int b[400];
string s[400];

string solve(int x){
    string ans = "0";
    int cur = 0;
    while(x --){
        if(ans[cur] < '9')
            ans[cur]++;
        else {
            ans += '1';
            cur ++;
        }
    }
    reverse(ans.begin(), ans.end());
    return ans;
}

string supersolve(string s, int cur){
    for(int i=s.size()-1; i>=0; i--){
        if(s[i] == '9')
            continue;
        int sum = 0;
        for(int j=0; j<=i; j++)
            sum += s[j] - '0';
        char tmp = s[i];
        while(s[i] < '9'){
            s[i] ++;
            sum ++;
            if(sum > cur)
                break;
            if(sum == cur){
                for(int j=i+1; j<s.size(); j++)
                    s[j] = '0';
                return s;
            }
            string new = solve(cur - sum);
            if(new.size() <= s.size() - i - 1){
                string ret = s.substr(0, i + 1);
                while(ret.size() + new.size() < s.size())
                    ret += '0';
                ret += new;
                return ret;
            }
        }
        s[i] = tmp;
    }
    if(solve(cur).size() > s.size())
        return solve(cur);
    string ret = "1";
    string new = solve(cur - 1);
    while(ret.size() + new.size() <= s.size())
        ret += '0';
    ret += new;
    return ret;
}

int main(){
    #ifndef ONLINE_JUDGE
        freopen("/home/spharish/input.txt", "r", stdin);
        #endif
    int n;
    cin >> n;
    for(int i=1; i<=n; i++)
        cin >> b[i];
    s[1] = solve(b[1]);
    for(int i=2; i<=n; i++)
        s[i] = supersolve(s[i - 1], b[i]);
    for(int i=1; i<=n; i++)
        cout << s[i] << endl;
}


#include <bits/stdc++.h>
#define f(i, a, n) for (i = a; i < n; i++)
#define fd(i, n, a) for (i = n; i >= a; i--)
#define rep(i,n) f(i,0,n)
#define repd(i,n) f(i, n, 0)
#define pb push_back
#define MOD 1000000007

#define s(x) scanf("%lld", &x); //s(x) is for long long int.
#define si(x) scanf("%d", &x);
#define sf(x) scanf("%f", &x);
#define sd(x) scanf("%lf", &x);
#define ss(x) scanf("%s", x);

#define psp printf(" "); //Print space - psp;
#define pnl printf("\n"); //Print new line - pnl;

#define p(x) printf("%lld", x);  //p(x) is for long long int.
#define pn(x) printf("%lld\n", x);  //..n(x) is for printing with New Line.
#define ps(x) printf("%lld ", x);  //..s(x) is for printing with Space.

#define pi(x) printf("%d", x);
#define pin(x) printf("%d\n", x);
#define pis(x) printf("%d ", x);
#define pf(x) printf("%f", x);
#define pfn(x) printf("%f\n", x);
#define pfs(x) printf("%f ", x);
#define pd(x) printf("%lf", x);
#define pdn(x) printf("%lf\n", x);
#define pds(x) printf("%lf ", x);

typedef long long int LL;
using namespace std;
int n;
string a[305];
int b[306];
int sum[305][400];
int checker = 0;

string solve(int num) {
    string tmp = "";

    while (num > 9) {
        tmp += "9";
        num -= 9;

    }
    if (num > 0 and num < 10) {
        tmp += char(num + '0');
    }
    else if (num >= 10) {
        return "0";
    }
    if (tmp.size() != 0) {
    reverse(tmp.begin(),tmp.end());
    }
    if (checker == 0) {
        if (tmp.size() != 0) {

    sum[0][1] = tmp[0] - '0';
    int i;
    f (i, 1, (tmp.size())) {
        sum[0][i+1] = tmp[i] - '0';
        sum[0][i+1]  += sum[0][i];
    }
    }
    checker = 1;
    }

    return tmp;
}
string supersolve(int len, int sum)
{
    string s = "";
    if (len == 1) {
        s += char(sum + '0');
        return s;
    }
    if (sum < 9*len) {
        for (int i = 1; i <= 9; i++) {
            if (9*(len-1) >= (sum-i)) {
                s += char(i + '0');
                sum -= i;
                len--;

                break;
            }
        }
        int j = 0;
        while (j < len) {
            if (j == len-1) {
                s += char(sum + '0');

                break;
            }
            for (int i = 0; i <= 9; i++) {
                if (9*(len-1) >= (sum-i)) {
                    s += char(i + '0');
                    len--;
                    sum -= i;

                    break;
                }
            }
        }
        return s;
    }
    else {
        return solve(sum);
    }
}
string compute (string ps, int num, int idx) {
    //cout << "*" << idx << endl;
    int len = ps.size();
    string s = "";
     //cout << "*" << s.size() << endl;
    //int flag = 0;
    int t;
    int i;
    //cout << len << endl;
    for (i = len-1; i >=0; i--) {

        int tmp = ps[i] - '0';

        //cout << i << endl;

        while (tmp < 9) {
            if ((num - (tmp+1) - sum[idx-1][i]) < 0){
                //flag = 1;
                //cout << "*";
                break;
            }
            //if (idx == 3 and i == 2)
            //cout << "#" << tmp << endl;
            if ((num - (tmp+1) - sum[idx-1][i]) > 9*(len-1-i)) {
                tmp++;
                //cout << "#";
                continue;
            }
            //cout << "#" << (num - (1+tmp) - sum[idx-1][i]) << endl;
            //cout << "#" << tmp << endl;
            s = solve ((num - (tmp+1) - sum[idx-1][i]));
        //  if (idx == 1 and i == 0)
            //  cout << "*" << tmp << endl;

                //cout << "*" << idx << endl;
                if (s.size() + i + 1 > len) {
                    tmp++;

                }
                else if (s.size() + i + 1<= len) {

                    //cout << "*";
                    //cout << "*" << idx << endl;
                     t = (len - (s.size()+i+1));
                    // cout << t << "*" <<  endl;
                     if (s.size() != 0)
                         reverse(s.begin(), s.end());
                    while (t--){
                        s += "0";
                    }

                tmp++;
                //cout << "*" << tmp << endl;

                s += char(tmp + '0');
                t = i-1;
                while (t >= 0) {
                    s += ps[t];
                    t--;
                }
                reverse(s.begin(),s.end());
                return s;
                }

        }
    }

    //if (flag == 1) {
        //cout << "#" << len <<" " << num<< endl;;
        s = supersolve(len+1, num);
        return s;
    //}

}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("/home/spharish/input.txt", "r", stdin);
    #endif
    cin >> n;

    int i;
    rep (i,n)  {
        cin >> b[i];
    }

    a[0] = solve(b[0]);
    cout << a[0] << endl;
    int j;
    f(i, 1, n) {
        a[i] = compute(a[i-1], b[i], i);
        cout << a[i] << endl;
        sum[i][1] = a[i][0] - '0';
        for (j = 2; j <= n; j++) {
            sum[i][j] = sum[i][j-1];
            sum[i][j] += a[i][j-1] - '0';

        }
        //cout << a[i];
    }

    /*rep (i,n) {
        cout << a[i] << endl;
    }*/

    return 0;
}


#include <bits/stdc++.h>

#define f(i, a, n) for (i = a; i < n; i++)
#define fd(i, n, a) for (i = n; i >= a; i--)
#define rep(i,n) f(i,0,n)
#define repd(i,n) f(i, n, 0)
#define pb push_back
#define MOD 1000000007

#define s(x) scanf("%lld", &x); //s(x) is for long long LL.
#define si(x) scanf("%d", &x);
#define sf(x) scanf("%f", &x);
#define sd(x) scanf("%lf", &x);
#define ss(x) scanf("%s", x);

#define psp prLLf(" "); //PrLL space - psp;
#define pnl prLLf("\n"); //PrLL new line - pnl;

#define p(x) prLLf("%lld", x);  //p(x) is for long long LL.
#define pn(x) prLLf("%lld\n", x);  //..n(x) is for prLLing with New Line.
#define ps(x) prLLf("%lld ", x);  //..s(x) is for prLLing with Space.

#define pi(x) prLLf("%d", x);
#define pin(x) prLLf("%d\n", x);
#define pis(x) prLLf("%d ", x);
#define pf(x) prLLf("%f", x);
#define pfn(x) prLLf("%f\n", x);
#define pfs(x) prLLf("%f ", x);
#define pd(x) prLLf("%lf", x);
#define pdn(x) prLLf("%lf\n", x);
#define pds(x) prLLf("%lf ", x);

typedef long long int LL;
using namespace std;
LL n;
string a[305];
LL b[305];
LL sum[305][400];
int checker = 0;

string solve(LL num) {
    string tmp = "";

    while (num > 9) {
        tmp += "9";
        num -= 9;

    }
    if (num > 0 and num < 10) {
        tmp += char(num + '0');
    }
    else if (num >= 10) {
        return "lol";
    }
    if (tmp.size() != 0) {
    reverse(tmp.begin(),tmp.end());
    }
    if (checker == 0 and tmp.size() != 0) {
    sum[0][1] = (tmp[0] - '0');
    LL i;
    f (i, 1, (tmp.size())) {
        sum[0][i+1] = (tmp[i] - '0');
        sum[0][i+1]  += sum[0][i];
    }
    checker = 1;
    }

    return tmp;
}
string supersolve(LL len, LL sum)
{
    string s = "";
    if (len == 1) {
        s += char(sum + '0');
        return s;
    }
    if (sum < 9*len) {
        for (LL i = 1; i <= 9; i++) {
            if (9*(len-1) >= (sum-i)) {
                s += (i + '0');
                sum -= i;
                len--;

                break;
            }
        }
        LL j = 0;
        while (j < len) {
            if (j == len-1) {
                s += (sum + '0');

                break;
            }
            for (LL i = 0; i <= 9; i++) {
                if (9*(len-1) >= (sum-i)) {
                    s += (i + '0');
                    len--;
                    sum -= i;

                    break;
                }
            }
        }
        return s;
    }
    else {
        return solve(sum);
    }
}
string compute (string ps, LL num, LL idx) {
    //cout << "*" << idx << endl;
    LL len = ps.size();
    string s = "";
     //cout << "*" << s.size() << endl;
    //int flag = 0;
    LL t;
    LL i;
    //cout << len << endl;
    for (i = len-1; i >=0; i--) {

        LL tmp = ps[i] - '0';

        //cout << i << endl;

        while (tmp < 9) {
            if ((num - (tmp+1) - sum[idx-1][i]) < 0){
                //flag = 1;
                //cout << "*";
                break;
            }
            //if (idx == 3 and i == 2)
            //cout << "#" << tmp << endl;
            if ((num - (tmp+1) - sum[idx-1][i]) > 9*(len-1-i)) {
                tmp++;
                //cout << "#";
                continue;
            }
            //cout << "#" << (num - (1+tmp) - sum[idx-1][i]) << endl;
            //cout << "#" << tmp << endl;
            s = solve ((num - (tmp+1) - sum[idx-1][i]));
        //  if (idx == 1 and i == 0)
            //  cout << "*" << tmp << endl;

                //cout << "*" << idx << endl;
                if (s.size() + i + 1 > len) {
                    tmp++;

                }
                else if (s.size() + i + 1<= len) {

                    //cout << "*";
                    //cout << "*" << idx << endl;
                     t = (len - (s.size()+i+1));
                    // cout << t << "*" <<  endl;
                     if (s.size() != 0)
                         reverse(s.begin(), s.end());
                    while (t--){
                        s += "0";
                    }

                tmp++;
                //cout << "*" << tmp << endl;

                s += (tmp + '0');
                t = i-1;
                while (t >= 0) {
                    s += ps[t];
                    t--;
                }
                reverse(s.begin(),s.end());
                return s;
                }

        }
    }

    //if (flag == 1) {
        //cout << "#" << len <<" " << num<< endl;;
        s = supersolve(len+1, num);
        return s;
    //}

}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("/home/spharish/input.txt", "r", stdin);
    #endif
    cin >> n;

    LL i;
    rep (i,n)  {
        cin >> b[i];
    }

    a[0] = solve(b[0]);
    cout << a[0] << endl;
    LL j;
    f(i, 1, n) {
        a[i] = compute(a[i-1], b[i], i);
        cout << a[i] << endl;
        sum[i][1] = a[i][0] - '0';
        for (j = 2; j <= n; j++) {
            sum[i][j] = sum[i][j-1];
            sum[i][j] += (a[i][j-1] - '0');

        }
        //cout << a[i];
    }

    /*rep (i,n) {
        cout << a[i] << endl;
    }*/

    return 0;
}


#include <bits/stdc++.h>

#define f(i, a, n) for (i = a; i < n; i++)
#define fd(i, n, a) for (i = n; i >= a; i--)
#define rep(i,n) f(i,0,n)
#define repd(i,n) f(i, n, 0)
#define pb push_back
#define MOD 1000000007

#define s(x) scanf("%lld", &x); //s(x) is for long long LL.
#define si(x) scanf("%d", &x);
#define sf(x) scanf("%f", &x);
#define sd(x) scanf("%lf", &x);
#define ss(x) scanf("%s", x);

#define psp prLLf(" "); //PrLL space - psp;
#define pnl prLLf("\n"); //PrLL new line - pnl;

#define p(x) prLLf("%lld", x);  //p(x) is for long long LL.
#define pn(x) prLLf("%lld\n", x);  //..n(x) is for prLLing with New Line.
#define ps(x) prLLf("%lld ", x);  //..s(x) is for prLLing with Space.

#define pi(x) prLLf("%d", x);
#define pin(x) prLLf("%d\n", x);
#define pis(x) prLLf("%d ", x);
#define pf(x) prLLf("%f", x);
#define pfn(x) prLLf("%f\n", x);
#define pfs(x) prLLf("%f ", x);
#define pd(x) prLLf("%lf", x);
#define pdn(x) prLLf("%lf\n", x);
#define pds(x) prLLf("%lf ", x);

typedef long long int LL;
using namespace std;
LL n;
string a[305];
LL b[305];
LL sum[305][400];
int checker = 0;

string solve(LL num) {
    string tmp = "";

    while (num > 9) {
        tmp += "9";
        num -= 9;

    }
    if (num > 0 and num < 10) {
        tmp += char(num + '0');
    }
    else if (num >= 10) {
        return "lol";
    }
    if (tmp.size() != 0) {
    reverse(tmp.begin(),tmp.end());
    }
    if (checker == 0 and tmp.size() != 0) {
    sum[0][1] = (tmp[0] - '0');
    LL i;
    f (i, 1, (tmp.size())) {
        sum[0][i+1] = (tmp[i] - '0');
        sum[0][i+1]  += sum[0][i];
    }
    checker = 1;
    }

    return tmp;
}
string supersolve(LL len, LL sum)
{
    string s = "";
    if (len == 1) {
        s += char(sum + '0');
        return s;
    }
    if (sum < 9*len) {
        for (LL i = 1; i <= 9; i++) {
            if (9*(len-1) >= (sum-i)) {
                s += (i + '0');
                sum -= i;
                len--;

                break;
            }
        }
        LL j = 0;
        while (j < len) {
            if (j == len-1) {
                s += (sum + '0');

                break;
            }
            for (LL i = 0; i <= 9; i++) {
                if (9*(len-1) >= (sum-i)) {
                    s += (i + '0');
                    len--;
                    sum -= i;

                    break;
                }
            }
        }
        return s;
    }
    else {
        return solve(sum);
    }
}
string compute (string ps, LL num, LL idx) {
    //cout << "*" << idx << endl;
    LL len = ps.size();
    string s = "";
     //cout << "*" << s.size() << endl;
    //int flag = 0;
    LL t;
    LL i;
    //cout << len << endl;
    for (i = len-1; i >=0; i--) {

        LL tmp = ps[i] - '0';

        //cout << i << endl;

        while (tmp < 9) {
            if ((num - (tmp+1) - sum[idx-1][i]) < 0){
                //flag = 1;
                //cout << "*";
                break;
            }
            //if (idx == 3 and i == 2)
            //cout << "#" << tmp << endl;
            if ((num - (tmp+1) - sum[idx-1][i]) > 9*(len-1-i)) {
                tmp++;
                //cout << "#";
                continue;
            }
            //cout << "#" << (num - (1+tmp) - sum[idx-1][i]) << endl;
            //cout << "#" << tmp << endl;
            s = solve ((num - (tmp+1) - sum[idx-1][i]));
        //  if (idx == 1 and i == 0)
            //  cout << "*" << tmp << endl;

                //cout << "*" << idx << endl;
                if (s.size() + i + 1 > len) {
                    tmp++;

                }
                else if (s.size() + i + 1<= len) {

                    //cout << "*";
                    //cout << "*" << idx << endl;
                     t = (len - (s.size()+i+1));
                    // cout << t << "*" <<  endl;
                     if (s.size() != 0)
                         reverse(s.begin(), s.end());
                    while (t--){
                        s += "0";
                    }

                tmp++;
                //cout << "*" << tmp << endl;

                s += (tmp + '0');
                t = i-1;
                while (t >= 0) {
                    s += ps[t];
                    t--;
                }
                reverse(s.begin(),s.end());
                return s;
                }

        }
    }

    //if (flag == 1) {
        //cout << "#" << len <<" " << num<< endl;;
        s = supersolve(len+1, num);
        return s;
    //}

}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("/home/spharish/input.txt", "r", stdin);
    #endif
    cin >> n;

    LL i;
    rep (i,n)  {
        cin >> b[i];
    }

    a[0] = solve(b[0]);
    cout << a[0] << endl;
    LL j;
    f(i, 1, n) {
        a[i] = compute(a[i-1], b[i], i);
        cout << a[i] << endl;
        sum[i][1] = a[i][0] - '0';
        for (j = 2; j <= n; j++) {
            sum[i][j] = sum[i][j-1];
            sum[i][j] += a[i][j-1] - '0';

        }
        //cout << a[i];
    }

    /*rep (i,n) {
        cout << a[i] << endl;
    }*/

    return 0;
}


#include <bits/stdc++.h>
#define f(i, a, n) for (i = a; i < n; i++)
#define fd(i, n, a) for (i = n; i >= a; i--)
#define rep(i,n) f(i,0,n)
#define repd(i,n) f(i, n, 0)
#define pb push_back
#define MOD 1000000007

#define s(x) scanf("%lld", &x); //s(x) is for long long int.
#define si(x) scanf("%d", &x);
#define sf(x) scanf("%f", &x);
#define sd(x) scanf("%lf", &x);
#define ss(x) scanf("%s", x);

#define psp printf(" "); //Print space - psp;
#define pnl printf("\n"); //Print new line - pnl;

#define p(x) printf("%lld", x);  //p(x) is for long long int.
#define pn(x) printf("%lld\n", x);  //..n(x) is for printing with New Line.
#define ps(x) printf("%lld ", x);  //..s(x) is for printing with Space.

#define pi(x) printf("%d", x);
#define pin(x) printf("%d\n", x);
#define pis(x) printf("%d ", x);
#define pf(x) printf("%f", x);
#define pfn(x) printf("%f\n", x);
#define pfs(x) printf("%f ", x);
#define pd(x) printf("%lf", x);
#define pdn(x) printf("%lf\n", x);
#define pds(x) printf("%lf ", x);

typedef long long int LL;
using namespace std;
int n;
string a[305];
int b[305];
int sum[305][400];
int checker = 0;

string solve(int num) {
    string tmp = "";

    while (num > 9) {
        tmp += "9";
        num -= 9;

    }
    if (num > 0 and num < 10) {
        tmp += (num + '0');
    }
    else if (num >= 10) {
        return "lol";
    }
    if (tmp.size() != 0) {
    reverse(tmp.begin(),tmp.end());
    }
    if (checker == 0) {
        if (tmp.size() != 0) {

    sum[0][1] = tmp[0] - '0';
    int i;
    f (i, 1, (tmp.size())) {
        sum[0][i+1] = tmp[i] - '0';
        sum[0][i+1]  += sum[0][i];
    }
    }
    checker = 1;
    }

    return tmp;
}
string supersolve(int len, int sum)
{
    string s = "";
    if (len == 1) {
        s += sum + '0';
        return s;
    }
    if (sum < 9*len) {
        for (int i = 1; i <= 9; i++) {
            if (9*(len-1) >= (sum-i)) {
                s += (i + '0');
                sum -= i;
                len--;

                break;
            }
        }
        int j = 0;
        while (j < len) {
            if (j == len-1) {
                s += (sum + '0');

                break;
            }
            for (int i = 0; i <= 9; i++) {
                if (9*(len-1) >= (sum-i)) {
                    s += (i + '0');
                    len--;
                    sum -= i;

                    break;
                }
            }
        }
        return s;
    }
    else {
        return solve(sum);
    }
}
string compute (string ps, int num, int idx) {
    //cout << "*" << idx << endl;
    int len = ps.size();
    string s = "";
     //cout << "*" << s.size() << endl;
    //int flag = 0;
    int t;
    int i;
    //cout << len << endl;
    for (i = len-1; i >=0; i--) {

        int tmp = ps[i] - '0';

        //cout << i << endl;

        while (tmp < 9) {
            if ((num - (tmp+1) - sum[idx-1][i]) < 0){
                //flag = 1;
                //cout << "*";
                break;
            }
            //if (idx == 3 and i == 2)
            //cout << "#" << tmp << endl;
            if ((num - (tmp+1) - sum[idx-1][i]) > 9*(len-1-i)) {
                tmp++;
                //cout << "#";
                continue;
            }
            //cout << "#" << (num - (1+tmp) - sum[idx-1][i]) << endl;
            //cout << "#" << tmp << endl;
            s = solve ((num - (tmp+1) - sum[idx-1][i]));
        //  if (idx == 1 and i == 0)
            //  cout << "*" << tmp << endl;

                //cout << "*" << idx << endl;
                if (s.size() + i + 1 > len) {
                    tmp++;

                }
                else if (s.size() + i + 1<= len) {

                    //cout << "*";
                    //cout << "*" << idx << endl;
                     t = (len - (s.size()+i+1));
                    // cout << t << "*" <<  endl;
                     if (s.size() != 0)
                         reverse(s.begin(), s.end());
                    while (t--){
                        s += "0";
                    }

                tmp++;
                //cout << "*" << tmp << endl;

                s += (tmp + '0');
                t = i-1;
                while (t >= 0) {
                    s += ps[t];
                    t--;
                }
                reverse(s.begin(),s.end());
                return s;
                }

        }
    }

    //if (flag == 1) {
        //cout << "#" << len <<" " << num<< endl;;
        s = supersolve(len+1, num);
        return s;
    //}

}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("/home/spharish/input.txt", "r", stdin);
    #endif
    cin >> n;

    int i;
    rep (i,n)  {
        cin >> b[i];
    }

    a[0] = solve(b[0]);
    cout << a[0] << endl;
    int j;
    f(i, 1, n) {
        a[i] = compute(a[i-1], b[i], i);
        cout << a[i] << endl;
        sum[i][1] = a[i][0] - '0';
        for (j = 2; j <= n; j++) {
            sum[i][j] = sum[i][j-1];
            sum[i][j] += a[i][j-1] - '0';

        }
        //cout << a[i];
    }

    /*rep (i,n) {
        cout << a[i] << endl;
    }*/

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int b[301];
string s[301];

string Min(int a)
{
    string t="";
    while(a>=10)
    {
        a-=9;
        t+="9";
    }
    t+=char(a+'0');
    reverse(t.begin(),t.end());
    return t;
}
string change1(string a)
{
    int i,L=a.length()-1;
    string b="";
    for(i=0;i<=L;++i)
    {
        if(a[i]!='1')
        {
            b+="1";
            b+=(char)(a[i]-1);
        }
        else b+=a[i];
    }
    return b;
}
string change2(string a,string b)
{
    int l1=a.length(),l2=b.length();
    int l=l1;
    string c="";
    c+=a[0];
    while(l1<=l2)
    {
        c+='0';
        ++l1;
    }
    for(int i=1;i<l;++i)
        c+=a[i];
    return c;
}

int compare(string a,string b)
{
    int l1=a.length(),l2=b.length();
    if(l1>l2) return 1;
    if(l1<l2) return -1;
    for(int i=0;i<l1;++i)
    {
        if(a[i]>b[i]) return 1;
        if(a[i]<b[i]) return -1;
    }
    return 0;
}

int main()
{
    int i,n;
    while(scanf("%d",&n)!=EOF)
    {
        scanf("%d",&b[1]);
        s[1]=Min(b[1]);
        for(i=2;i<=n;++i)
        {
            scanf("%d",&b[i]);
            s[i]=Min(b[i]);
            while(compare(s[i],s[i-1])<=0)
            {
                if(s[i][0]=='1') s[i]=change2(s[i],s[i-1]);
                else s[i]=change1(s[i]);
            }
        }
        for(i=1;i<=n;++i) cout<<s[i]<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int b[301];
string s[301];

string Min(int a)
{
    string t="";
    while(a>=10)
    {
        a-=9;
        t+="9";
    }
    t+=char(a+'0');
    reverse(t.begin(),t.end());
    return t;
}
string change1(string a)
{
    int i,L=a.length()-1;
    string b="";
    for(i=0;i<=L;++i)
    {
        if(a[i]!='1')
        {
            b+="1";
            b+=(char)(a[i]-1);
        }
        else b+=a[i];
    }
    return b;
}
string change2(string a,string b)
{
    int l1=a.length(),l2=b.length();
    string c="";
    c+=a[0];
    while(l1<=l2)
    {
        c+='0';
        ++l1;
    }
    for(int i=1;i<l1;++i)
        c+=a[i];
    return c;
}

int compare(string a,string b)
{
    int l1=a.length(),l2=b.length();
    if(l1>l2) return 1;
    if(l1<l2) return -1;
    for(int i=0;i<l1;++i)
    {
        if(a[i]>b[i]) return 1;
        if(a[i]<b[i]) return -1;
    }
    return 0;
}

int main()
{
    int i,n;
    while(scanf("%d",&n)!=EOF)
    {
        scanf("%d",&b[1]);
        s[1]=Min(b[1]);
        for(i=2;i<=n;++i)
        {
            scanf("%d",&b[i]);
            s[i]=Min(b[i]);
            while(compare(s[i],s[i-1])<=0)
            {
                if(s[i][0]=='1')
                    s[i]=change2(s[i],s[i-1]);
                else
                    s[i]=change1(s[i]);
            }
        }
        for(i=1;i<=n;++i) cout<<s[i]<<"]"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int L,a[305];
void add1(int x)
{
    int i=1;
    while(x)
    {
        if(a[i]==9) ++i;
        else
        {
            ++a[i],--x;
        }
        L=max(L,i);
    }
}
void output()
{
    for(int i=L;i>=1;--i) printf("%d",a[i]);
    puts("");
}
int main()
{
    int n,i,b1,b2;
    scanf("%d",&n);
    L=1;
    scanf("%d",&b1);
    add1(b1);
    output();
    for(i=2;i<=n;++i)
    {
        scanf("%d",&b2);
        int x=b2-b1;
        b1=b2;
        if(x>0) add1(x);
        else
        {
        int k=1;
    while(x<=0)
    {
        x+=a[k];
        a[k++]=0;
        L=max(L,k);
    }
    while(a[k]==9)
    {
        x+=a[k];
        a[k++]=0;
        L=max(L,k);
    }
    ++a[k],--x;
    add1(x);
        }
        output();
    }
    return 0;
}


    import java.util.*;
    public class cpbracket {
        public static void main (String[] args) {
            Scanner in = new Scanner(System.in);
            int T = in.nextInt();
            for (int t = 0; t < T; t++) {
                int n = in.nextInt();
                String s = in.next();
                int c=0;
                for(int i=0;i<n;i++){
                    if(s.charAt(i)=='('){
                        c++;
                    }
                    else{
                        c--;
                        if(c<0){
                            c=0;
                        }
                    }
                }
                System.out.println(c);
            }
        }
    }

→Judgement Protocol


import java.io.*;

public class Main{

    public static void main(String[] args) throws IOException{
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

        int T = Integer.parseInt(in.readLine());

        while(T -- > 0){

            int n = Integer.parseInt(in.readLine());

            String str = in.readLine();
            int res = 0;
            int bal = 0;
            for(int i=0; i<n; i++) {
            	char c = str.charAt(i);

            	if(c == '(') bal ++;
            	else{
            		bal --;
            		if(bal < 0) {
            			res ++;
            			bal = 0;
            		}
            	}
            }

            System.out.println(res);
        }
    }
}


import java.io.*;

public class Main{

    public static void main(String[] args) throws IOException{
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

        int T = Integer.parseInt(in.readLine());

        while(T -- > 0){

            int n = Integer.parseInt(in.readLine());

            String str = in.readLine();
            int res = 0;
            int bal = 0;
            for(int i=n-1; i>=0; i--) {
            	char c = str.charAt(i);

            	if(c == ')') bal ++;
            	else{
            		bal --;
            		if(bal < 0) {
            			res ++;
            			bal = 0;
            		}
            	}
            }

            System.out.println(res);
        }
    }
}


import java.utils.*;
import java.io.*;
public class Solution
{
    public static void main(String[] args)
    {
        Scanner input = new Scanner(System.in);
        input t = input.nextInt();
        for(int i = 0; i < t; i++)
        {
            int n = input.nextInt();
            input.nextLine();
            String s = input.nextLine();
            char[] array = s.toCharArray();
            int a = 0;
            int b = 0;
            int count = 0;
            for(char c : array)
            {
                if(c == '(')
                {
                    a++;
                }
                else
                {
                    b++;
                }
                if(b>a)
                {
                    count++;
                    a=0;
                    b=0;
                }
            }
            System.out.println(count);
        }
    }
}


import java.util.*;
import java.io.*;
public class Solution
{
    public static void main(String[] args)
    {
        Scanner input = new Scanner(System.in);
        int t = input.nextInt();
        for(int i = 0; i < t; i++)
        {
            int n = input.nextInt();
            input.nextLine();
            String s = input.nextLine();
            char[] array = s.toCharArray();
            int a = 0;
            int b = 0;
            int count = 0;
            for(char c : array)
            {
                if(c == '(')
                {
                    a++;
                }
                else
                {
                    b++;
                }
                if(b>a)
                {
                    count++;
                    a=0;
                    b=0;
                }
            }
            System.out.println(count);
        }
    }
}


import java.util.*;
import java.io.*;
public class Solution
{
    public static void main(String[] args)
    {
        Scanner input = new Scanner(System.in);
        input t = input.nextInt();
        for(int i = 0; i < t; i++)
        {
            int n = input.nextInt();
            input.nextLine();
            String s = input.nextLine();
            char[] array = s.toCharArray();
            int a = 0;
            int b = 0;
            int count = 0;
            for(char c : array)
            {
                if(c == '(')
                {
                    a++;
                }
                else
                {
                    b++;
                }
                if(b>a)
                {
                    count++;
                    a=0;
                    b=0;
                }
            }
            System.out.println(count);
        }
    }
}


import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
    public static void main(String[] args)
    {
         Scanner sc=new Scanner(System.in);
         int t=sc.nextInt();

         StringBuilder sb=new StringBuilder();

         while(t-->0)
         {
             Stack<Character> st=new Stack<Character>();

             int n=sc.nextInt();
             String s=sc.nextLine();

             for(int i=0; i<n; i++)
             {
                 char c=s.charAt(i);

                 if(c=='(')
                 {
                    st.push(c);
                 }
                 else
                 {
                     if(st.isEmpty()==false&&st.peek()=='(')
                     {
                         st.pop();
                     }
                     else
                     {
                         st.push(c);
                     }
                 }
             }

             sb.append((st.size()/2)+"\n");
         }

         System.out.print(sb.append());

    }
}


import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
    public static void main(String[] args)
    {
         Scanner sc=new Scanner(System.in);
         int t=sc.nextInt();

         StringBuilder sb=new StringBuilder();

         while(t-->0)
         {
             Stack<Character> st=new Stack<Character>();

             int n=sc.nextInt();
             String s=sc.nextLine();

             for(int i=0; i<n; i++)
             {
                 char c=s.charAt(i);

                 if(c=='(')
                 {
                    st.puch(c);
                 }
                 else
                 {
                     if(st.isEmpty()==false&&st.peek()=='(')
                     {
                         st.pop();
                     }
                     else
                     {
                         st.push(c);
                     }
                 }
             }

             sb.append((st.size()/2)+"\n");
         }

         System.out.print(sb.toString());

    }
}


import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
    public static void main(String[] args)
    {
         Scanner sc=new Scanner(System.in);
         int t=sc.nextInt();

         StringBuilder sb=new StringBuilder();

         while(t-->0)
         {
             Stack<Character> st=new Stack<Character>();

             int n=sc.nextInt();
             String s=sc.next();

             for(int i=0; i<n; i++)
             {
                 char c=s.charAt(i);

                 if(c=='(')
                 {
                    st.push(c);
                 }
                 else
                 {
                     if(st.isEmpty()==false&&st.peek()=='(')
                     {
                         st.pop();
                     }
                     else
                     {
                         st.push(c);
                     }
                 }
             }

             sb.append((st.size()/2)+"\n");
         }

         System.out.print(sb.toString());

    }
}


import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
    public static void main(String[] args)
    {
         Scanner sc=new Scanner(System.in);
         int t=sc.nextInt();

         StringBuilder sb=new StringBuilder();

         while(t-->0)
         {
             Stack<Character> st=new Stack<Character>();

             int n=sc.nextInt();
             String s=sc.nextLine();

             for(int i=0; i<n; i++)
             {
                 char c=s.charAt(i);

                 if(c=='(')
                 {
                    st.push(c);
                 }
                 else
                 {
                     if(st.isEmpty()==false&&st.peek()=='(')
                     {
                         st.pop();
                     }
                     else
                     {
                         st.push(c);
                     }
                 }
             }

             sb.append((st.size()/2)+"\n");
         }

         System.out.print(sb.toString());

    }
}


import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
    public static void main(String[] args)
    {
         Scanner sc=new Scanner(System.in);
         int t=sc.nextInt();

         StringBuilder sb=new StringBuilder();

         while(t-->0)
         {
             Stack<Character> st=new Stack<Character>();

             int n=sc.nextInt();
             String s=sc.nextLine();

             for(int i=0; i<n; i++)
             {
                 char c=s.charAt(i);

                 if(c=='(')
                 {
                    st.puch(c);
                 }
                 else
                 {
                     if(st.isEmpty()==false&&st.peek()=='(')
                     {
                         st.pop();
                     }
                     else
                     {
                         st.push(c);
                     }
                 }
             }

             sb.append((st.size()/2)+"\n");
         }

         System.out.print(sb.append());

    }
}


import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
	public static void main(String[] args) {
             Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		while(t-->0) {
			int n = sc.nextInt();
			String s = sc.next();
			Stack<Character> st = new Stack<>();
			st.push(s.charAt(0));
			for(int i=1;i<n;i++) {
				if(st.isEmpty()) st.push(s.charAt(i));
				else if(s.charAt(i)==')') {
				if(st.peek()=='(') st.pop();
				else st.push(s.charAt(i));
				}
				else st.push(s.charAt(i));
			}
			System.out.println(st.size()/2);
		}

}}


import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
	public static void main(String[] args) {
             Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		while(t-->0) {
			int n = sc.nextInt();
			String s = sc.next();
			int co = 0;
			if(s.charAt(0)==')') co++;
			for(int i=1;i<n-1;i++) {

				if(s.charAt(i)==')' && s.charAt(i-1)==')') {
					//System.out.println("i="+i);
					co++;
				}

			}
			System.out.println(co);
		}

}}


import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
import java.util.regex.*;

public class Solution {
        public static void main(String args[])
        {       Scanner sc=new Scanner(System.in);
                int t=sc.nextInt();
                sc.nextLine();
                while(t-->0)
                {
                   int n=sc.nextInt();
                   sc.nextLine();
                   String s=sc.nextLine();
                   Stack<Character> hi=new Stack<>();
                   int count=0;
                   for(int i=0;i<n;i++)
                   {
                       if(hi.isEmpty() && s.charAt(i)==')')
                       {
                            count++;

                       }
                       else if(s.charAt(i)=='(')
                       hi.push(s.charAt(i));
                       else
                       hi.pop();
                   }
                   System.out.println(count);
                }
        }


import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
import java.util.regex.*;

public class Solution {
        public static void main(String args[])
        {       Scanner sc=new Scanner(System.in);
                int t=sc.nextInt();
                sc.nextLine();
                while(t-->0)
                {
                   int n=sc.nextInt();
                   sc.nextLine();
                   String s=sc.nextLine();
                   Stack<Character> hi=new Stack<>();
                   int count=0;
                   for(int i=0;i<n;i++)
                   {
                       if(hi.isEmpty() && s.charAt(i)==')')
                       {
                            count++;

                       }
                       else if(s.charAt(i)=='(')
                       hi.push(s.charAt(i));
                       else
                       hi.pop();
                   }
                   System.out.println(count);
                }
        }
}


import java.util.*;
import java.io.*;

public class prefix {

    public static void main(String args[]) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int t = Integer.parseInt(br.readLine().trim());

        while (t-->0){

            String s1 = br.readLine().trim();

            Stack<Character> s = new Stack<>();

            for (int i=0 ; i<s1.length() ; i++){
                if (s1.charAt(i) == '('){
                    s.push(s1.charAt(i));
                }else if (s1.charAt(i) == ')'){
                    s.pop();
                }
            }

            System.out.println(s.size()/2);
        }
    }
}


import java.util.*;
import java.io.*;

public class prefix {

    public static void main(String args[]) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int t = Integer.parseInt(br.readLine().trim());

        while (t-->0){
            int n = Integer.parseInt(br.readLine().trim());
            String s1 = br.readLine().trim();

            Stack<Character> s = new Stack<>();

            for (int i=0 ; i<s1.length() ; i++){
                if (s1.charAt(i) == '('){
                    s.push(s1.charAt(i));
                }else if (s1.charAt(i) == ')' && !s.isEmpty()){
                    s.pop();
                }
            }

            System.out.println(s.size());
        }
    }
}


import java.util.*;
import java.io.*;

public class prefix {

    public static void main(String args[]) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int t = Integer.parseInt(br.readLine().trim());

        while (t-->0){
            int n = Integer.parseInt(br.readLine().trim());
            String s1 = br.readLine().trim();

            Stack<Character> s = new Stack<>();

            for (int i=0 ; i<s1.length() ; i++){
                if (s1.charAt(i) == '('){
                    s.push(s1.charAt(i));
                }else if (s1.charAt(i) == ')' && !s.isEmpty()){
                    s.pop();
                }
            }

            System.out.println(s.size()/2);
        }
    }
}


import java.util.*;
import java.io.*;
import java.*;

public class Main
{
	public static void main(String[] args) {
	    Scanner in = new Scanner(System.in);
	    int t = in.nextInt();
	    for (int i=0; i<t; i++)
	    {
	        int n = in.nextInt();
	        String s = in.next();
	        Stack<Character> st = new Stack<>();
	        for (int j=0; j<n; j++)
	        {
	            char a = s.charAt(j);
	            if (a=='(')
	            {
	                st.push(a);
	            }
	            else
	            {
	                if (!st.isEmpty() && st.peek()=='(')
	                {
	                    st.pop();
	                }
	                else
	                {
	                    st.push(a);
	                }
	            }
	        }
	        System.out.println(st.size()/2);
	    }
	}
}


import java.util.*;
import java.io.*;
import java.*;

public class Main
{
	public static void main(String[] args) {
	    Scanner in = new Scanner(System.in);
	    int t = in.nextInt();
	    for (int i=0; i<t; i++)
	    {
	        int n = in.nextInt();
	        String s = in.next();
	        Stack<Character> st = new Stack<>();
	        for (int j=0; j<n; j++)
	        {
	            char a = s.charAt(j);
	            if (a=='(')
	            {
	                st.push(a);
	            }
	            else
	            {
	                if (st.size()!=0 && st.peek()==')')
	                {
	                    st.pop();
	                }
	                else
	                {
	                    st.push(a);
	                }
	            }
	        }
	        System.out.println(st.size()/2);
	    }
	}
}


#include <iostream>
using namespace std;
int main()
{
int n,m,a,b;
cin>>n;
string s;
for(int i=0;i<n;i++){
    cin>>m;
    cin>>s;
    int c=0; int x=0;
    for (int j=0;j<s.size();j++)
    if(s[j]=='('){
    a=j;
    if(x>a)b=x;
     else b=a;
    if(j==m-1) break;
     else{
       for(int k=b+1;k<s.size();k++)
          if(s[k]==')'){c++;x=k;break;}}
    }
    m/=2;
    m-=c;
    cout<<m<<endl;
    }
return 0;
}


/*
 * by okay__
 * 23:51 Oct_14_2020
 */
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        string s;
        cin >> s;
        stack<char> st;
        for (auto &i : s) {
            if (i == '(')
                st.push(i);
            if (i == ')')
                if (not st.empty())
                    st.pop();
        }

        cout << st.size() << endl;
    }

    return 0;
}


#include<iostream>
#include<math.h>
using namespace std;

int t,n,b,k;
string s;
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	cin>>t;
	while(t--){
		int a=0;
		cin>>n;
		cin>>s;
		for(int i=0;i<n;i++){
			if(s[i]=='(') a=a+1;
			else a=max(a-1,0);
		}
		cout<<a<<'\n';
	}
	return 0;
}


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

int t;
int l;
char * s;
stack<char> stk;

int main() {
    scanf("%d", &t);
    //printf("Read t = %d\n", t);

    while (t--) {
        scanf("%d", &l);
        //printf("Read l = %d\n", l);

        s = (char*) malloc(l * sizeof(char));

        scanf("%s", s);
        //printf("Read s = %s\n", s);

        for (int i = 0; i < l; i++) {
            if (s[i] == ')' && stk.size() > 0 && stk.top() == '(') {
                stk.pop();
            } else {
                stk.push(s[i]);
            }
        }

        printf("%d\n", stk.size() / 2);

        while (!stk.empty()) {
            stk.pop();
        }
    }
}


#include <iostream>
using namespace std;
int main()
{
	int testcases,i;
	cin>>testcases;
	while(testcases--)
	{
		int dummy;
		cin>>dummy;
		string a,b;
		cin>>a;
		for(i = 0 ; i < a.length()-1 ; i++)
		{
			if(a[i] == '(' and a[i+1] == ')')
			{
				a.erase(i,2);
				i = -1;
			}
			if(a.length() == 0)
			break;
		}
		cout<<a.length()/2<<endl;
	}
}


#include <bits/stdc++.h>

typedef long long ll;
using namespace std;

/**
 * use as : sort(v.begin(), v.end(), comp);
 */
struct compPairs {
	bool comp(pair<int, int>& a, pair<int, int>& b) {
		return a.first == b.first ? a.second < b.second : a.first < b.first;
	}
};

class FastScanner {
public:

	static void readIntegerArray(int n, vector<int>& v) {
		for (int i = 0; i < n; ++i) {
			scanf("%d", &v[i]);
		}
	}

	static void readLongArray(int n, vector<long>& v) {
		for (int i = 0; i < n; ++i) {
			scanf("%ld", &v[i]);
		}
	}

	static void readStringArray(int n, vector<string>& v) {
		for (int i = 0; i < n; ++i) {
			cin >> v[i];
		}
	}

	static void printIntArr(vector<int>& v) {
		for (int & num : v) {
			cout << num << " ";
		}
		cout << "\n";
	}

	static void printStringArr(vector<string>& v) {
		for (string & st : v) {
			cout << st << " ";
		}
		cout << "\n";
	}

};

void generatePos(vector<pair<int, int>>& vector, int x, int y, int n, int m) {
	for (int i = 1; i <= n; ++i) {
		vector.emplace_back(make_pair(x, i));
	}
	for (int i = 1; i <= m; ++i) {
		vector.emplace_back(make_pair(i, y));
	}
}

void solve(int n, string brackets) {
	stack<int> br;
	int num = 0;
	for (int i = 0; i < n; ++i) {
		if (brackets[i] == ')') {
			if (br.empty()) {
				num++;
			}
			else {
				br.pop();
			}
		}
		else {
			br.push(1);
		}
	}
	cout << num << "\n";
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int tests;
	scanf("%d", &tests);
	while (tests--) {
		int n;
		string brackets;
		scanf("%d", &n);
		cin >> brackets;
		solve(n, brackets);
	}
	return 0;
}


var n = readline();
var llen = [];
var inp = [];
for (var i  = 0; i<n;i++){
    llen[i]=readline();
    inp[i]=readline();
}
function repAll(aa) {
    var b  = true;
    var a = aa.length;
    while (b){
        aa = aa.replace(/\(\)/g,"");
        if (aa.length === a){

            b=false;
        }else{
            a = aa.length;
        }
    }
    return aa;
}
for (var i  = 0; i<n;i++) {
    var tmp = repAll(inp[i]);
    write((tmp.match(/\(/g) || []).length + "\n");

}


var x= parseInt(readline());

while(x--){
  var a=parseInt(readline());
  var seq=readline();

  var open=0,close=0;
  for(var i=0; i<seq.length; i++){
    if(seq[i]==='(')
      open++;
    if(seq[i]===')'){
      if(open>0)
        open--;
      else
        close++;
    }
  }
  print(close);
}


var testCase = Number(readline());
while(testCase--)
{
	readline();
	var str = readline();
	for( var i=1;i<=25;i++)
	{
		str=str.replace('()','');
	}
	print(Math.floor(str.length/2));
}