#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int T = 1;
  cin >> T;
  while (T--) {
    bool flag = true, cond = true;
    long long n, i, j, x, y, ind, k, m, p = 0, mx = 0, diff, y1, cnt = 0, mn;
    string s, t;
    cin >> s;
    cin >> m;
    vector<long long> a(m);
    for (i = 0; i < m; i++) cin >> a[i];
    n = s.size();
    long long arr[26] = {0};
    for (i = 0; i < s.size(); i++) {
      arr[s[i] - 'a']++;
    }
    for (i = 25; i >= 0; i--) {
      if (arr[i] != 0) {
        ind = i;
        break;
      }
    }
    for (i = 0; i < m; i++) t += '.';
    long long b[m];
    cnt = 0;
    for (i = 0; i < m; i++) {
      if (a[i] == 0) {
        cnt++;
      }
    }
    while (ind >= 0 && arr[ind] < cnt) ind--;
    for (i = 0; i < m; i++) {
      if (a[i] == 0) {
        t[i] = 'a' + ind;
      }
    }
    ind--;
    while (ind >= 0 && arr[ind] == 0) ind--;
    while (ind >= 0 && count(t.begin(), t.end(), '.') > 0) {
      for (i = 0; i < m; i++) b[i] = 0;
      for (i = 0; i < m; i++) {
        if (t[i] != '.') {
          for (j = 0; j < m; j++) {
            if (t[j] == '.') b[j] += abs(i - j);
          }
        }
      }
      cnt = 0;
      for (i = 0; i < m; i++) {
        if (a[i] == b[i] && a[i] != 0) {
          cnt++;
        }
      }
      while (ind >= 0 && arr[ind] < cnt) ind--;
      for (i = 0; i < m; i++) {
        if (a[i] == b[i] && a[i] != 0) {
          t[i] = 'a' + ind;
        }
      }
      ind--;
      while (ind >= 0 && arr[ind] == 0) ind--;
    }
    cout << t << "\n";
  }
  return 0;
}
