You are on page 1of 2

#include <bits/stdc++.

h>
using namespace std;
int T, n, a[20010];
string s;

int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
//freopen("ZSTRING.INP", "r", stdin);
//freopen("ZSTRING.OUT", "w", stdout);
cin >> T;
for (int iTest = 1; iTest <= T; iTest++) {
cin >> n;
bool oce = 1;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] >= 27)
oce = 0;
}
if (a[1] == 1 && n == 1) {
cout << "z\n";
continue;
}
if (a[1] == 1 || oce == 0) {
cout << -1 << '\n';
continue;
}
s = "z";
a[1]--;
int pos = 24;
for (int i = 1; i <= n; i++) {
if (i % 2 == 0) {
pos = 1;
int d = 1;
while (d < a[i]) {
if (pos < 0 || pos > 25) {
oce = 0;
break;
}
s += ('a' + pos);
pos++;
d++;
}
if (i < n)
pos = max(pos, a[i+1]);
if (pos < 0 || pos > 25) {
oce = 0;
break;
}
s += ('a' + pos);
}
else {
pos = a[i] - 1;
int d = 1;
while (d <= a[i]) {
if (pos < 0 || pos > 25) {
oce = 0;
break;
}
s += ('a' + pos);
pos--;
d++;
}
}
if (oce == 0) break;
}
if (oce == 0) cout << -1 << '\n';
else cout << s << '\n';
}
}

You might also like