#include<bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { int i,z,a1,b1,len; string s; cin>>s; int x,y; cin>>x>>y; int m=0,n=0; len=s.length(); for(i=0;i<len;i++) { if(s[i]=='a') m++; if(s[i]=='b') n++; } z=m+n; a1=0,b1=0; for(i=0;i<z;i++) { if(m>0||n>0) { if((a1<x)&&(m!=0)) { a1++; cout<<"a"; b1=0; m--; } else if((b1<y)&&(n!=0)) { b1++; cout<<"b"; a1=0; n--; } else if(a1>=x&&n==0) { cout<<"*a"; a1=1; b1=0; m--; } else if(b1>=y&&m==0) { cout<<"*b"; a1=0; b1=1; } } } cout<<endl; } return 0; }
Asked by: Manish_Kumar_Savita on April 7, 2019, 6:34 p.m. Last updated on April 7, 2019, 6:34 p.m.