#include <bits/stdc++.h>
using namespace std;
long long max(long long a, long long b) { return (a > b) ? a : b; }
long long min(long long a, long long b) { return (a < b) ? a : b; }
long long mm(vector<long long> a, vector<long long> b) {
  if (a[1] < b[1]) return true;
  if (a[1] == b[1] && a[0] < b[0]) return true;
  return false;
}
long long gcd(long long a, long long b) {
  while (1) {
    if (a == 0) return b;
    b %= a;
    if (b == 0) return a;
    a %= b;
  }
}
long long p2(long long k, long long n) {
  long long re = 1;
  while (n) {
    if (n % 2 == 1) re = (re * k) % 1000000007;
    k *= k;
    k %= 1000000007;
    n /= 2;
  }
  return re;
}
int main() {
  long long n, m, i, j, t, k;
  t = 1;
  cin >> t;
  for (long long ii = 0; ii < t; ii++) {
    string s;
    cin >> s;
    cin >> m;
    n = s.size();
    vector<long long> a(m);
    k = 0;
    for (i = 0; i < m; i++) {
      cin >> a[i];
      if (a[i] == 0) k++;
    }
    vector<long long> b(26);
    vector<char> p(m, 'A');
    vector<long long> d;
    for (i = 0; i < n; i++) b[s[i] - 'a']++;
    for (i = 25; i >= 0; i--)
      if (b[i] >= k) break;
    j = i;
    for (i = 0; i < m; i++)
      if (a[i] == 0) {
        d.push_back(i);
        p[i] = j + 'a';
      }
    j = j - 1;
    while (k < m) {
      long long l1 = 0;
      vector<long long> d1;
      for (i = 0; i < m; i++) {
        if (p[i] != 'A') continue;
        long long l = 0;
        for (long long h = 0; h < d.size(); h++) l += abs(d[h] - i);
        if (l == a[i]) {
          l1++;
          d1.push_back(i);
        }
      }
      for (; j >= 0; j--)
        if (b[j] >= l1) break;
      for (i = 0; i < d1.size(); i++) {
        k++;
        p[d1[i]] = j + 'a';
        d.push_back(d1[i]);
      }
      j--;
    }
    for (i = 0; i < m; i++) cout << p[i];
    cout << endl;
  }
  return 0;
}
