#include <bits/stdc++.h>
using namespace std;
bool comp(char a, char b) {
  if (a > b) return true;
  return false;
}
int main() {
  long long t;
  cin >> t;
  while (t--) {
    string second;
    cin >> second;
    sort(second.begin(), second.end(), comp);
    int m;
    cin >> m;
    vector<char> ans(m);
    vector<pair<int, int> > v(m);
    int zero = 0;
    for (int i = 0; i < m; i++) {
      cin >> v[i].first;
      v[i].second = i;
      if (v[i].first == 0) zero++;
    }
    int l = 0;
    for (long long i = 0; i < m; i++) {
      vector<int> jk;
      if (zero != 1) {
        int p = l + 1;
        int count = 1;
        while (count != zero && l < second.size()) {
          if (second[p] == second[p - 1]) {
            count++;
            p++;
          } else {
            l++;
            p = l + 1;
            count = 1;
          }
        }
      }
      for (long long j = 0; j < m; j++) {
        if (v[j].first == 0) {
          ans[j] = second[l];
          l++;
          jk.push_back(j);
          v[j].first = -1;
        }
      }
      while (second[l] == second[l - 1]) l++;
      zero = 0;
      for (long long x = 0; x < jk.size(); x++) {
        for (long long j = 0; j < m; j++) {
          if (v[j].first > 0) {
            if (j < jk[x]) {
              v[j].first -= (jk[x] - j);
            } else {
              v[j].first += (jk[x] - j);
            }
            if (v[j].first == 0) {
              zero++;
            }
          }
        }
      }
    }
    for (long long i = 0; i < m; i++) {
      cout << ans[i];
    }
    cout << endl;
  }
  return 0;
}
