#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long max(long long a, long long b) {
  if (a > b) return a;
  return b;
}
long long min(long long a, long long b) {
  if (a < b) return a;
  return b;
}
long long ssum(long long n) { return (n * (n + 1)) / 2; }
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return (a * b) / (gcd(a, b)); }
int cnt[26];
int main() {
  int t;
  cin >> t;
  while (t--) {
    string str;
    cin >> str;
    memset(cnt, 0, sizeof(cnt));
    for (int i = 0; i < str.size(); i++) cnt[str[i] - 'a'] += 1;
    int m;
    cin >> m;
    int arr[m];
    for (int i = 0; i < m; i++) cin >> arr[i];
    vector<vector<int> > vSet;
    vector<int> entry;
    while (true) {
      entry.clear();
      for (int i = 0; i < m; i++) {
        if (arr[i] == 0) entry.push_back(i);
      }
      if (entry.empty()) break;
      int n = entry.size();
      for (int i = 0; i < n; i++) {
        arr[entry[i]] = INT_MAX;
        for (int j = 0; j < m; j++) {
          arr[j] -= abs(entry[i] - j);
        }
      }
      vSet.push_back(entry);
    }
    string ans(m, '!');
    int j = 25;
    for (int i = 0; i < vSet.size(); i++) {
      while (j >= 0) {
        if (vSet[i].size() <= cnt[j]) {
          for (int k = 0; k < vSet[i].size(); k++) {
            ans[vSet[i][k]] = 'a' + j;
          }
          cnt[j] = 0;
          j -= 1;
          break;
        }
        cnt[j] = 0;
        j -= 1;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
