#include <bits/stdc++.h>
using namespace std;
void printVector(vector<string> &v) {
  for (auto x : v) cout << x << "\n";
}
void printVector(vector<int> &v) {
  for (auto x : v) cout << x << " ";
  cout << "\n";
}
void printVector(vector<char> &v) {
  for (auto x : v) cout << x;
  cout << "\n";
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int n = s.size();
    int m;
    cin >> m;
    vector<int> b(m);
    for (int i = 0; i < m; i++) {
      cin >> b[i];
    }
    vector<int> freq(26, 0);
    for (int i = 0; i < n; i++) {
      freq[(int)(s[i] - 'a')]++;
    }
    vector<char> ans(m);
    int j = 25;
    vector<int> vis(m, 0);
    int v = 0;
    while (v < m) {
      vector<int> ind;
      for (int i = 0; i < m; i++) {
        if (b[i] == 0 && vis[i] == 0) {
          vis[i] = 1;
          v++;
          ind.push_back(i);
        }
      }
      int k = ind.size();
      while (freq[j] < k) {
        j--;
      }
      for (auto i : ind) {
        ans[i] = (char)('a' + j);
      }
      j--;
      for (int i = 0; i < m; i++) {
        if (vis[i] == 0) {
          for (auto in : ind) {
            b[i] -= abs(i - in);
          }
        }
      }
    }
    printVector(ans);
  }
}
