#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  for (; b; a %= b, swap(a, b))
    ;
  return a;
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); };
int dr[] = {0, 1, 0, -1, 1, 1, -1, -1};
int dc[] = {1, 0, -1, 0, 1, -1, 1, -1};
int n, m, k, t;
int a[51];
int main() {
  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    cin >> n;
    vector<int> alp[26];
    string ans;
    vector<bool> sel(51, 0);
    vector<int> scnt(26, 0);
    for (int i = 0; i < s.size(); i++) {
      scnt[s[i] - 'a']++;
    }
    for (int i = 0; i < n; i++) {
      ans += ' ';
      cin >> a[i];
    }
    int aidx = 25;
    while (1) {
      int mn = 1e9;
      for (int i = 0; i < n; i++) {
        if (!sel[i]) mn = min(mn, a[i]);
      }
      if (mn == 1e9) break;
      vector<int> v;
      int cnt = 0;
      for (int i = 0; i < n; i++) {
        if (sel[i]) continue;
        if (mn == a[i]) {
          sel[i] = 1;
          v.push_back(i);
          cnt++;
        }
      }
      while (scnt[aidx] < cnt) aidx--;
      for (auto it : v) {
        ans[it] = aidx + 'a';
      }
      for (int i = 0; i < n; i++) {
        if (!sel[i]) {
          for (int j = 0; j < v.size(); j++) a[i] -= abs(i - v[j]);
        }
      }
      aidx--;
    }
    cout << ans << '\n';
  }
  return 0;
}
