#include <bits/stdc++.h>
using namespace std;
const int N = 210, mod = 1e9 + 7, inf = 0x3f3f3f;
int a[N], num[30];
char ans[N];
int n;
string s;
vector<int> tmp;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> s >> n;
    memset(num, 0, sizeof num);
    for (int i = 0; i < s.size(); i++) num[s[i] - 'a']++;
    for (int i = 0; i < n; i++) cin >> a[i];
    int cnt = n, kk = 25;
    while (cnt) {
      tmp.clear();
      for (int i = 0; i < n; i++) {
        if (!a[i]) tmp.push_back(i), cnt--, a[i] = -1;
      }
      while (tmp.size() > num[kk]) kk--;
      num[kk] -= tmp.size();
      for (int i = 0; i < tmp.size(); i++) {
        ans[tmp[i]] = kk + 'a';
        for (int j = 0; j < n; j++) {
          if (a[j] > 0) a[j] -= abs(j - tmp[i]);
        }
      }
      kk--;
    }
    ans[n] = 0;
    cout << ans << '\n';
  }
  return 0;
}
