#include <bits/stdc++.h>
const int MAX = 1e5 + 10;
const int M = 10;
const long long MOD = 2147493647;
using namespace std;
char s[60], cnt[60];
int a[60], sum[60], vis[60];
int main() {
  int t, m;
  cin >> t;
  while (t--) {
    cin >> s + 1 >> m;
    int n = strlen(s + 1);
    memset(sum, 0, sizeof(sum));
    memset(vis, 0, sizeof(vis));
    for (int i = 1; i <= m; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) sum[s[i] - 'a' + 1]++;
    int ans = 0, pos = 26;
    while (ans < m) {
      int k = 0, nw;
      for (int i = 1; i <= m; i++)
        if (a[i] == 0 && vis[i] == 0) k++;
      for (int i = pos; i > 0; i--)
        if (sum[i] >= k) {
          nw = i;
          break;
        }
      int c = 0, len = 0;
      for (int i = 1; i <= m; i++) {
        if (a[i] == 0 && vis[i] == 0) {
          vis[i] = 1;
          len += i;
          c++;
          ans++;
          cnt[i] = char(nw + 'a' - 1);
          for (int j = 1; j < i; j++)
            if (a[j]) a[j] -= (i - j);
        } else
          a[i] -= c * i - len;
      }
      pos = nw - 1;
    }
    for (int i = 1; i <= m; i++) cout << cnt[i];
    cout << endl;
  }
  return 0;
}
