#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890123456789LL
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge
typedef long long cat;
#ifdef DONLINE_JUDGE
// palindromic tree is better than splay tree!
#define lld I64d
#endif
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(10);
int T;
cin >> T;
while(T--) {
string S;
int x,y;
cin >> S >> x >> y;
int a =0, b =0;
for(int i =0; i < (int)S.length(); i++) {
if(S[i] == 'a') a++;
else b++;
}
string ans;
while(a > 0 && b > 0) {
if(a > b) {
for(int j =0; j < min(x,a-b+1); j++) ans +='a';
ans +='b';
a -=min(x,a-b+1);
b--;
}
else if(a < b) {
for(int j =0; j < min(y,b-a+1); j++) ans +='b';
ans +='a';
b -=min(y,b-a+1);
a--;
}
else break; // a == b
}
if(a > 0 && b > 0) { // a == b
string s ="ab";
if(!ans.empty() && ans[0] == 'b') s ="ba";
for(int i =0; i < a; i++) ans +=s;
cout << ans << "\n";
continue;
}
// b == 0 || a == 0
for(int i =0; i < a; i++) {
if(i%x == 0 && i > 0) ans +='*';
ans +='a';
}
for(int i =0; i < b; i++) {
if(i%y == 0 && i > 0) ans +='*';
ans +='b';
}
cout << ans << "\n";
}
}
// look at my code
// my code is amazing
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Ci8vIGlvc3RyZWFtIGlzIHRvbyBtYWluc3RyZWFtCiNpbmNsdWRlIDxjc3RkaW8+Ci8vIGJpdGNoI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