#include <bits/stdc++.h>
using namespace std;
const int N = 40043;
const long long int mod = 1e9 + 7;
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int lcm(int a, int b) { return (a * b) / gcd(a, b); }
int pow(int a, int b, int mo) {
  if (a == 0) return 1;
  long long int u = pow(a, b / 2, mo);
  u = (u * u) % mo;
  if (b % 2 == 1) u = (u * a) % mo;
  return u;
}
long long int power(long long int a, long long int b) {
  long long int ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ans;
}
long long int xx, yy, dd;
void equation(long long int a, long long int b) {
  if (b == 0) {
    xx = 1;
    yy = 0;
    dd = a;
  } else {
    equation(b, a % b);
    long long int temp = xx;
    xx = yy;
    yy = temp - (a / b) * yy;
  }
}
long long int inverse(long long int a, long long int m) {
  equation(a, m);
  return (xx % m + m) % m;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s, s1;
    cin >> s;
    s1 = s;
    int m, n;
    n = s.length();
    cin >> m;
    int b[m];
    map<char, int> mp;
    for (int i = 0; i < n; i++) mp[s[i]] += 1;
    for (int i = 0; i < m; i++) {
      cin >> b[i];
    }
    vector<char> v(m);
    int a[m];
    sort(s.begin(), s.end());
    for (int i = 0; i < m; i++) a[i] = 0;
    int cnt = 0, j = n - 1;
    while (cnt != m) {
      int c = 0;
      vector<int> p;
      for (int i = 0; i < m; i++) {
        if (b[i] == 0) c++, p.push_back(i);
      }
      while (mp[s[j]] < c) {
        j -= 1;
      }
      for (auto x : p) {
        cnt++;
        v[x] = s[j];
        for (int i = 0; i < m; i++) {
          if (b[i] != 0 && b[i] != -1) {
            if (i < x)
              b[i] -= (x - i);
            else
              b[i] -= (i - x);
          }
        }
        b[x] = -1;
      }
      j -= mp[s[j]];
    }
    for (auto x : v) cout << x << "";
    cout << endl;
  }
}
