#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define F0(n, i) for(int i = 0; i < n; i++)
#define each(a) for(auto& e: a)
#define pb push_back
template<typename T>
class segtree {
public:
vector<T> t;
int n;
T def;
function<T(T, T)> fx;
void build(int _n, T _def, function<T(T, T)> _fx) {
n = _n; def = _def; fx = _fx;
t.assign(n * 2, def);
for(int i = n - 1; i; i--) t[i] = fx(t[i * 2], t[i * 2 + 1]);
}
void build(string& a, T _def, function<T(T, T)> _fx) {
n = a.size(); def = _def; fx = _fx;
t.assign(n * 2, def);
F0(n, i) t[i + n] = {a[i], i};
for(int i = n - 1; i; i--) t[i] = fx(t[i * 2], t[i * 2 + 1]);
}
void update(int i, T v) {
for(t[i += n] = v; i > 1; ) {
i /= 2;
t[i] = fx(t[i * 2], t[i * 2 + 1]);
}
}
T query(int l, int r) {
T lans = def, rans = def;
for(l += n, r += n; l < r; l /= 2, r /= 2) {
if(l % 2) lans = fx(lans, t[l++]);
if(r % 2) rans = fx(t[--r], rans);
}
return fx(lans, rans);
}
};
void solve() {
string s;
int k;
cin >> s >> k;
int n = s.size();
segtree<pair<char, int>> Max;
Max.build(s, pair<char, int>{'a', n}, [&](pair<char, int> x, pair<char, int> y) {
if(x.first >= y.first) return x;
return y;
});
int i = 0;
string ans;
while(i + k < n) {
pair<char, int> q = Max.query(i, i + k + 1);
ans.pb(q.first);
k -= q.second - i;
i = q.second + 1;
}
cout << ans;
}
int32_t main() {
int t = 1;
cin >> t;
while(t--) {
solve();
cout << endl;
cerr << endl;
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgojZGVmaW5lIGludCBpbnQ2NF90CiNkZWZpbmUgZW5kbCAnXG4nCiNkZWZpbmUgdmkgdmVjdG9yPGludD4KI2RlZmluZSB2dmkgdmVjdG9yPHZpPgojZGVmaW5lIEYwKG4sIGkpIGZvcihpbnQgaSA9ID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