#include<bits/stdc++.h>
using namespace std;
// #CPP_STL #Strings
// https://www.hackerrank.com/challenges/c-tutorial-stringstream/forum
// https://www.geeksforgeeks.org/stringstream-c-applications/
// Input:
// 2
// 46,75,987
// 23 456 789
// 2,456,908
// 1 267 908
int main(){
// freopen("ip.txt","r",stdin);
int t;
cin>>t;
cin.ignore();
while(t--){
vector<int> num;
string x;
char c; // for char ip in string
int temp; // for num ip in string
cout<<"Enter comma separated integers"<<endl;
getline(cin,x);
stringstream ss(x);
//=============( .str() )========================
// stringstream ss;
// ss.str(x);
while(ss>>temp){ // checks if ip is of type temp(here int)
num.push_back(temp);
ss>>c; // if ip is comma(or any char) push it to char c
}
for(int i=0;i<num.size();i++){
cout<<num[i]<<" ";
}
cout<<endl;
num.clear();
x.clear();
cout<<"Enter space separated numbers"<<endl;
getline(cin,x);
ss.clear();
ss.str(x);
while(ss>>temp){
num.push_back(temp);
//ss>>c; // Not req for space
}
for(int i=0;i<num.size();i++){
cout<<num[i]<<" ";
}
cout<<endl;
}
return 0;
}