#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    string s;
    cin >> s;
    int m;
    cin >> m;
    char t[m + 1];
    t[m] = '\0';
    vector<int> b(m), freq(26);
    for (int i = 0; i < m; i++) scanf("%d", &b[i]);
    for (auto i : s) freq[i - 'a']++;
    int j = 25;
    while (true) {
      vector<int> pos;
      for (int i = 0; i < m; i++)
        if (b[i] == 0) pos.push_back(i);
      if (pos.empty()) break;
      while (pos.size() > freq[j]) j--;
      for (auto p : pos) t[p] = (j + 'a');
      j--;
      for (int i = 0; i < m; i++)
        if (b[i] == 0)
          b[i] = -1;
        else
          for (auto p : pos) b[i] -= abs(i - p);
    }
    cout << t << endl;
  }
  return 0;
}
