#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e6+10;

map<int, int> dist;

int a[maxn];

map<int, vector<int>> grafo;

void bfs(int n)
{
	queue<int> fila;

	for (int i = 1; i <= n; i++)
	{
		dist[a[i]] = 1;
		fila.push(a[i]);
	}

	while (!fila.empty())
	{
		int u = fila.front(); fila.pop();

		for (auto v: grafo[u])
		{
			if (dist[v] == -1)
			{
				dist[v] = dist[u]+1;
				fila.push(v);
			}
		}
	}
}

int main(void)
{
	int n, m;
	scanf("%d %d", &n, &m);

	for (int i = 1; i <= m; i++)
	{
		scanf("%d", &a[i]);

		a[i] -= n;

		for (int v = -1000; v <= 1000; v++)
			if (v+a[i] >= -1000 && v+a[i] <= 1000)
				grafo[v].push_back(v+a[i]);
	}

	for (int i = -1000; i <= 1000; i++)
		dist[i] = -1;

	bfs(m);

	printf("%d\n", dist[0]);
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e6+10;

int dist[2010];

int a[maxn];

vector<int> grafo[2010];

void bfs(int n)
{
	queue<int> fila;

	for (int i = 1; i <= n; i++)
	{
		dist[a[i]+1000] = 1;
		fila.push(a[i]+1000);
	}

	while (!fila.empty())
	{
		int u = fila.front(); fila.pop();

		for (auto v: grafo[u])
		{
			if (dist[v] == -1)
			{
				dist[v] = dist[u]+1;
				fila.push(v);
			}
		}
	}
}

int main(void)
{
	int n, m;
	scanf("%d %d", &n, &m);

	for (int i = 1; i <= m; i++)
	{
		scanf("%d", &a[i]);

		a[i] -= n;

		for (int v = -1000; v <= 1000; v++)
			if (v+a[i] >= -1000 && v+a[i] <= 1000)
				grafo[v+1000].push_back(v+a[i]+1000);
	}

	memset(dist, -1, sizeof dist);

	bfs(m);

	printf("%d\n", dist[1000]);
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 2e3+10;

map<int, int> dist;

int a[maxn];

map<int, vector<int>> grafo;

void bfs(int n)
{
	queue<int> fila;

	for (int i = 1; i <= n; i++)
	{
		dist[a[i]] = 1;
		fila.push(a[i]);
	}

	while (!fila.empty())
	{
		int u = fila.front(); fila.pop();

		for (auto v: grafo[u])
		{
			if (dist[v] == -1)
			{
				dist[v] = dist[u]+1;
				fila.push(v);
			}
		}
	}
}

int main(void)
{
	int n, m;
	scanf("%d %d", &n, &m);

	for (int i = 1; i <= m; i++)
	{
		scanf("%d", &a[i]);

		a[i] -= n;

		for (int v = -1000; v <= 1000; v++)
			if (v+a[i] >= -1000 && v+a[i] <= 1000)
				grafo[v].push_back(v+a[i]);
	}

	for (int i = -1000; i <= 1000; i++)
		dist[i] = -1;

	bfs(m);

	printf("%d\n", dist[0]);
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e6+10;

int a[maxn];

int dist[2010];
bool mark[2010];

vector<int> grafo[2010];

void bfs(int n)
{
	queue<int> fila;

	for (int i = 1; i <= n; i++)
	{
		dist[a[i]+1000] = 1;
		fila.push(a[i]+1000);
	}

	while (!fila.empty())
	{
		int u = fila.front(); fila.pop();

		for (auto v: grafo[u])
		{
			if (dist[v] == -1)
			{
				dist[v] = dist[u]+1;
				fila.push(v);
			}
		}
	}
}

int main(void)
{
	int n, m;
	scanf("%d %d", &n, &m);

	for (int i = 1; i <= m; i++)
	{
		scanf("%d", &a[i]);

		a[i] -= n;

		if (mark[a[i]+n]) continue;
		mark[a[i]+n] = 1;

		for (int v = -1000; v <= 1000; v++)
			if (v+a[i] >= -1000 && v+a[i] <= 1000)
				grafo[v+1000].push_back(v+a[i]+1000);
	}

	memset(dist, -1, sizeof dist);

	bfs(m);

	printf("%d\n", dist[1000]);
}


#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;

const int MAXN = 1003;
const int MAXL = 10000007;

int n, k;
set<int> pos, neg;
set<int> seen;

int main() {
    ios_base::sync_with_stdio(false);
    scanf("%d %d", &n, &k);

    int x;
    for (int i = 0; i < k; ++i) {
        scanf("%d", &x);
        if (x >= n)
            pos.insert(x - n);
        else
            neg.insert(x - n);
    }

    queue<int> state;
    state.push(0);

    int ans = -1;
    int level = 0;
    while (!state.empty()) {
        int sz = state.size();
        while (sz-- > 0) {
            int cur = state.front();
            state.pop();

            if (cur < -MAXL or cur > MAXL)
                continue;

            if (cur == 0 and level > 0) {
                ans = level;
                state = queue<int>();
                break;
            } else if (level > MAXL) {
                state = queue<int>();
                break;
            }

            if (cur > -1000) {
                for (int nv : neg) {
                    int val = cur + nv;
                    if (seen.find(val) == seen.end()) {
                        seen.insert(val);
                        state.push(val);
                    }
                }
            }
            if (cur < 1000) {
                for (int nv : pos) {
                    int val = cur + nv;
                    if (seen.find(val) == seen.end()) {
                        seen.insert(val);
                        state.push(val);
                    }
                }
            }
        }

        ++level;
    }

    printf("%d\n", ans);

    return 0;
}


#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;

const int MAXN = 1003;
const int MAXL = 1000006;

int n, k;
set<int> pos, neg;
set<int> seen;

int main() {
    ios_base::sync_with_stdio(false);
    scanf("%d %d", &n, &k);

    int x;
    for (int i = 0; i < k; ++i) {
        scanf("%d", &x);
        if (x >= n)
            pos.insert(x - n);
        else
            neg.insert(x - n);
    }

    queue<int> state;
    state.push(0);

    int ans = -1;
    int level = 0;
    while (!state.empty()) {
        int sz = state.size();
        while (sz-- > 0) {
            int cur = state.front();
            state.pop();

            if (cur < -MAXL or cur > MAXL)
                continue;

            if (cur == 0 and level > 0) {
                ans = level;
                state = queue<int>();
                break;
            } else if (level > MAXL) {
                state = queue<int>();
                break;
            }

            if (cur >= 0) {
                for (int nv : neg) {
                    int val = cur + nv;
                    if (seen.find(val) == seen.end()) {
                        seen.insert(val);
                        state.push(val);
                    }
                }
            } else {
                for (int nv : pos) {
                    int val = cur + nv;
                    if (seen.find(val) == seen.end()) {
                        seen.insert(val);
                        state.push(val);
                    }
                }
            }
        }

        ++level;
    }

    printf("%d\n", ans);

    return 0;
}


#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;

const int MAXN = 1003;
const int MAXL = 100005;

int n, k;
set<int> pos, neg;
set<int> seen;

int main() {
    ios_base::sync_with_stdio(false);
    scanf("%d %d", &n, &k);

    int x;
    for (int i = 0; i < k; ++i) {
        scanf("%d", &x);
        if (x >= n)
            pos.insert(x - n);
        else
            neg.insert(x - n);
    }

    queue<int> state;
    state.push(0);

    int ans = -1;
    int level = 0;
    while (!state.empty()) {
        int sz = state.size();
        while (sz-- > 0) {
            int cur = state.front();
            state.pop();

            if (cur < -MAXL or cur > MAXL)
                continue;

            if (cur == 0 and level > 0) {
                ans = level;
                state = queue<int>();
                break;
            } else if (level > MAXL) {
                state = queue<int>();
                break;
            }

            if (cur >= 0) {
                for (int nv : neg) {
                    int val = cur + nv;
                    if (seen.find(val) == seen.end()) {
                        seen.insert(val);
                        state.push(val);
                    }
                }
            } else {
                for (int nv : pos) {
                    int val = cur + nv;
                    if (seen.find(val) == seen.end()) {
                        seen.insert(val);
                        state.push(val);
                    }
                }
            }
        }

        ++level;
    }

    printf("%d\n", ans);

    return 0;
}


#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;

const int MAXN = 1003;
const int MAXL = 10004;

int n, k;
set<int> pos, neg;
set<int> seen;
int ZERO = 1001;

int main() {
    ios_base::sync_with_stdio(false);
    scanf("%d %d", &n, &k);

    int x;
    for (int i = 0; i < k; ++i) {
        scanf("%d", &x);
        if (x >= n)
            pos.insert(x - n);
        else
            neg.insert(x - n);
    }

    queue<int> state;
    state.push(0);

    int ans = -1;
    int level = 0;
    while (!state.empty()) {
        int sz = state.size();
        while (sz-- > 0) {
            int cur = state.front();
            state.pop();

            if (cur < -MAXL or cur > MAXL)
                continue;

            if (cur == 0 and level > 0) {
                ans = level;
                state = queue<int>();
                break;
            } else if (level > MAXL) {
                state = queue<int>();
                break;
            }

            if (cur >= 0) {
                for (int nv : neg) {
                    int val = cur + nv;
                    if (seen.find(val) == seen.end()) {
                        seen.insert(val);
                        state.push(val);
                    }
                }
            } else {
                for (int nv : pos) {
                    int val = cur + nv;
                    if (seen.find(val) == seen.end()) {
                        seen.insert(val);
                        state.push(val);
                    }
                }
            }
        }

        ++level;
    }

    printf("%d\n", ans);

    return 0;
}


/// c.cpp

# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
const pair < int , int > DD[] = {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < __typeof(v.x) > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vl vector < ll >
# define pll pair < ll , ll >
# define pii pair < int , int >
# define mp make_pair
# define db long double
# define fail puts("-1")
# define yes puts("YES")
# define no puts("NO")
# define PP puts("Possible")
# define II puts("Impossible")
# define vii vector < pii >
# define vll vector < ll >
# define pb push_back
# define pdd pair < db , db >
inline int readChar();
template <class T = int> inline T readInt();
template <class T> inline void writeInt( T x, char end = 0 );
inline void writeChar( int x );
inline void writeWord( const char *s );

/** Read */

static const int buf_size = 4096;

inline int getChar() {
    static char buf[buf_size];
    static int len = 0, pos = 0;
    if (pos == len)
        pos = 0, len = fread(buf, 1, buf_size, stdin);
    if (pos == len)
        return -1;
    return buf[pos++];
}

inline int readChar() {
    int c = getChar();
    while (c <= 32)
        c = getChar();
    return c;
}

template <class T>
inline T readInt() {
    int s = 1, c = readChar();
    T x = 0;
    if (c == '-')
        s = -1, c = getChar();
    while ('0' <= c && c <= '9')
        x = x * 10 + c - '0', c = getChar();
    return s == 1 ? x : -x;
}

/** Write */

static int write_pos = 0;
static char write_buf[buf_size];

inline void writeChar( int x ) {
    if (write_pos == buf_size)
        fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
    write_buf[write_pos++] = x;
}

template <class T>
inline void writeInt( T x, char end ) {
    if (x < 0)
        writeChar('-'), x = -x;

    char s[24];
    int n = 0;
    while (x || !n)
        s[n++] = '0' + x % 10, x /= 10;
    while (n--)
        writeChar(s[n]);
    if (end)
        writeChar(end);
}

inline void writeWord( const char *s ) {
    while (*s)
        writeChar(*s++);
}

struct Flusher {
    ~Flusher() {
        if (write_pos)
            fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
    }
} flusher;
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
int gcd(int a,int b)
{
    return !b ? a : gcd(b,a % b);
}
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int k = readInt();
    int n = readInt();
    int g = 0;
    int mn = 0,mx = 0;
    static int was[1 << 20];
    for (int i = 1;i <= n;++i)
    {
        int v = readInt();
        v = k - v;
        g = gcd(g,abs(v));
        mn |= v < 0;
        mx |= v > 0;
        was[v + 2048] = 1;
    }
    if (k % g)
        return fail * 0;
    if (!mn || !mx)
        return fail * 0;
    vi ss;
    k /= g;
    for (int i = 0;i <= 4096;++i)
        if (was[i])
            ss.pb((i - 2048) / g);
    static int D[1 << 20];
    const int lim = 4096;
    for (int i = 1;i <= lim;++i)
        D[i] = 1e9;
    queue < int > Q;
    Q.push(0);
    while (!Q.empty() && D[k] >= 1e9)
    {
        int node = Q.front();
        Q.pop();
        for (auto it : ss)
            if (0 <= it + node && it + node <= lim)
                if (D[it + node] > D[node] + 1)
                    D[it + node] = D[node] + 1,Q.push(it + node);
    }
    if (D[k] <= 1e9)
        fo << D[k] << '\n';
    else
        fo << "-1\n";
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


/// c.cpp

# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
const pair < int , int > DD[] = {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < __typeof(v.x) > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vl vector < ll >
# define pll pair < ll , ll >
# define pii pair < int , int >
# define mp make_pair
# define db long double
# define fail puts("-1")
# define yes puts("YES")
# define no puts("NO")
# define PP puts("Possible")
# define II puts("Impossible")
# define vii vector < pii >
# define vll vector < ll >
# define pb push_back
# define pdd pair < db , db >
inline int readChar();
template <class T = int> inline T readInt();
template <class T> inline void writeInt( T x, char end = 0 );
inline void writeChar( int x );
inline void writeWord( const char *s );

/** Read */

static const int buf_size = 4096;

inline int getChar() {
    static char buf[buf_size];
    static int len = 0, pos = 0;
    if (pos == len)
        pos = 0, len = fread(buf, 1, buf_size, stdin);
    if (pos == len)
        return -1;
    return buf[pos++];
}

inline int readChar() {
    int c = getChar();
    while (c <= 32)
        c = getChar();
    return c;
}

template <class T>
inline T readInt() {
    int s = 1, c = readChar();
    T x = 0;
    if (c == '-')
        s = -1, c = getChar();
    while ('0' <= c && c <= '9')
        x = x * 10 + c - '0', c = getChar();
    return s == 1 ? x : -x;
}

/** Write */

static int write_pos = 0;
static char write_buf[buf_size];

inline void writeChar( int x ) {
    if (write_pos == buf_size)
        fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
    write_buf[write_pos++] = x;
}

template <class T>
inline void writeInt( T x, char end ) {
    if (x < 0)
        writeChar('-'), x = -x;

    char s[24];
    int n = 0;
    while (x || !n)
        s[n++] = '0' + x % 10, x /= 10;
    while (n--)
        writeChar(s[n]);
    if (end)
        writeChar(end);
}

inline void writeWord( const char *s ) {
    while (*s)
        writeChar(*s++);
}

struct Flusher {
    ~Flusher() {
        if (write_pos)
            fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
    }
} flusher;
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int k = readInt();
    int n = readInt();
    static int was[1 << 20];
    for (int i = 1;i <= n;++i)
    {
        int v = readInt();
        v = k - v;
        was[v + 2048] = 1;
    }
    vi ss;
    for (int i = 0;i <= 4096;++i)
        if (was[i])
            ss.pb(i - 2048);
    static int D[1 << 20];
    const int lim = 1 << 13;
    for (int i = 0;i <= lim;++i)
        D[i] = 1e9;
    queue < int > Q;
    for (auto it : ss)
        D[it + 4096] = 1,Q.push(it + 4096);
    while (!Q.empty() && D[4096] >= 1e9)
    {
        int node = Q.front();
        Q.pop();
        for (auto it : ss)
            if (0 <= it + node && it + node <= lim)
                if (D[it + node] > D[node] + 1)
                    D[it + node] = D[node] + 1,Q.push(it + node);
    }
    if (D[4096] < 1e9)
        fo << D[4096] << '\n';
    else
        fo << "-1\n";
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


/// c.cpp

# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
const pair < int , int > DD[] = {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < __typeof(v.x) > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vl vector < ll >
# define pll pair < ll , ll >
# define pii pair < int , int >
# define mp make_pair
# define db long double
# define fail puts("-1")
# define yes puts("YES")
# define no puts("NO")
# define PP puts("Possible")
# define II puts("Impossible")
# define vii vector < pii >
# define vll vector < ll >
# define pb push_back
# define pdd pair < db , db >
inline int readChar();
template <class T = int> inline T readInt();
template <class T> inline void writeInt( T x, char end = 0 );
inline void writeChar( int x );
inline void writeWord( const char *s );

/** Read */

static const int buf_size = 4096;

inline int getChar() {
    static char buf[buf_size];
    static int len = 0, pos = 0;
    if (pos == len)
        pos = 0, len = fread(buf, 1, buf_size, stdin);
    if (pos == len)
        return -1;
    return buf[pos++];
}

inline int readChar() {
    int c = getChar();
    while (c <= 32)
        c = getChar();
    return c;
}

template <class T>
inline T readInt() {
    int s = 1, c = readChar();
    T x = 0;
    if (c == '-')
        s = -1, c = getChar();
    while ('0' <= c && c <= '9')
        x = x * 10 + c - '0', c = getChar();
    return s == 1 ? x : -x;
}

/** Write */

static int write_pos = 0;
static char write_buf[buf_size];

inline void writeChar( int x ) {
    if (write_pos == buf_size)
        fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
    write_buf[write_pos++] = x;
}

template <class T>
inline void writeInt( T x, char end ) {
    if (x < 0)
        writeChar('-'), x = -x;

    char s[24];
    int n = 0;
    while (x || !n)
        s[n++] = '0' + x % 10, x /= 10;
    while (n--)
        writeChar(s[n]);
    if (end)
        writeChar(end);
}

inline void writeWord( const char *s ) {
    while (*s)
        writeChar(*s++);
}

struct Flusher {
    ~Flusher() {
        if (write_pos)
            fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
    }
} flusher;
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
int gcd(int a,int b)
{
    return !b ? a : gcd(b,a % b);
}
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int k = readInt();
    int n = readInt();
    int g = 0;
    int mn = 0,mx = 0;
    static int was[1 << 20];
    for (int i = 1;i <= n;++i)
    {
        int v = readInt();
        v = k - v;
        g = gcd(g,abs(v));
        mn |= v < 0;
        mx |= v > 0;
        was[v + 2048] = 1;
    }
    if (k % g)
        return fail * 0;
    if (!mn || !mx)
        return fail * 0;
    vi ss;
    k /= g;
    for (int i = 0;i <= 4096;++i)
        if (was[i])
            ss.pb((i - 2048) / g);
    static int D[1 << 20];
    const int lim = 4096;
    for (int i = 0;i <= lim;++i)
        D[i] = 1e9;
    queue < int > Q;
    for (auto it : ss)
        D[it] = 1,Q.push(it);
    while (!Q.empty() && D[0] >= 1e9)
    {
        int node = Q.front();
        Q.pop();
        for (auto it : ss)
            if (0 <= it + node && it + node <= lim)
                if (D[it + node] > D[node] + 1)
                    D[it + node] = D[node] + 1,Q.push(it + node);
    }
    if (D[0] < 1e9)
        fo << D[0] << '\n';
    else
        fo << "-1\n";
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


/// c.cpp

# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
const pair < int , int > DD[] = {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < __typeof(v.x) > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vl vector < ll >
# define pll pair < ll , ll >
# define pii pair < int , int >
# define mp make_pair
# define db long double
# define fail puts("-1")
# define yes puts("YES")
# define no puts("NO")
# define PP puts("Possible")
# define II puts("Impossible")
# define vii vector < pii >
# define vll vector < ll >
# define pb push_back
# define pdd pair < db , db >
inline int readChar();
template <class T = int> inline T readInt();
template <class T> inline void writeInt( T x, char end = 0 );
inline void writeChar( int x );
inline void writeWord( const char *s );

/** Read */

static const int buf_size = 4096;

inline int getChar() {
    static char buf[buf_size];
    static int len = 0, pos = 0;
    if (pos == len)
        pos = 0, len = fread(buf, 1, buf_size, stdin);
    if (pos == len)
        return -1;
    return buf[pos++];
}

inline int readChar() {
    int c = getChar();
    while (c <= 32)
        c = getChar();
    return c;
}

template <class T>
inline T readInt() {
    int s = 1, c = readChar();
    T x = 0;
    if (c == '-')
        s = -1, c = getChar();
    while ('0' <= c && c <= '9')
        x = x * 10 + c - '0', c = getChar();
    return s == 1 ? x : -x;
}

/** Write */

static int write_pos = 0;
static char write_buf[buf_size];

inline void writeChar( int x ) {
    if (write_pos == buf_size)
        fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
    write_buf[write_pos++] = x;
}

template <class T>
inline void writeInt( T x, char end ) {
    if (x < 0)
        writeChar('-'), x = -x;

    char s[24];
    int n = 0;
    while (x || !n)
        s[n++] = '0' + x % 10, x /= 10;
    while (n--)
        writeChar(s[n]);
    if (end)
        writeChar(end);
}

inline void writeWord( const char *s ) {
    while (*s)
        writeChar(*s++);
}

struct Flusher {
    ~Flusher() {
        if (write_pos)
            fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
    }
} flusher;
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
int gcd(int a,int b)
{
    return !b ? a : gcd(b,a % b);
}
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int k = readInt();
    int n = readInt();
    if (!k)
        return puts("0") * 0;
    int g = 0;
    int mn = 0,mx = 0;
    static int was[1 << 20];
    for (int i = 1;i <= n;++i)
    {
        int v = readInt();
        v = k - v;
        g = gcd(g,abs(v));
        mn |= v < 0;
        mx |= v > 0;
        was[v + 2048] = 1;
    }
    if (!g)
        return fail * 0;
    if (k % g)
        return fail * 0;
    if (!mn || !mx)
        return fail * 0;
    vi ss;
    k /= g;
    for (int i = 0;i <= 4096;++i)
        if (was[i])
            ss.pb((i - 2048) / g);
    static int D[1 << 20];
    const int lim = 4096;
    for (int i = 0;i <= lim;++i)
        D[i] = 1e9;
    queue < int > Q;
    for (auto it : ss)
        D[it] = 1,Q.push(it);
    while (!Q.empty() && D[0] >= 1e9)
    {
        int node = Q.front();
        Q.pop();
        for (auto it : ss)
            if (0 <= it + node && it + node <= lim)
                if (D[it + node] > D[node] + 1)
                    D[it + node] = D[node] + 1,Q.push(it + node);
    }
    if (D[0] < 1e9)
        fo << D[0] << '\n';
    else
        fo << "-1\n";
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


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

#define fo(i,s,t) for(int i = s; i <= t; ++ i)
#define fd(i,s,t) for(int i = s; i >= t; -- i)
const int maxn = 1000500;
const int maxm = 1005;

int n, k, a[maxn], dp[maxm*2];
queue<int> q;

int main()
{
	scanf("%d%d",&n,&k);
	fo(i,1,k) scanf("%d",&a[i]);
	memset(dp,0x3f,sizeof(dp));
	fo(i,1,k)
	{
		dp[a[i]-n+maxm] = 1;
		q.push(a[i]-n+maxm);
	}
	int h;
	while(!q.empty())
	{
		h = q.front(); q.pop();
		fo(i,1,k)
		{
			if(h+a[i]-n<2*maxm && h+a[i]-n>=0 && dp[h+a[i]-n]>dp[h]+1)
			{
				assert(dp[h+a[i]-n]==0x3f3f3f3f);
				dp[h+a[i]-n] = dp[h]+1;
				q.push(h+a[i]-n);
			}
		}
	}
	printf("%d",(dp[maxm]==0x3f3f3f3f?-1:dp[maxm]));
	return 0;
}


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

#define rep(i,n) for(ll i=0;i<n;i++)
#define srep(i,s,n) for(int i=s;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAX (int)1e9 + 99
#define vi vector<int>
#define vb vector<bool>
#define ll long long
#define vll vector<ll>
#define pa pair<int, int>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define mod 998244353
#define bitcount __builtin_popcount

ll floorSqrt(ll x)
{
    return (ll)sqrt(x);
}

void solve()
{
    ll n, k;
    cin>>n>>k;
    /*int a=3;
    while(k-->1)
    {
        do{
            a++;
        }while(bitcount(a)!=2);
    }*/
	ll i = (floorSqrt((k << 3) - 1) + 1) >> 1;
    ll j = k - ((i*(i - 1)) >> 1) - 1;

    ll r = (1ll << i) | (1ll << j);

    string res="";
    rep(i,n)
    {
        if(r&1)
        res = "b"+res;
        else
        res = "a"+res;
        r>>=1;
    }
    cout<<res;
}

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

    while(t--)
    {
        solve();
        cout<<"\n";
    }
    return 0;
}


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

#define rep(i,n) for(ll i=0;i<n;i++)
#define srep(i,s,n) for(int i=s;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAX (int)1e9 + 99
#define vi vector<int>
#define vb vector<bool>
#define ll long long
#define vll vector<ll>
#define pa pair<int, int>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define mod 998244353
#define bitcnt __builtin_popcount

void solve()
{
    ll n, k;
    cin>>n>>k;
    /*Works but gives TLE
    int a=3;
    while(k-->1)
    {
        do{
            a++;
        }while(bitcount(a)!=2);
    }*/

	string res(n,'a');
    rrep(i,n-1)
    {
        if(k<=n-i-1)
        {
            s[i]=s[n-k]='b';
            break;
        }
        k-=(n-i-1);
    }
    cout<<res;
}

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

    while(t--)
    {
        solve();
        cout<<"\n";
    }
    return 0;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,s,n) for(int i=s;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAX (int)1e9 + 99
#define vi vector<int>
#define vb vector<bool>
#define ll long long
#define vll vector<ll>
#define pa pair<int, int>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define mod 998244353
#define bitcount __builtin_popcount
void solve()
{
    int n, k;
    cin>>n>>k;
    /*int a=3;
    while(k-->1)
    {
        do{
            a++;
        }while(bitcount(a)!=2);
    }*/
	int r = 0;
	int i = 1;
	while((r=i*(i+1)/2)<k)
	{
		i++;
	}
	r = (int)(pow(2, i) + pow(2, i-(r-k)-1));

    string res="";
    rep(i,n)
    {
        if(r&1)
        res = "b"+res;
        else
        res = "a"+res;
        r/=2;
    }
    cout<<res;
}

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

    while(t--)
    {
        solve();
        cout<<"\n";
    }
    return 0;
}


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

#define rep(i,n) for(ll i=0;i<n;i++)
#define srep(i,s,n) for(int i=s;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAX (int)1e9 + 99
#define vi vector<int>
#define vb vector<bool>
#define ll long long
#define vll vector<ll>
#define pa pair<int, int>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define mod 998244353
#define bitcount __builtin_popcount

int floorSqrt(int x)
{
    return (int)sqrt(x);
}

void solve()
{
    ll n, k;
    cin>>n>>k;
    /*int a=3;
    while(k-->1)
    {
        do{
            a++;
        }while(bitcount(a)!=2);
    }*/
	int i = (floorSqrt((k << 3) - 1) + 1) >> 1;
    int j = k - ((i*(i - 1)) >> 1) - 1;

    ll r = (1ll << i) | (1ll << j);

    string res="";
    rep(i,n)
    {
        if(r&1)
        res = "b"+res;
        else
        res = "a"+res;
        r>>=1;
    }
    cout<<res;
}

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

    while(t--)
    {
        solve();
        cout<<"\n";
    }
    return 0;
}


//Author: kaiyu
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <unordered_map>
#include <cstring>
#include <string>
#include <numeric>
#include <iomanip>
#define SZ(x) ((int)(x).size())
#define all(x)  x.begin(),x.end()
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
typedef long long ll;
#define tt int t;cin >> t;while(t--)
#define int3(x,y,z) ll x,y,z;cin >> x >> y >> z;
#define int2(x,y) ll x,y;cin >> x >>y;
#define int1(x) ll x;cin>>x;
#define  fio ios::sync_with_stdio(0);cin.tie(NULL);
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

//if (s1.find(s2) != std::string::npos) {
//   std::cout << "found!" << '\n';
//}

using namespace std;

int main() {
    fio
    tt{
        int2(n,k)
        if(k != 2000000000) {
            char arr[n];
            memset(arr,'a', sizeof(arr));
            if(k == 1) {
                arr[n - 1] = 'b';
                arr[n - 2] = 'b';
                for (char i:arr) {
                    cout << i;
                }
                cout << endl;

                continue;
            }
            vector<ll>p;
            bool x = 1;
            ll e = 0;
            for (int j = 1;  ; ++j) {
                e += j;
                p.push_back(e);
                if(e > 2ll*100000000 || e > 1ll * n *(n-1)/2) {
                    break;
                }
            }
            auto lb = lower_bound(p.begin(),p.end(),k);
            int ez = lb - p.begin();
            int pos = n-2 - ez;
            if(pos < 0) {
                pos = 0;
            }
            arr[pos] = 'b';
            int ww = k ;
            int x2 = p[ez - 2 ];
            int x3 = p[ez-1];
            int x6 = p[ez-1] - p[ez-2];
            int x4 = n;
            int x5 = k - p[ez - 1];
            int pos2 = n - (abs(k - p[ez - 1]));
            arr[pos2] = 'b';

            for(char i:arr) {
                cout << i;
            }
            cout << endl;

        }
        else {
            char arr[n];
            memset(arr,'a', sizeof(arr));
            if(k == 1) {
                arr[n - 1] = 'b';
                arr[n - 2] = 'b';
                for (char i:arr) {
                    cout << i;
                }
                cout << endl;

                continue;
            }
            vector<ll>p;
            bool x = 1;
            ll e = 0;
            for (int j = 1;  ; ++j) {
                e += j;
                p.push_back(e);
                if(e > 2ll*100000000 || e > 1ll * n *(n-1)/2) {
                    break;
                }
            }
            auto lb = lower_bound(p.begin(),p.end(),k);
            int ez = lb - p.begin();
            int pos = n-2 - ez;
            if(pos < 0) {
                pos = 0;
            }
            arr[pos] = 'b';
            int ww = k ;
            int x2 = p[ez - 2 ];
            int x3 = p[ez-1];
            int x6 = p[ez-1] - p[ez-2];
            int x4 = n;
            int x5 = k - p[ez - 1];
//            int pos2 = n - (abs(k - p[ez - 1]));
//            arr[pos2] = 'b';

            for(char i:arr) {
                cout << i;
            }
            cout << endl;

        }

    }
    return 0;

}


//Author: kaiyu
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <unordered_map>
#include <cstring>
#include <string>
#include <numeric>
#include <iomanip>
#define SZ(x) ((int)(x).size())
#define all(x)  x.begin(),x.end()
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define tt int t;cin >> t;while(t--)
#define int3(x,y,z) int x,y,z;cin >> x >> y >> z;
#define int2(x,y) int x,y;cin >> x >>y;
#define int1(x) int x;cin>>x;
typedef long long ll;
#define  fio ios::sync_with_stdio(0);cin.tie(NULL);
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

//if (s1.find(s2) != std::string::npos) {
//   std::cout << "found!" << '\n';
//}

using namespace std;

int main() {
    fio
    tt{
        int2(n,k)
        string s ="";
        for (int i = 0; i < n-2; ++i) {
            s = s + 'a';
        }
        s= s+'b';
        s = s+'b';
        k--;
        while(k) {
            bool  val = next_permutation(s.begin(),s.end());
            k--;
        }

        cout << s << endl;

    }
    return 0;

}


//Author: kaiyu
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <unordered_map>
#include <cstring>
#include <string>
#include <numeric>
#include <iomanip>
#define SZ(x) ((int)(x).size())
#define all(x)  x.begin(),x.end()
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
typedef long long ll;
#define tt int t;cin >> t;while(t--)
#define int3(x,y,z) ll x,y,z;cin >> x >> y >> z;
#define int2(x,y) ll x,y;cin >> x >>y;
#define int1(x) ll x;cin>>x;
#define  fio ios::sync_with_stdio(0);cin.tie(NULL);
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

//if (s1.find(s2) != std::string::npos) {
//   std::cout << "found!" << '\n';
//}

using namespace std;

int main() {
    fio
    tt{
        int2(n,k)
            char arr[n];
            memset(arr,'a', sizeof(arr));
            if(k == 1) {
                arr[n - 1] = 'b';
                arr[n - 2] = 'b';
                for (char i:arr) {
                    cout << i;
                }
                cout << endl;

                continue;
            }
            vector<ll>p;
            bool x = 1;
            ll e = 0;
            for (int j = 1;  ; ++j) {
                e += j;
                p.push_back(e);
                if(e > 2ll*(1e+9) || e > 1ll * n *(n-1)/2) {
                    break;
                }
            }
            auto lb = lower_bound(p.begin(),p.end(),k);
            int ez = lb - p.begin();
            int pos = n-2 - ez;
            if(pos < 0) {
                pos = 0;
            }
            arr[pos] = 'b';

            int pos2 = n - (abs(k - p[ez - 1]));
            arr[pos2] = 'b';

            for(char i:arr) {
                cout << i;
            }
            cout << endl;

        }

    return 0;
}


// C++ program to print n-th permutation
#include <iostream>
using namespace std;

#define ll long long int

const int MAX_CHAR = 26;
const int MAX_FACT = 20;
ll fact[MAX_FACT];

// utility for calculating factorials
void precomputeFactorials()
{
    fact[0] = 1;
    for (int i = 1; i < MAX_FACT; i++)
        fact[i] = fact[i - 1] * i;
}

// function for nth permutation
void nPermute(char str[], int n)
{
    precomputeFactorials();

    // length of given string
    int len = strlen(str);

    // Count frequencies of all
    // characters
    int freq[MAX_CHAR] = { 0 };
    for (int i = 0; i < len; i++)
        freq[str[i] - 'a']++;

    // out string for output string
    char out[MAX_CHAR];

    // iterate till sum equals n
    int sum = 0;
    int k = 0;

    // We update both n and sum in this
    // loop.
    while (sum != n) {

        sum = 0;
        // check for characters present in freq[]
        for (int i = 0; i < MAX_CHAR; i++) {
            if (freq[i] == 0)
                continue;

            // Remove character
            freq[i]--;

            // calculate sum after fixing
            // a particuar char
            int xsum = fact[len - 1 - k];
            for (int j = 0; j < MAX_CHAR; j++)
                xsum /= fact[freq[j]];
            sum += xsum;

            // if sum > n fix that char as
            // present char and update sum
            // and required nth after fixing
            // char at that position
            if (sum >= n) {
                out[k++] = i + 'a';
                n -= (sum - xsum);
                break;
            }

            // if sum < n, add character back
            if (sum < n)
                freq[i]++;
        }
    }

    // if sum == n means this char will provide its
    // greatest permutation as nth permutation
    for (int i=MAX_CHAR-1; k < len && i >= 0; i--)
        if (freq[i]) {
            out[k++] = i + 'a';
            freq[i++]--;
        }

    // append string termination
    // character and print result
    out[k] = '\0';
    cout << out;
}

int main()
{
    int t;
    cin >> t;
    while(t--) {
        int n,k;
        cin >> n >> k;
        string s = "";
        for (int i = 0; i < n-2; ++i) {
            s=s+'a';
        }
        s=s+'b';
        s=s+'b';
        char str[s.size()];
        for (int j = 0; j < s.size(); ++j) {
            str[j] = s.at(j);
        }

        nPermute(str, k);
        cout << endl;
    }

    return 0;
}


//Author: kaiyu
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <unordered_map>
#include <cstring>
#include <string>
#include <numeric>
#include <iomanip>
#define SZ(x) ((int)(x).size())
#define all(x)  x.begin(),x.end()
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
typedef long long ll;
#define tt int t;cin >> t;while(t--)
#define int3(x,y,z) ll x,y,z;cin >> x >> y >> z;
#define int2(x,y) ll x,y;cin >> x >>y;
#define int1(x) ll x;cin>>x;
#define  fio ios::sync_with_stdio(0);cin.tie(NULL);
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

//if (s1.find(s2) != std::string::npos) {
//   std::cout << "found!" << '\n';
//}

using namespace std;

int main() {
    fio
    tt{
        int2(n,k)
        string s ="";
        for (int i = 0; i < n-2; ++i) {
            s = s + 'a';
        }
        s= s+'b';
        s = s+'b';
        if(k == 1) {
            cout << s << endl;
            continue;
        }
        char arr[n];
        memset(arr,'a', sizeof(arr));
        vector<ll>p;
        bool x = 1;
        ll e = 0;
        for (int j = 1;  ; ++j) {
            e += j;
            p.push_back(e);
            if(e > 2ll*100000000 || e > 1ll * n *(n-1)/2) {
                break;
            }
        }
        auto lb = lower_bound(p.begin(),p.end(),k);
        int ez = lb - p.begin();
        int pos = n-2 - ez;
        if(pos < 0) {
            pos = 0;
        }
        arr[pos] = 'b';

        int pos2 = n - (k - p[ez - 1]);
        arr[pos2] = 'b';

        for(char i:arr) {
            cout << i;
        }
        cout << endl;

    }
    return 0;

}


//Author: kaiyu
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <unordered_map>
#include <cstring>
#include <string>
#include <numeric>
#include <iomanip>
#define SZ(x) ((int)(x).size())
#define all(x)  x.begin(),x.end()
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
typedef long long ll;
#define tt int t;cin >> t;while(t--)
#define int3(x,y,z) ll x,y,z;cin >> x >> y >> z;
#define int2(x,y) ll x,y;cin >> x >>y;
#define int1(x) ll x;cin>>x;
#define  fio ios::sync_with_stdio(0);cin.tie(NULL);
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

//if (s1.find(s2) != std::string::npos) {
//   std::cout << "found!" << '\n';
//}

using namespace std;

int main() {
    fio
    tt{
        int2(n,k)
        char arr[n];
        memset(arr,'a', sizeof(arr));
        if(k == 1) {
            arr[n-1] = 'b';
            arr[n-2] = 'b';
            for(char i:arr) {
                cout << i;
            }
            cout << endl;

            continue;
        }
        char arr[n];
        memset(arr,'a', sizeof(arr));
        vector<ll>p;
        bool x = 1;
        ll e = 0;
        for (int j = 1;  ; ++j) {
            e += j;
            p.push_back(e);
            if(e > 2ll*100000000 || e > 1ll * n *(n-1)/2) {
                break;
            }
        }
        auto lb = lower_bound(p.begin(),p.end(),k);
        int ez = lb - p.begin();
        int pos = n-2 - ez;
        if(pos < 0) {
            pos = 0;
        }
        arr[pos] = 'b';

        int pos2 = n - (k - p[ez - 1]);
        arr[pos2] = 'b';

        for(char i:arr) {
            cout << i;
        }
        cout << endl;

    }
    return 0;

}


//Author: kaiyu
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <unordered_map>
#include <cstring>
#include <string>
#include <numeric>
#include <iomanip>
#define SZ(x) ((int)(x).size())
#define all(x)  x.begin(),x.end()
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
typedef long long ll;
#define tt int t;cin >> t;while(t--)
#define int3(x,y,z) ll x,y,z;cin >> x >> y >> z;
#define int2(x,y) ll x,y;cin >> x >>y;
#define int1(x) ll x;cin>>x;
#define  fio ios::sync_with_stdio(0);cin.tie(NULL);
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

//if (s1.find(s2) != std::string::npos) {
//   std::cout << "found!" << '\n';
//}

using namespace std;

int main() {
    fio
    tt{
        int2(n,k)
        char arr[n];
        memset(arr,'a', sizeof(arr));
        if(k == 1) {
            arr[n - 1] = 'b';
            arr[n - 2] = 'b';
            for (char i:arr) {
                cout << i;
            }
            cout << endl;

            continue;
        }
        vector<ll>p;
        bool x = 1;
        ll e = 0;
        for (int j = 1;  ; ++j) {
            e += j;
            p.push_back(e);
            if(e > 2ll*100000000 || e > 1ll * n *(n-1)/2) {
                break;
            }
        }
        auto lb = lower_bound(p.begin(),p.end(),k);
        int ez = lb - p.begin();
        int pos = n-2 - ez;
        if(pos < 0) {
            pos = 0;
        }
        arr[pos] = 'b';
        int ww = k ;
        int x2 = p[ez - 2 ];
        int x3 = p[ez-1];
        int x6 = p[ez-1] - p[ez-2];
        int x4 = n;
        int x5 = k - p[ez - 1];
//        int pos2 = n - (abs(k - p[ez - 1]));
//        arr[pos2] = 'b';

        for(char i:arr) {
            cout << i;
        }
        cout << endl;

    }
    return 0;

}


// C++ program to print n-th permutation
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

#define ll long long int

const int MAX_CHAR = 26;
const int MAX_FACT = 20;
ll fact[MAX_FACT];

// utility for calculating factorials
void precomputeFactorials()
{
    fact[0] = 1;
    for (int i = 1; i < MAX_FACT; i++)
        fact[i] = fact[i - 1] * i;
}

// function for nth permutation
void nPermute(char str[], int n)
{
    precomputeFactorials();

    // length of given string
    int len = strlen(str);

    // Count frequencies of all
    // characters
    int freq[MAX_CHAR] = { 0 };
    for (int i = 0; i < len; i++)
        freq[str[i] - 'a']++;

    // out string for output string
    char out[MAX_CHAR];

    // iterate till sum equals n
    int sum = 0;
    int k = 0;

    // We update both n and sum in this
    // loop.
    while (sum != n) {

        sum = 0;
        // check for characters present in freq[]
        for (int i = 0; i < MAX_CHAR; i++) {
            if (freq[i] == 0)
                continue;

            // Remove character
            freq[i]--;

            // calculate sum after fixing
            // a particuar char
            int xsum = fact[len - 1 - k];
            for (int j = 0; j < MAX_CHAR; j++)
                xsum /= fact[freq[j]];
            sum += xsum;

            // if sum > n fix that char as
            // present char and update sum
            // and required nth after fixing
            // char at that position
            if (sum >= n) {
                out[k++] = i + 'a';
                n -= (sum - xsum);
                break;
            }

            // if sum < n, add character back
            if (sum < n)
                freq[i]++;
        }
    }

    // if sum == n means this char will provide its
    // greatest permutation as nth permutation
    for (int i=MAX_CHAR-1; k < len && i >= 0; i--)
        if (freq[i]) {
            out[k++] = i + 'a';
            freq[i++]--;
        }

    // append string termination
    // character and print result
    out[k] = '\0';
    cout << out;
}

int main()
{
    int t;
    cin >> t;
    while(t--) {
        int n,k;
        cin >> n >> k;
        string s = "";
        for (int i = 0; i < n-2; ++i) {
            s=s+'a';
        }
        s=s+'b';
        s=s+'b';
        char str[s.size()];
        for (int j = 0; j < s.size(); ++j) {
            str[j] = s.at(j);
        }

        nPermute(str, k);
        cout << endl;
    }

    return 0;
}


//Author: kaiyu
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <unordered_map>
#include <cstring>
#include <string>
#include <numeric>
#include <iomanip>
#define SZ(x) ((int)(x).size())
#define all(x)  x.begin(),x.end()
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
typedef long long ll;
#define tt int t;cin >> t;while(t--)
#define int3(x,y,z) ll x,y,z;cin >> x >> y >> z;
#define int2(x,y) ll x,y;cin >> x >>y;
#define int1(x) ll x;cin>>x;
#define  fio ios::sync_with_stdio(0);cin.tie(NULL);
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

//if (s1.find(s2) != std::string::npos) {
//   std::cout << "found!" << '\n';
//}

using namespace std;

int main() {
    fio
    tt{
        int2(n,k)
        char arr[n];
        memset(arr,'a', sizeof(arr));
        if(k == 1) {
            arr[n-1] = 'b';
            arr[n-2] = 'b';
            for(char i:arr) {
                cout << i;
            }
            cout << endl;

            continue;
        }

        vector<ll>p;
        bool x = 1;
        ll e = 0;
        for (int j = 1;  ; ++j) {
            e += j;
            p.push_back(e);
            if(e > 2ll*100000000 || e > 1ll * n *(n-1)/2) {
                break;
            }
        }
        auto lb = lower_bound(p.begin(),p.end(),k);
        int ez = lb - p.begin();
        int pos = n-2 - ez;
        if(pos < 0) {
            pos = 0;
        }
        arr[pos] = 'b';

        int pos2 = n - (k - p[ez - 1]);
        arr[pos2] = 'b';

        for(char i:arr) {
            cout << i;
        }
        cout << endl;

    }
    return 0;

}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    unsigned long long int j,n,C1,C2,A,B,T,K,t;
    // string S(n,'a');
    cin>>t;
    for(int i=0;i<t;i++)
    {
        cin>>n;
        string S(n,'a');
        // T = (n*(n-1))/2;
        cin>>K;
        for(j=1;j<=n;j++)
        {
            if(2*K<((j*(j-1))+2))
            {
                C1 = (((j-1)*(j-2))+2)/2;
                B=j;
                A=K-C1;
                break;
            }
        }

        S[n-A-1]='b';
        S[n-B]='b';
        cout<<S;
        cout<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long n,C1,C2,A,B,T,K,t;
    // string S(n,'a');
    cin>>t;
    for(int i=0;i<t;i++)
    {
        cin>>n;
        string S(n,'a');
        // T = (n*(n-1))/2;
        cin>>K;
        for(int j=1;j<=n;j++)
        {
            C2 = ((j*j)-j+2)/2;
            if(K<C2)
            {
                C1 = (((j-1)*(j-1))-(j-1)+2)/2;
                B=j;
                A=K-C1;
                break;
            }
        }

        S[n-A-1]='b';
        S[n-B]='b';
        cout<<S;
        cout<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    unsigned long long int n,C1,C2,A,B,T,K,t;
    // string S(n,'a');
    cin>>t;
    for(int i=0;i<t;i++)
    {
        cin>>n;
        string S(n,'a');
        // T = (n*(n-1))/2;
        cin>>K;
        int j=1;
        while(1)
        {
            if(2*K<((j*(j-1))+2))
            {
                C1 = (((j-1)*(j-2))+2)/2;
                B=j;
                A=K-C1;
                break;
            }
            j++;
        }

        S[n-A-1]='b';
        S[n-B]='b';
        cout<<S;
        cout<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    unsigned long long int n,C1,C2,A,B,T,K,t;
    // string S(n,'a');
    cin>>t;
    for(int i=0;i<t;i++)
    {
        cin>>n;
        string S(n,'a');
        // T = (n*(n-1))/2;
        cin>>K;
        for(int j=1;j<=n;j++)
        {
            if(2*K<((j*(j-1))+2))
            {
                C1 = (((j-1)*(j-2))+2)/2;
                B=j;
                A=K-C1;
                break;
            }
        }

        S[n-A-1]='b';
        S[n-B]='b';
        cout<<S;
        cout<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    unsigned long long int n,C1,C2,A,B,T,K,t;
    // string S(n,'a');
    cin>>t;
    for(int i=0;i<t;i++)
    {
        cin>>n;
        string S(n,'a');
        // T = (n*(n-1))/2;
        cin>>K;
        for(int j=1;j<=n;j++)
        {
            if(K<((j*j)-j+2)/2)
            {
                C1 = (((j-1)*(j-1))-(j-1)+2)/2;
                B=j;
                A=K-C1;
                break;
            }
        }

        S[n-A-1]='b';
        S[n-B]='b';
        cout<<S;
        cout<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    unsigned long long int n,C1,C2,A,B,T,K,t;
    // string S(n,'a');
    cin>>t;
    for(int i=0;i<t;i++)
    {
        cin>>n;
        string S(n,'a');
        // T = (n*(n-1))/2;
        cin>>K;
        for(int j=1;j<=n;j++)
        {
            C2 = ((j*j)-j+2)/2;
            if(K<C2)
            {
                C1 = (((j-1)*(j-1))-(j-1)+2)/2;
                B=j;
                A=K-C1;
                break;
            }
        }

        S[n-A-1]='b';
        S[n-B]='b';
        cout<<S;
        cout<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    unsigned long long n,C1,C2,A,B,T,K,t;
    // string S(n,'a');
    cin>>t;
    for(int i=0;i<t;i++)
    {
        cin>>n;
        string S(n,'a');
        // T = (n*(n-1))/2;
        cin>>K;
        for(int j=1;j<=n;j++)
        {
            C2 = ((j*j)-j+2)/2;
            if(K<C2)
            {
                C1 = (((j-1)*(j-1))-(j-1)+2)/2;
                B=j;
                A=K-C1;
                break;
            }
        }

        S[n-A-1]='b';
        S[n-B]='b';
        cout<<S;
        cout<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    unsigned long long int n,C1,C2,A,B,T,K,t;
    // string S(n,'a');
    cin>>t;
    for(int i=0;i<t;i++)
    {
        cin>>n;
        string S(n,'a');
        // T = (n*(n-1))/2;
        cin>>K;
        for(int j=1;j<=n;j++)
        {
            if(K<((j*(j-1))+2)/2)
            {
                C1 = (((j-1)*(j-2))+2)/2;
                B=j;
                A=K-C1;
                break;
            }
        }

        S[n-A-1]='b';
        S[n-B]='b';
        cout<<S;
        cout<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long j,n,C1,C2,A,B,T,K,t;
    // string S(n,'a');
    cin>>t;
    for(int i=0;i<t;i++)
    {
        cin>>n;
        string S(n,'a');
        // T = (n*(n-1))/2;
        cin>>K;
        for(j=1;j<=n;j++)
        {
            C2 = (j*j-j+2)/2;
            if(K<C2)
            {
                C1 = ((j-1)*(j-1)-(j-1)+2)/2;
                B=j;
                A=K-C1;
                break;
            }
        }

        S[n-A-1]='b';
        S[n-B]='b';
        cout<<S;
        cout<<endl;
    }

    return 0;
}


//By      :Prajwal Sonawane
//Email   :prajwalsonawane35@gmail.com
//Language:C++
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define digits(x) floor(log10(n) + 1)
#define pn(x) cout << x <<"\n";
#define ps(x) cout << x <<" ";
#define deb(x) cout << #x << "=" << x << endl;
#define test unsigned int t;cin >> t;while(t--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main(void)
{
    fastio
    test
    {
        ll n,k;
        cin>>n>>k;

        //string s[n+1];

        int x1 = (sqrt(8*k+1) + 1)/2;

        int t1 = n-x1;
        int t2 = n-(k - ((x1-1)*(x1-2))/2);
        //deb(t1) deb(t2)

        for(int i=1; i<=n; i++)
        {
            if(i == t1 || i == t2)
            cout<<"b";
            else
            cout<<"a";
        }
        cout<<"\n";

    }
    return 0;
}


//By      :Prajwal Sonawane
//Email   :prajwalsonawane35@gmail.com
//Language:C++
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define digits(x) floor(log10(n) + 1)
#define pn(x) cout << x <<"\n";
#define ps(x) cout << x <<" ";
#define deb(x) cout << #x << "=" << x << endl;
#define test unsigned int t;cin >> t;while(t--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main(void)
{
    fastio
    test
    {
        ll n,k;
        cin>>n>>k;

        //string s[n+1];
        int x1;
        if(k == 1)
        x1 = 1;
        else
        x1 = (sqrt(8*k+1) + 1)/2;

        int t1 = n-x1;
        int t2 = n-(k - ((x1-1)*(x1-2))/2);
        deb(t1) deb(t2)

        for(int i=1; i<=n; i++)
        {
            if(i == t1 || i == t2)
            cout<<"b";
            else
            cout<<"a";
        }
        cout<<"\n";

    }
    return 0;
}


//By      :Prajwal Sonawane
//Email   :prajwalsonawane35@gmail.com
//Language:C++
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define digits(x) floor(log10(n) + 1)
#define pn(x) cout << x <<"\n";
#define ps(x) cout << x <<" ";
#define deb(x) cout << #x << "=" << x << endl;
#define test unsigned int t;cin >> t;while(t--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main(void)
{
    fastio
    test
    {
        ll n,k;
        cin>>n>>k;

        int x = ceil((sqrt(1+8*k) - 1)/2);
        int t1,t2,p;
        if(k == 1) p = 0;
        else
        {
            p = x*(x-1)/2;
        }

        t1 = n-x;
        t2 = n-(k-p-1);

        for(int i=1; i<=n; i++)
        {
            if(i == t1 || i == t2)
            cout<<"b";
            else
            cout<<"a";
        }
        cout<<"\n";

    }
    return 0;
}


//By      :Prajwal Sonawane
//Email   :prajwalsonawane35@gmail.com
//Language:C++
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define digits(x) floor(log10(n) + 1)
#define pn(x) cout << x <<"\n";
#define ps(x) cout << x <<" ";
#define deb(x) cout << #x << "=" << x << endl;
#define test unsigned int t;cin >> t;while(t--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main(void)
{
    fastio
    test
    {
        ll n,k;
        cin>>n>>k;

        //string s[n+1];

        int x1 = ceil((sqrt(8*k+1) + 1)/(float)2);

        int t1 = n-x1;
        int t2 = n-(k - ((x1-1)*(x1-2))/2);
        //deb(t1) deb(t2)

        for(int i=1; i<=n; i++)
        {
            if(i == t1 || i == t2)
            cout<<"b";
            else
            cout<<"a";
        }
        cout<<"\n";

    }
    return 0;
}


//By      :Prajwal Sonawane
//Email   :prajwalsonawane35@gmail.com
//Language:C++
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define digits(x) floor(log10(n) + 1)
#define pn(x) cout << x <<"\n";
#define ps(x) cout << x <<" ";
#define deb(x) cout << #x << "=" << x << endl;
#define test unsigned int t;cin >> t;while(t--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main(void)
{
    fastio
    test
    {
        ll n,k;
        cin>>n>>k;

        ll x = ceil((sqrt(1+8*k) - 1)/2);

        ll t1,t2,p;
        if(k == 1) p = 0;
        else
        {
            p = x*(x-1)/2;
        }

        t1 = n-x;
        t2 = n-(k-p-1);

        for(int i=1; i<=n; i++)
        {
            if(i == t1 || i == t2)
            cout<<"b";
            else
            cout<<"a";
        }
        cout<<"\n";

    }
    return 0;
}


//By      :Prajwal Sonawane
//Email   :prajwalsonawane35@gmail.com
//Language:C++
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define digits(x) floor(log10(n) + 1)
#define pn(x) cout << x <<"\n";
#define ps(x) cout << x <<" ";
#define deb(x) cout << #x << "=" << x << endl;
#define test unsigned int t;cin >> t;while(t--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main(void)
{
    fastio
    test
    {
        ll n,k;
        cin>>n>>k;

        ll x = ceil((sqrt(1+8*k) - 1)/2);
        ll t1,t2,p;
        if(k == 1) p = 0;
        else
        {
            p = x*(x-1)/2;
        }

        t1 = n-x;
        t2 = n-(k-p-1);

        for(int i=1; i<=n; i++)
        {
            if(i == t1 || i == t2)
            cout<<"b";
            else
            cout<<"a";
        }
        cout<<"\n";

    }
    return 0;
}


//By      :Prajwal Sonawane
//Email   :prajwalsonawane35@gmail.com
//Language:C++
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define digits(x) floor(log10(n) + 1)
#define pn(x) cout << x <<"\n";
#define ps(x) cout << x <<" ";
#define deb(x) cout << #x << "=" << x << endl;
#define test unsigned int t;cin >> t;while(t--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main(void)
{
    fastio
    test
    {
        ll n,k;
        cin>>n>>k;

        //string s[n+1];

        int x1 = ceil((sqrt(8*k+1) - 1)/(float)2);

        int t1 = n-x1;
        int t2 = n-(k - ((x1-1)*(x1-2))/2);
        //deb(t1) deb(t2)

        for(int i=1; i<=n; i++)
        {
            if(i == t1 || i == t2)
            cout<<"b";
            else
            cout<<"a";
        }
        cout<<"\n";

    }
    return 0;
}


//By      :Prajwal Sonawane
//Email   :prajwalsonawane35@gmail.com
//Language:C++
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define digits(x) floor(log10(n) + 1)
#define pn(x) cout << x <<"\n";
#define ps(x) cout << x <<" ";
#define deb(x) cout << #x << "=" << x << endl;
#define test unsigned int t;cin >> t;while(t--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main(void)
{
    fastio
    test
    {
        ll n,k;
        cin>>n>>k;

        //string s[n+1];

        int x1 = ceil((sqrt(8*k+1) - 1)/(float)2);

        int t1 = n-x1;
        int t2 = n-(k - ((x1-1)*(x1))/2);
        //deb(t1) deb(t2)

        for(int i=1; i<=n; i++)
        {
            if(i == t1 || i == t2)
            cout<<"b";
            else
            cout<<"a";
        }
        cout<<"\n";

    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll  long long
#define all(v) (v.begin(),v.end())
#define ff first
#define ss second
const ll maxn=2e5+10;
const ll mod=1e9+7;

int main() {
  	fast;
  	int t,n,k,i,j;
  	cin>>t;
  	while(t--)
  	{
  		cin>>n>>k;
  		k=n*(n-1)/2-k+1;
  		string s(n,'a');
  		int cnt=0;
		for(i=0,j=0;i<n-1;++i){

			j=i+1;
			if(k>cnt){
				cnt+=n-j;
			}
			if(k<=cnt){
				s[i]='b';
				j=n-1;
				while(cnt!=k)
				{
					--j;
					--cnt;
				}
				s[j]='b';
				break;
			}

		}
		cout<<s<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll  long long
#define all(v) (v.begin(),v.end())
#define ff first
#define ss second
const ll maxn=2e5+10;
const ll mod=1e9+7;

int main() {
  	fast;
  	int t,i,j,k,n;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=998244353;
const ll maxn=1e10;
//vector<vector<int> > adj(maxn);
//vector<bool> used(maxn,false);
//vector<int> d(maxn),p(maxn);
ll bin(ll a, ll b) {
	//a%=m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a; //mod
        a = a * a; //mod
        b >>= 1;
    }
    return res;
}

int gcd(int a, int b, int & x, int & y) {
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    int x1, y1;
    int d = gcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}
ll fact(ll x)
{
  ll res=1;
  for(ll i=1;i<=x;i++)
    res=(res*i)%mod;

  return res;
}

ll lmod(string n,ll x)
{

	ll res=0;
	for(ll i=0;i<n.length();++i)
	{
		res=(res*10+(int)n[i]-'0')%x;
	}
	return res;
}
bool ispal(string s,int l,int r)
{
	string t=s;
	for(int i=l,j=r;i<=r;++i)
	{
		if(s[i]!=s[j])
			return false;
		else
			{
				--j;
			}
	}
	return true;
}
bool pl(string s)
{
	string t(s.rbegin(),s.rend());
	return t==s;
}
/*void bfs(int s,int &ans)
{
	queue<int> q;
	used[s]=true;
	p[s]=-1;
	d[s]=0;
	q.push(s);
	while(!q.empty())
	{
		int v=q.front();
		q.pop();
		for(int u: adj[v])
		{
			if(!used[u])
			{
				used[u]=true;
				q.push(u);
				d[u]=d[v]+1;
				ans=max(ans,d[u]);
				p[u]=v;
			}

		}
	}
}*/

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	ll t,n,k,i,j;
	cin>>t;
	while(t--)
	{
		cin>>n>>k;
		k=n*(n-1)/2-k+1;
		string s;
		for(i=0;i<n;i++)
		s.push_back('a');

		ll cnt=1,flag=0;
		for(i=0;i<n-1;++i)
		{
			for(j=i+1;j<n;++j)
			{
				if(cnt==k)
				{
					s[i]='b';
					s[j]='b';
					flag=1;
					break;
				}
				++cnt;
			}
			if(flag==1)
				break;
		}

		cout<<s<<endl;
	}

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=998244353;
const ll maxn=1e10;
//vector<vector<int> > adj(maxn);
//vector<bool> used(maxn,false);
//vector<int> d(maxn),p(maxn);
ll bin(ll a, ll b) {
	//a%=m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a; //mod
        a = a * a; //mod
        b >>= 1;
    }
    return res;
}

int gcd(int a, int b, int & x, int & y) {
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    int x1, y1;
    int d = gcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}
ll fact(ll x)
{
  ll res=1;
  for(ll i=1;i<=x;i++)
    res=(res*i)%mod;

  return res;
}

ll lmod(string n,ll x)
{

	ll res=0;
	for(ll i=0;i<n.length();++i)
	{
		res=(res*10+(int)n[i]-'0')%x;
	}
	return res;
}
bool ispal(string s,int l,int r)
{
	string t=s;
	for(int i=l,j=r;i<=r;++i)
	{
		if(s[i]!=s[j])
			return false;
		else
			{
				--j;
			}
	}
	return true;
}
bool pl(string s)
{
	string t(s.rbegin(),s.rend());
	return t==s;
}
/*void bfs(int s,int &ans)
{
	queue<int> q;
	used[s]=true;
	p[s]=-1;
	d[s]=0;
	q.push(s);
	while(!q.empty())
	{
		int v=q.front();
		q.pop();
		for(int u: adj[v])
		{
			if(!used[u])
			{
				used[u]=true;
				q.push(u);
				d[u]=d[v]+1;
				ans=max(ans,d[u]);
				p[u]=v;
			}

		}
	}
}*/

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	ll t,n,k,i,j;
	cin>>t;
	while(t--)
	{
		cin>>n>>k;
		k=n*(n-1)/2-k+1;
		string s;
		for(i=0;i<n;i++)
		s.push_back('a');

		ll cnt=n-1,flag=0;
		for(i=0,j=1;i<n-1;++i,++cnt)
		{
			if(k<=cnt)
			{
				j=n-1-cnt+k;
				s[i]='b';
				s[j]='b';
				break;
			}
			else
			{
				++j;
				cnt+=n-j-1;
			}

		}
		cout<<s<<endl;
	}

}


#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll  long long
#define all(v) (v.begin(),v.end())
#define ff first
#define ss second
const ll maxn=2e5+10;
const ll mod=1e9+7;

int main() {
  	fast;
  	ll t,n,k,i,j;
  	cin>>t;
  	while(t--)
  	{
  		cin>>n>>k;
  		k=n*(n-1)/2-k+1;
  		string s(n,'a');
  		int cnt=0;
		for(i=0,j=0;i<n-1;++i){

			j=i+1;
			if(k>cnt){
				cnt+=n-j;
			}
			if(k<=cnt){
				s[i]='b';
				j=n-1;
				while(cnt!=k)
				{
					--j;
					--cnt;
				}
				s[j]='b';
				break;
			}

		}
		cout<<s<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=998244353;
const ll maxn=1e10;
//vector<vector<int> > adj(maxn);
//vector<bool> used(maxn,false);
//vector<int> d(maxn),p(maxn);
ll bin(ll a, ll b) {
	//a%=m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a; //mod
        a = a * a; //mod
        b >>= 1;
    }
    return res;
}

int gcd(int a, int b, int & x, int & y) {
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    int x1, y1;
    int d = gcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}
ll fact(ll x)
{
  ll res=1;
  for(ll i=1;i<=x;i++)
    res=(res*i)%mod;

  return res;
}

ll lmod(string n,ll x)
{

	ll res=0;
	for(ll i=0;i<n.length();++i)
	{
		res=(res*10+(int)n[i]-'0')%x;
	}
	return res;
}
bool ispal(string s,int l,int r)
{
	string t=s;
	for(int i=l,j=r;i<=r;++i)
	{
		if(s[i]!=s[j])
			return false;
		else
			{
				--j;
			}
	}
	return true;
}
bool pl(string s)
{
	string t(s.rbegin(),s.rend());
	return t==s;
}
/*void bfs(int s,int &ans)
{
	queue<int> q;
	used[s]=true;
	p[s]=-1;
	d[s]=0;
	q.push(s);
	while(!q.empty())
	{
		int v=q.front();
		q.pop();
		for(int u: adj[v])
		{
			if(!used[u])
			{
				used[u]=true;
				q.push(u);
				d[u]=d[v]+1;
				ans=max(ans,d[u]);
				p[u]=v;
			}

		}
	}
}*/

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	ll t,n,k,i,j;
	cin>>t;
	while(t--)
	{
		cin>>n>>k;
		k=n*(n-1)/2-k+1;
		string s;
		for(i=0;i<n;i++)
		s.push_back('a');

		ll cnt=n-1,flag=0;
		for(i=0,j=1;i<n-1;++i)
		{
			if(k<=cnt)
			{
				j=n-1-cnt+k;
				s[i]='b';
				s[j]='b';
				break;
			}
			else
			{
				++j;
				cnt+=n-j;
			}

		}
		cout<<s<<endl;
	}

}


#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll  long long
#define all(v) (v.begin(),v.end())
#define ff first
#define ss second
const ll maxn=2e5+10;
const ll mod=1e9+7;

int main() {
  	fast;
  	ll t,n,k,i,j;
  	cin>>t;
  	while(t--)
  	{
  		cin>>n>>k;
  		k=n*(n-1)/2-k+1;
  		string s(n,'a');
  		ll cnt=0;
		for(i=0,j=0;i<n-1;++i){

			j=i+1;
			if(k>cnt){
				cnt+=n-j;
			}
			if(k<=cnt){
				s[i]='b';
				j=n-1-cnt+k;
				s[j]='b';
				break;
			}

		}
		cout<<s<<endl;
	}
}


#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) begin(x),end(x)
#define oo(i,a) for (int i = 0; i < (a); i++)
#define ooo(i,a,b) for (int i = a; i < (b); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const char newl = 10;
const int MOD = 998244353;
const int N = 100005;
// set N
void run(){
   ll n, k;
   cin >> n >> k;
   ll f = 0;
   ll ord = 1;
   while ( ( ( (f + 1) * f) / 2) < k ) f++;
   ll s = ((f * (f + 1)) - k * 2) >> 1;
   f = n - f - 1;
   s = f + s + 1;
   string o(n, 'a'); o[f] = 'b'; o[s] = 'b';
   cout << o << newl;
   return ;
}
int main(){
   ios_base::sync_with_stdio(0);
   cout.tie(0);cin.tie(0);
   int t = 1;
   cin >> t;
   for (int tc = 1; tc <= t; tc++) {
      // cout << "Case #" << tc << ": ";
      run();
   }
   return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) begin(x),end(x)
#define oo(i,a) for (int i = 0; i < (a); i++)
#define ooo(i,a,b) for (int i = a; i < (b); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 100005;
const int MOD = 998244353;
const char newl = 10;
char nc() { char a; cin >> a; return a;}
int nxt() { int a; cin >> a; return a;}
template <class T>
void print(const T& x, const string& end = " "){
   cout << x << end;
}
// set N
int run(){
   int n, k;
   cin >> n >> k;
   int f = 0;
   while ( (((f + 1) * f) / 2) < k ) f++;
   int s = k - ( (f * (f - 1)) / 2 );
   f = n - f - 1;
   s = f + s + 1;
   string o(n, 'a');
   o[f] = 'b'; o[s] = 'b';
   cout << o << newl;
   return 0;
}
int main(){
   ios_base::sync_with_stdio(0);
   cout.tie(0);cin.tie(0);
   int t = 1;
   cin >> t;
   for (int tc = 1; tc <= t; tc++) {
      // cout << "Case #" << tc << ": ";
      run();
   }
   return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) begin(x),end(x)
#define oo(i,a) for (int i = 0; i < (a); i++)
#define ooo(i,a,b) for (int i = a; i < (b); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 100005;
const int MOD = 998244353;
const char newl = 10;
char nc() { char a; cin >> a; return a;}
int nxt() { int a; cin >> a; return a;}
template <class T>
void print(const T& x, const string& end = " "){
   cout << x << end;
}
// set N
int run(){
   int n, k;
   cin >> n >> k;
   int f = ceil(
      (-1.0 + sqrt(1 + 8 * k))/2
   );
   int s = ( (f * (f + 1)) / 2 ) - k;
   f = n - f - 1;
   s = f + s + 1;
   string o(n, 'a'); o[f] = 'b'; o[s] = 'b';
   cout << o << newl;
   return 0;
}
int main(){
   ios_base::sync_with_stdio(0);
   cout.tie(0);cin.tie(0);
   int t = 1;
   cin >> t;
   for (int tc = 1; tc <= t; tc++) {
      // cout << "Case #" << tc << ": ";
      run();
   }
   return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) begin(x),end(x)
#define oo(i,a) for (int i = 0; i < (a); i++)
#define ooo(i,a,b) for (int i = a; i < (b); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const char newl = 10;
const int MOD = 998244353;
const int N = 100005;
// set N
void run(){
   int n, k;
   cin >> n >> k;
   int f = ceil(
      (-1.0 + sqrt(1.0 + 8.0 * k))
      / 2.0
   );
   int s = ((f * (f + 1)) - k * 2) >> 1;
   f = n - f - 1;
   s = f + s + 1;
   string o(n, 'a'); o[f] = 'b'; o[s] = 'b';
   cout << o << newl;
   return ;
}
int main(){
   ios_base::sync_with_stdio(0);
   cout.tie(0);cin.tie(0);
   int t = 1;
   cin >> t;
   for (int tc = 1; tc <= t; tc++) {
      // cout << "Case #" << tc << ": ";
      run();
   }
   return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) begin(x),end(x)
#define oo(i,a) for (int i = 0; i < (a); i++)
#define ooo(i,a,b) for (int i = a; i < (b); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const char newl = 10;
const int MOD = 998244353;
const int N = 100005;
// set N
void run(){
   int n, k;
   cin >> n >> k;
   int f = ceil(
      (-1.0 + sqrt(1.0 + 8.0 * k))
      / 2.0
   );
   int s = ( (f * (f + 1)) / 2 ) - k;
   f = n - f - 1;
   s = f + s + 1;
   string o(n, 'a'); o[f] = 'b'; o[s] = 'b';
   cout << o << newl;
   return ;
}
int main(){
   ios_base::sync_with_stdio(0);
   cout.tie(0);cin.tie(0);
   int t = 1;
   cin >> t;
   for (int tc = 1; tc <= t; tc++) {
      // cout << "Case #" << tc << ": ";
      run();
   }
   return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) begin(x),end(x)
#define oo(i,a) for (int i = 0; i < (a); i++)
#define ooo(i,a,b) for (int i = a; i < (b); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 100005;
const int MOD = 998244353;
const char newl = 10;
char nc() { char a; cin >> a; return a;}
int nxt() { int a; cin >> a; return a;}
template <class T>
void print(const T& x, const string& end = " "){
   cout << x << end;
}
// set N
int run(){
   int n, k;
   cin >> n >> k;
   int f = 0;
   while ( (((f + 1) * f) / 2) < k ) f++;
   int s = ( (f * (f + 1)) / 2 ) - k;
   f = n - f - 1;
   s = f + s + 1;
   string o(n, 'a'); o[f] = 'b'; o[s] = 'b';
   cout << o << newl;
   return 0;
}
int main(){
   ios_base::sync_with_stdio(0);
   cout.tie(0);cin.tie(0);
   int t = 1;
   cin >> t;
   for (int tc = 1; tc <= t; tc++) {
      // cout << "Case #" << tc << ": ";
      run();
   }
   return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) begin(x),end(x)
#define oo(i,a) for (int i = 0; i < (a); i++)
#define ooo(i,a,b) for (int i = a; i < (b); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const char newl = 10;
const int MOD = 998244353;
const int N = 100005;
// set N
void run(){
   int n, k;
   cin >> n >> k;
   int f = 0;
   int ord = 1;
   while ( ( ( (f + 1) * f) / 2) < k ) f++;
   int s = ((f * (f + 1)) - k * 2) >> 1;
   f = n - f - 1;
   s = f + s + 1;
   string o(n, 'a'); o[f] = 'b'; o[s] = 'b';
   cout << o << newl;
   return ;
}
int main(){
   ios_base::sync_with_stdio(0);
   cout.tie(0);cin.tie(0);
   int t = 1;
   cin >> t;
   for (int tc = 1; tc <= t; tc++) {
      // cout << "Case #" << tc << ": ";
      run();
   }
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL n, k;
void solve(){
    if(n == 2){
        cout<<"bb"<<endl; return ;
    }
    LL x = 0, y = 0, xx;
    xx = (LL) sqrt(k * 2);
    for(LL i = max(xx - 20, 2LL); i <= xx + 20; ++i){
        if((i - 1) * (i - 2) / 2 < k && i * (i - 1) / 2 >= k){
            x = i; break;
        }
    }
    y = k - (x - 1) * (x - 2) / 2;
    for(LL i = n; i > x; i--) printf("a");
    printf("b");
    for(LL i = x - 1; i > y; i--) printf("a");
    printf("b");
    for(LL i = y - 1; i >= 1; i--) printf("a");
    printf("\n");
    return ;
}
int main(){
    LL T;
    cin>>T;
    while(T--){
        scanf("%lld%lld", &n, &k);
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int n, k;
void solve(){
    if(n == 2){
        cout<<"bb"<<endl; return ;
    }
    int x, y, xx;
    xx = (int) sqrt(k * 2);
    for(int i = max(xx - 10, 2); i <= xx + 10; ++i){
        if((i - 1) * (i - 2) / 2 < k && i * (i - 1) / 2 >= k){
            x = i; break;
        }
    }
    y = k - (x - 1) * (x - 2) / 2;
    for(int i = n; i > x; i--) printf("a");
    printf("b");
    for(int i = x - 1; i > y; i--) printf("a");
    printf("b");
    for(int i = y - 1; i >= 1; i--) printf("a");
    printf("\n");
    return ;
}
int main(){
    int T;
    cin>>T;
    while(T--){
        scanf("%d%d", &n, &k);
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL n, k;
void solve(){
    if(n == 2){
        cout<<"bb"<<endl; return ;
    }
    LL x, y, xx;
    xx = (LL) sqrt(k);
    for(LL i = xx - 20; i <= xx + 20; ++i){
        if((i - 1) * (i - 2) / 2 < k && i * (i - 1) / 2 >= k){
            x = i; break;
        }
    }
    y = k - (x - 1) * (x - 2) / 2LL;
    for(int i = n; i > x; i--) printf("a");
    printf("b");
    for(int i = x - 1; i > y; i--) printf("a");
    printf("b");
    for(int i = y - 1; i >= 1; i--) printf("a");
    printf("\n");
    return ;
}
int main(){
    int T;
    cin>>T;
    while(T--){
        cin>>n>>k;
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL n, k;
void solve(){
    if(n == 2){
        cout<<"bb"<<endl; return ;
    }
    LL x, y, xx;
    xx = (LL) sqrt(k);
    for(LL i = max(xx - 10, 2LL); i <= xx + 10; ++i){
        if((i - 1) * (i - 2) / 2 < k && i * (i - 1) / 2 >= k){
            x = i; break;
        }
    }
    y = k - (x - 1) * (x - 2) / 2LL;
    for(int i = n; i > x; i--) printf("a");
    printf("b");
    for(int i = x - 1; i > y; i--) printf("a");
    printf("b");
    for(int i = y - 1; i >= 1; i--) printf("a");
    printf("\n");
    return ;
}
int main(){
    int T;
    cin>>T;
    while(T--){
        scanf("%lld%lld", &n, &k);
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL n, k;
void solve(){
    if(n == 2){
        cout<<"bb"<<endl; return ;
    }
    LL x = 0, y = 0, xx;
    xx = (LL) sqrt(k * 2);
    for(LL i = max(xx - 20, 2); i <= xx + 20; ++i){
        if((i - 1) * (i - 2) / 2 < k && i * (i - 1) / 2 >= k){
            x = i; break;
        }
    }
    y = k - (x - 1) * (x - 2) / 2;
    for(LL i = n; i > x; i--) printf("a");
    printf("b");
    for(LL i = x - 1; i > y; i--) printf("a");
    printf("b");
    for(LL i = y - 1; i >= 1; i--) printf("a");
    printf("\n");
    return ;
}
int main(){
    LL T;
    cin>>T;
    while(T--){
        scanf("%d%d", &n, &k);
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int n, k;
void solve(){
    if(n == 2){
        cout<<"bb"<<endl; return ;
    }
    int x, y, xx;
    xx = (int) sqrt(k);
    for(int i = max(xx - 10, 2); i <= xx + 10; ++i){
        if((i - 1) * (i - 2) / 2 < k && i * (i - 1) / 2 >= k){
            x = i; break;
        }
    }
    y = k - (x - 1) * (x - 2) / 2;
    for(int i = n; i > x; i--) printf("a");
    printf("b");
    for(int i = x - 1; i > y; i--) printf("a");
    printf("b");
    for(int i = y - 1; i >= 1; i--) printf("a");
    printf("\n");
    return ;
}
int main(){
    int T;
    cin>>T;
    while(T--){
        scanf("%d%d", &n, &k);
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL n, k;
void solve(){
    if(n == 2){
        cout<<"bb"<<endl; return ;
    }
    LL x, y, xx;
    xx = (LL) sqrt(k);
    for(LL i = max(xx - 100, 2LL); i <= xx + 100; ++i){
        if((i - 1) * (i - 2) / 2 < k && i * (i - 1) / 2 >= k){
            x = i; break;
        }
    }
    y = k - (x - 1) * (x - 2) / 2LL;
    for(int i = n; i > x; i--) printf("a");
    printf("b");
    for(int i = x - 1; i > y; i--) printf("a");
    printf("b");
    for(int i = y - 1; i >= 1; i--) printf("a");
    printf("\n");
    return ;
}
int main(){
    int T;
    cin>>T;
    while(T--){
        scanf("%lld%lld", &n, &k);
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
void solve(){
    int a, b;
    cin>>a>>b;
    if(a % b == 0){
        cout<<0<<endl; return ;
    }
    if(a < b){
        cout<<b-a<<endl; return ;
    }
    else{
        int c = a % b;
        cout<<b - c<<endl; return ;
    }
}
int main(){
    int T;
    cin>>T;
    while(T--){
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int n, k;
void solve(){
    if(n == 2){
        cout<<"bb"<<endl; return ;
    }
    int x, y, xx;
    xx = (int) sqrt(k);
    for(int i = max(xx - 3, 2); i <= xx + 3; ++i){
        if((i - 1) * (i - 2) / 2 < k && i * (i - 1) / 2 >= k){
            x = i; break;
        }
    }
    y = k - (x - 1) * (x - 2) / 2;
    for(int i = n; i > x; i--) printf("a");
    printf("b");
    for(int i = x - 1; i > y; i--) printf("a");
    printf("b");
    for(int i = y - 1; i >= 1; i--) printf("a");
    printf("\n");
    return ;
}
int main(){
    int T;
    cin>>T;
    while(T--){
        scanf("%d%d", &n, &k);
        solve();
    }
    return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
using namespace std;

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
   int t,n,i,k,x,j,z;
   string a;
   cin>>t;
   for (i=0;i<t;i++)
   {
       cin>>n>>k;
       a="";
       for (i=0;i<n-2;i++)
       {
           a+="a";
       }
       a+="bb";
       x=(-1+sqrt(1+8*k))/2;
       while (x*(x+1)/2<k)
       {
           x++;
       }
       x--;
       z=x*(x+1)/2;

      swap(a[n-2],a[n-2-x]);
      swap(a[n-1],a[n-(k-z)]);
      cout<<a<<endl;
      //cout<<x<<" "<<k<<" "<<z<<endl;
       //cout<<x<<endl;
   }
   return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
using namespace std;

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
   long long int t,n,i,k,x,j,z;
   cin>>t;
   for (i=0;i<t;i++)
   {
       cin>>n>>k;
       x=0;
      // x=(-1+sqrt(1+8*k))/2;
       while (x*(x+1)/2<k)
       {
           x++;
       }

       z=x*(x+1)/2;
      for(j=0;j<n-1-x;j++)
      {
          cout<<"a";
      }
      cout<<"b";
      for (j=0;j<z-k;j++)
      {
          cout<<"a";
      }
      cout<<"b";
      for (j=0;j<x-(z-k)-1;j++)
      {
          cout<<"a";
      }
      cout<<endl;
       //cout<<x<<endl;
   }
   return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
using namespace std;

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
   long long int t,n,i,k,x,j,z;
   string a;
   cin>>t;
   for (i=0;i<t;i++)
   {
       cin>>n>>k;
       a="";
       for (i=0;i<n-2;i++)
       {
           a+="a";
       }
       a+="bb";
       x=(-1+sqrt(1+8*k))/2;
       while (x*(x+1)/2<k)
       {
           x++;
       }
       x--;
       z=x*(x+1)/2;

      swap(a[n-2],a[n-2-x]);
      swap(a[n-1],a[n-(k-z)]);
      cout<<a<<endl;
      //cout<<x<<" "<<k<<" "<<z<<endl;
       //cout<<x<<endl;
   }
   return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
using namespace std;

int main() {
   int t,n,i,k,x,j,z;
   cin>>t;
   for (i=0;i<t;i++)
   {
       cin>>n>>k;
       x=1;
       while (x*(x+1)/2<k)
       {
           x++;
       }

       z=x*(x+1)/2;
      for(j=0;j<n-1-x;j++)
      {
          cout<<"a";
      }
      cout<<"b";
      for (j=0;j<z-k;j++)
      {
          cout<<"a";
      }
      cout<<"b";
      for (j=0;j<x-(z-k)-1;j++)
      {
          cout<<"a";
      }
      cout<<endl;
       //cout<<x<<endl;
   }
   return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
using namespace std;

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
   int t,n,i,k,x,j,z;
   cin>>t;
   for (i=0;i<t;i++)
   {
       cin>>n>>k;
       x=1;
       while (x*(x+1)/2<k)
       {
           x++;
       }

       z=x*(x+1)/2;
      for(j=0;j<n-1-x;j++)
      {
          cout<<"a";
      }
      cout<<"b";
      for (j=0;j<z-k;j++)
      {
          cout<<"a";
      }
      cout<<"b";
      for (j=0;j<x-(z-k)-1;j++)
      {
          cout<<"a";
      }
      cout<<endl;
       //cout<<x<<endl;
   }
   return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
using namespace std;

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
   int t,n,i,k,x,j,z;
   string a;
   cin>>t;
   for (i=0;i<t;i++)
   {
       cin>>n>>k;
       a="";
       for (i=0;i<n-2;i++)
       {
           a+="a";
       }
       a+="bb";
       x=(-1+sqrt(1+8*k))/2;
       while (x*(x+1)/2<k)
       {
           x++;
       }
       x--;
       z=x*(x+1)/2;

      swap(a[n-2],a[n-2-x]);
      swap(a[n-1],a[n-(k-z)]);
      cout<<a<<endl;
      cout<<x<<" "<<k<<" "<<z<<endl;
       //cout<<x<<endl;
   }
   return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
using namespace std;

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
   int t,n,i,k,x,j,z;
   cin>>t;
   for (i=0;i<t;i++)
   {
       cin>>n>>k;
       x=(-1+sqrt(1+8*k))/2;
       while (x*(x+1)/2<k)
       {
           x++;
       }

       z=x*(x+1)/2;
      for(j=0;j<n-1-x;j++)
      {
          cout<<"a";
      }
      cout<<"b";
      for (j=0;j<z-k;j++)
      {
          cout<<"a";
      }
      cout<<"b";
      for (j=0;j<x-(z-k)-1;j++)
      {
          cout<<"a";
      }
      cout<<endl;
       //cout<<x<<endl;
   }
   return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
using namespace std;

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
   long long int t,n,i,k,x,j,z;
   cin>>t;
   for (i=0;i<t;i++)
   {
       cin>>n>>k;
      // x=(-1+sqrt(1+8*k))/2;
       while (x*(x+1)/2<k)
       {
           x++;
       }

       z=x*(x+1)/2;
      for(j=0;j<n-1-x;j++)
      {
          cout<<"a";
      }
      cout<<"b";
      for (j=0;j<z-k;j++)
      {
          cout<<"a";
      }
      cout<<"b";
      for (j=0;j<x-(z-k)-1;j++)
      {
          cout<<"a";
      }
      cout<<endl;
       //cout<<x<<endl;
   }
   return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
using namespace std;

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
   long long int t,n,i,k,x,j,z;
   cin>>t;
   for (i=0;i<t;i++)
   {
       cin>>n>>k;
       x=(-1+sqrt(1+8*k))/2;
       while (x*(x+1)/2<k)
       {
           x++;
       }

       z=x*(x+1)/2;
      for(j=0;j<n-1-x;j++)
      {
          cout<<"a";
      }
      cout<<"b";
      for (j=0;j<z-k;j++)
      {
          cout<<"a";
      }
      cout<<"b";
      for (j=0;j<x-(z-k)-1;j++)
      {
          cout<<"a";
      }
      cout<<endl;
       //cout<<x<<endl;
   }
   return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main(){
	int n,t,k,first_b,second_b,now;
	cin>>t;

    while(t--){
        cin>>n>>k;
        first_b=2;
        string s(n,'a');
        now=1;
        for(int i=1;i<=n;i++){
           second_b=1;
           while(second_b<i){
               if(now==k){
                   s[n-second_b]='b';
                   s[n-i]='b';
                   cout<<s<<endl;
                   i=n;
                   i++;
                   break;
               }
               else{
                   second_b++;
                   now++;
               }
           }
        }
    }
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main(){
	int n,t,k,first_b,second_b,now;
	cin>>t;

    while(t--){
        cin>>n>>k;
        first_b=2;
        string s(n,'a');
        now=1;
        for(int i=1;i<n;i++){
           second_b=1;
           while(second_b<first_b){
               if(now==k){
                   s[n-second_b]='b';
                   s[n-first_b]='b';
                   cout<<s<<endl;
                   i=n;
                   break;
               }
               else{
                   second_b++;
                   now++;
               }
           }
           first_b++;
        }
    }
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main(){
	int n,t,k,first_b,second_b,now;
	cin>>t;

    while(t--){
        cin>>n>>k;
        first_b=2;
        string s(n,'a');
        now=1;
        for(int i=1;i<=n;i++){
           second_b=1;
           while(second_b<i){
               if(now==k){
                   s[n-second_b]='b';
                   s[n-i]='b';
                   cout<<s<<endl;
                   i=n;
                   i++;
                   break;
               }
               else{
                   second_b++;
                   now++;
               }
           }
        }
    }
	 return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main(){
	int n,t,k,print_now;
	bool printed=false;
	cin>>t;

    while(t>0){
            print_now=0;
        	cin>>n>>k;
            string s(n,'a');
            s.replace(n-2,2,"bb");
            string initial=s;

            print_now++;
            if(print_now==k ){
                cout<<s<<endl ;
                t--;
                continue; // will jump to next testcase
            }

            int a_to_deal=1;
            while(a_to_deal<=n-2){
     		    string s3(a_to_deal,'a');

    		    s.replace(n-2-a_to_deal+1,a_to_deal,s3);
    		    s[n-2-a_to_deal]='b';

                print_now++;
                if(print_now==k){
                 cout<<s<<endl ;

                 break; // will jump to t--
               }

     		    for(int j=0;j<a_to_deal;j++){
     			    if(s[n-1-a_to_deal]=='a'){
     				    s[n-2-j]='b';
     				    s[n-1-j]='a';
		 		    }
		 		    print_now++;
		 		    if(print_now==k){
                        cout<<s<<endl ;
                        printed=true;
                        break;
                    }
		 		 if(printed){
		 		     break;
		 		 }
	 		    }
	 		    a_to_deal++;
	 		    s=initial;
	    }
	    t--;
    }
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main(){
	int n,t,k,print_now;
	cin>>t;

    for(int l=0;l<t;l++){
            print_now=0;
        	cin>>n>>k;
            string s(n,'a');
            string s2(2,'b');
            s.replace(n-2,n,s2);
            string initial=s;

            print_now++;
            if(print_now==k){
                cout<<s<<endl ;
            }

            int a_to_deal=1;
            while(a_to_deal<=n-2){
     		    string s3(a_to_deal,'a');

    		    s.replace(n-2-a_to_deal+1,a_to_deal,s3);
    		    s[n-2-a_to_deal]='b';

                print_now++;
                if(print_now==k){
                 cout<<s<<endl ;
               }

     		    for(int j=0;j<a_to_deal;j++){
     			    if(s[n-1-a_to_deal]=='a'){
     				    s[n-2-j]='b';
     				    s[n-1-j]='a';
		 		    }
		 		    print_now++;
		 		    if(print_now==k){
                        cout<<s<<endl ;
                    }

	 		    }
	 		    a_to_deal++;
	 		    s=initial;
	    }
    }
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main(){
	int n,t,k,print_now;
	bool printed;
	cin>>t;

    while(t>0){
            printed=false;
            print_now=0;
        	cin>>n>>k;
            string s(n,'a');
            s.replace(n-2,2,"bb");
            string initial=s;

            print_now++;
            if(print_now==k ){
                cout<<s<<endl ;
                t--;
                continue; // will jump to next testcase
            }

            int a_to_deal=1;
            while(a_to_deal<=n-2){
     		    string s3(a_to_deal,'a');

    		    s.replace(n-2-a_to_deal+1,a_to_deal,s3);
    		    s[n-2-a_to_deal]='b';

                print_now++;
                if(print_now==k){
                 cout<<s<<endl ;
                 printed=true;
                 break; // will jump to t--
               }

     		    for(int j=0;j<a_to_deal;j++){
     			    if(s[n-1-a_to_deal]=='a'){
     				    s[n-2-j]='b';
     				    s[n-1-j]='a';
		 		    }
		 		    print_now++;
		 		    if(print_now==k){
                        cout<<s<<endl ;
                        printed=true;
                        break;
                    }

	 		    }
	 		     if(printed){
		 		     break;
		 		 }
	 		    a_to_deal++;
	 		    s=initial;
	    }
	    t--;
    }
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main(){
	int n,t,k,print_now;
	cin>>t;

    while(t>0){
            print_now=0;
        	cin>>n>>k;
            string s(n,'a');
            s.replace(n-2,2,"bb");
            string initial=s;

            print_now++;
            if(print_now==k){
                cout<<s<<endl ;
                t--;
                continue;
            }

            int a_to_deal=1;
            while(a_to_deal<=n-2){
     		    string s3(a_to_deal,'a');

    		    s.replace(n-2-a_to_deal+1,a_to_deal,s3);
    		    s[n-2-a_to_deal]='b';

                print_now++;
                if(print_now==k){
                 cout<<s<<endl ;
                 t--;
                 continue;
               }

     		    for(int j=0;j<a_to_deal;j++){
     			    if(s[n-1-a_to_deal]=='a'){
     				    s[n-2-j]='b';
     				    s[n-1-j]='a';
		 		    }
		 		    print_now++;
		 		    if(print_now==k){
                        cout<<s<<endl ;
                        t--;
                        continue;
                    }

	 		    }
	 		    a_to_deal++;
	 		    s=initial;
	    }
	    t--;
    }
	return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<long long int> vll;
typedef vector<char> vc;
typedef long double ld;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;
typedef string::iterator strit;
typedef vector<long long int>::iterator vllit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;
const int EPS = 1e-6;

#define _  %  MOD
#define __ %= MOD

#define      each(it,s)        for(vit it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))

#define      rep(i, n)         for(int i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(int i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(int i = a; i >= (n); --i)
#define 	 pq(x)			   priority_queue<x,std::vector<x>,compare>
#define 	 rpq(x)			   priority_queue<x,std::vector<x>,compare>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define vin(a,n) vi a;rep(i,n){int in;fri(in);a.pb(in);}
#define arrin(arr,n) rep(i,n){cin>>arr[i];}
#define vp(a) rep(i,a.size()){cout<<a[i]<<" ";}
#define fbo find_by_order
#define ook order_of_key
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
/*
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    */
int main()
{
    fastio;
    int t;
    cin>>t;
    while(t--)
    {
        ll n,k;
        cin>>n>>k;
        ll i=(ll)((sqrt(1+8*k)-1)/2)-1;
        int f=0;
        while((i*(i+1))/2<k)
        {
            i++;
            //f++;
        }
        //cout<<f<<endl;
        ll d = i*(i+1)/2 - k;
        string s(n,'a');
        s[n-1-i]='b';
        s[n+d-i]='b';
        cout<<s<<endl;
    }
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<long long int> vll;
typedef vector<char> vc;
typedef long double ld;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;
typedef string::iterator strit;
typedef vector<long long int>::iterator vllit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;
const int EPS = 1e-6;

#define _  %  MOD
#define __ %= MOD

#define      each(it,s)        for(vit it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))

#define      rep(i, n)         for(int i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(int i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(int i = a; i >= (n); --i)
#define 	 pq(x)			   priority_queue<x,std::vector<x>,compare>
#define 	 rpq(x)			   priority_queue<x,std::vector<x>,compare>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define vin(a,n) vi a;rep(i,n){int in;fri(in);a.pb(in);}
#define arrin(arr,n) rep(i,n){cin>>arr[i];}
#define vp(a) rep(i,a.size()){cout<<a[i]<<" ";}
#define fbo find_by_order
#define ook order_of_key
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
/*
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    */
int main()
{
    fastio;
    int t;
    cin>>t;
    while(t--)
    {
        int n,k;
        cin>>n>>k;
        int i=1;
        while((i*(i+1))/2<k)
        {
            i++;
        }
        int d = i*(i+1)/2 - k;
        string s="";
        rep(j,n-1-i)
        s+='a';
        s+='b';
        rep(j,d)
        s+='a';
        s+='b';
        while(s.size()<n)
        s+='a';
        cout<<s<<endl;
    }
}