#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios::sync_with_stdio(false);
  int ntc;
  cin >> ntc;
  while (ntc--) {
    string s;
    cin >> s;
    int m;
    cin >> m;
    vector<int> b(m);
    for (int& bi : b) cin >> bi;
    map<char, int> cnt;
    for (char c : s) cnt[c]++;
    vector<char> t(m, '*');
    char top = 'z';
    while (true) {
      if constexpr (false) {
        for (int i = 0; i < m; i++)
          if constexpr (false) cerr << b[i] << ' ';
        if constexpr (false) cerr << endl;
      }
      int nz = 0;
      for (int i = 0; i < m; i++)
        if (t[i] == '*' and b[i] == 0) nz++;
      if (not nz) break;
      while (cnt[top] < nz) top--;
      for (int i = 0; i < m; i++) {
        if (t[i] != '*' or b[i] != 0) continue;
        t[i] = top;
      }
      for (int i = 0; i < m; i++) {
        if (t[i] != top) continue;
        for (int j = 0; j < m; j++) {
          if (t[j] == '*') {
            b[j] -= abs(i - j);
            if constexpr (false) {
              if constexpr (false) cerr << "[" << i << ", " << j << "]" << endl;
            }
          }
        }
      }
      top--;
    }
    for (int i = 0; i < m; i++) {
      int x = 0;
      for (int j = 0; j < m; j++) {
        if (t[j] > t[i]) x += abs(i - j);
      }
    }
    for (char ti : t) cout << ti;
    cout << '\n';
  }
}
