//Round#751_A
include <bits/stdc++.h>
include
define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std; int main() { int T;cin>>T; while(T--) { fastio(); string s,store,store1; cin>>s; int count=s.length(); store=s; sort(s.begin(), s.end()); store1=s[0]; cout<<s[0]; auto it = std::find(store.begin(), store.end(), s[0]); if (it != store.end()) store.erase(it); cout<<" "<<store<<endl; } return 0; }
/*INPUT :
3 fc aaaa thebrightboiler
*/