#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const double pi = acos(-1.0);
clock_t start_time = clock();
template <typename T, typename U>
inline void amin(T &x, U y) {
  if (y < x) x = y;
}
template <typename T, typename U>
inline void amax(T &x, U y) {
  if (x < y) x = y;
}
template <typename T>
inline void write(T x) {
  int i = 20;
  char buf[21];
  buf[20] = '\n';
  do {
    buf[--i] = x % 10 + '0';
    x /= 10;
  } while (x);
  do {
    putchar(buf[i]);
  } while (buf[i++] != '\n');
}
template <typename T>
inline T readInt() {
  T n = 0, s = 1;
  char p = getchar();
  if (p == '-') s = -1;
  while ((p < '0' || p > '9') && p != EOF && p != '-') p = getchar();
  if (p == '-') s = -1, p = getchar();
  while (p >= '0' && p <= '9') {
    n = (n << 3) + (n << 1) + (p - '0');
    p = getchar();
  }
  return n * s;
}
void solve(string s, int m, vector<int> &b) {
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      bpq;
  priority_queue<pair<int, int>, vector<pair<int, int>>, less<pair<int, int>>>
      cntpq;
  string t;
  t.resize(m);
  vector<int> idx;
  for (int i = 0; i < m; i += 1) {
    if (b[i] == 0) {
      idx.push_back(i);
    }
  }
  sort(s.begin(), s.end(), greater<int>());
  int n = s.size();
  int l = 0;
  do {
    int cnt_idx = idx.size();
    int cnt = 0;
    while (l < n && cnt < cnt_idx) {
      cnt = 1;
      while (l < n - 1 && s[l] == s[l + 1]) {
        cnt++;
        l++;
      }
      l++;
    }
    for (int i : idx) {
      t[i] = s[l - 1];
    }
    vector<int> curr_idx;
    for (int i = 0; i < m; i += 1) {
      if (b[i] > 0) {
        for (int j : idx) {
          b[i] -= abs(i - j);
        }
        if (b[i] == 0) curr_idx.push_back(i);
      }
    }
    idx = curr_idx;
  } while (!idx.empty() && l < n);
  cout << t << endl;
}
int main() {
  int tc;
  tc = readInt<int>();
  while (tc--) {
    string s;
    int m;
    cin >> s;
    cin >> m;
    vector<int> b(m);
    for (auto &i : b) {
      cin >> i;
    }
    solve(s, m, b);
  }
  return 0;
}
