#include <bits/stdc++.h>
using namespace std;
long long t, n, i, j, k, x, y, z, l, r, mid, ans, mod = 998244353, h, g, m;
long long a[300005], b[300005], c[300005];
char ch;
string s;
vector<long long> v[300005], u;
int main() {
  ios::sync_with_stdio(NULL);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> s >> m;
    for (i = 0; i < m; i++) cin >> a[i];
    for (i = 0; i < 26; i++) b[i] = 0;
    for (i = 0; i < s.size(); i++) b[s[i] - 'a']++;
    while (1) {
      u.clear();
      for (i = 0; i < m; i++)
        if (a[i] == 0) u.push_back(i), a[i]--;
      if (u.size() == 0) break;
      for (i = 25; i >= 0; i--)
        if (b[i] >= u.size())
          break;
        else
          b[i] = 0;
      b[i] = 0;
      for (j = 0; j < m; j++) {
        if (a[j] <= 0) continue;
        for (k = 0; k < u.size(); k++) a[j] -= abs(u[k] - j);
      }
      for (j = 0; j < u.size(); j++) c[u[j]] = i;
    }
    for (i = 0; i < m; i++) cout << char('a' + c[i]);
    cout << "\n";
  }
}
