#include <bits/stdc++.h>
using namespace std;
int cnt[26], b[58];
int m, need, last;
char t[58];
int mX() {
  for (int i = 25; i >= 0; i--)
    if (cnt[i] >= need && i < last) {
      last = i;
      cnt[i] = 0;
      return i;
    }
}
bool check() {
  for (int i = 0; i < m; i++) {
    if (t[i] == '0') return false;
  }
  return true;
}
void f() {
  if (check()) return;
  need = 0;
  vector<int> pos;
  for (int i = 0; i < m; i++)
    if (b[i] == 0) {
      need++;
      pos.push_back(i);
    }
  int mx = mX();
  for (int i = 0; i < m; i++) {
    if (b[i] == 0) {
      b[i] = INT_MAX;
      t[i] = ('a' + mx);
    } else
      for (int x = 0; x < pos.size(); x++) b[i] -= abs(i - pos[x]);
  }
  f();
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    string s;
    cin >> s;
    memset(cnt, 0, sizeof(cnt));
    memset(b, 0, sizeof(b));
    for (int i = 0; i < s.size(); i++) cnt[s[i] - 'a']++;
    cin >> m;
    for (int i = 0; i < m; i++) t[i] = '0';
    for (int i = 0; i < m; i++) cin >> b[i];
    last = 26;
    f();
    for (int i = 0; i < m; i++) cout << t[i];
    cout << endl;
  }
}
