#include<iostream>
#include<vector>
using namespace std;
const int N = 100;
vector<int> d[N];
int n;
int main()
{
cin >> n;
for(int i = 1; i <= n; i++)
{
int t;
cin >> t;
while(t != -1)
{
d[i].push_back(t);
cin >> t;
}
}
for(int i = 1; i <= n; i++)
{
for(int j = 0; j < d[i].size(); j++)
{
cout << d[i][j] << " ";
}
cout << endl;
}
return 0;
}