#include using namespace std; void test_case(int tc){ int n, m, k; cin >> n >> m >> k; vector x, y; for (size_t i = 0; i < n; i++){ char c; cin >> c; x.push_back(c); } for (size_t i = 0; i < m; i++){ char c; cin >> c; y.push_back(c); } int k_counter = 0; string result = ""; // We need to keep track of the last one for optimal placement I think bool lastChoice = x.front() < y.front(); sort(x.begin(), x.end()); reverse(x.begin(), x.end()); sort(y.begin(), y.end()); reverse(y.begin(), y.end()); while(!x.empty() && !y.empty()){ char cx = x.back(), cy = y.back(); if(lastChoice != (cx < cy)){ k_counter = 0; } if(lastChoice == (cx < cy) && k_counter == k){ k_counter = 0; lastChoice = cx >= cy; if(cx < cy){ y.pop_back(); result.push_back(cy); } else { x.pop_back(); result.push_back(cx); } } else { lastChoice = cx < cy; if(cx < cy){ x.pop_back(); result.push_back(cx); } else{ y.pop_back(); result.push_back(cy); } } k_counter++; } cout << result << '\n'; } int main(){ ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; for(int tc = 1; tc <= t; ++tc){ test_case(tc); } cout << flush; return 0; }