#include <bits/stdc++.h>
#define endl '\n'
#define debug1( x ) cout << #x << " = " <<  x << endl;
#define debug2( x, y) cout <<#x << " = " << x << " , " <<#y << " = " << y <<endl;
#define F first
#define S second
#define PB push_back
#define size( x )   int( ( x ).size( ) )
#define endl '\n'
#define rep(i, a, b) for( __typeof(a) i =(a); i<(b);i++)
#define rept(i, a, b) for( __typeof(a) i =(a); i<=(b);i++)
#define all(x) x.begin(),x.end()

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

int main(){
  ios::sync_with_stdio( false );
  cin.tie( nullptr );
#ifdef LOCAL
  freopen("in", "r" , stdin);
#endif

  int n, m, t;cin >>t;
  while(t--){
    cin >> n >> m;
    vector< vi > G(n);
    int to ,from;

    rep( i, 0, m){
      cin >> to >> from; to--; from--;
      G[ from ].PB( to );
      G[ to ].PB( from );
    }
    int best = -1;
    priority_queue < pair<int, int> > p;
    rep( i, 0, n){
      if( size(G[i])> best ){
        best = size(G[i]);
        to = i;
      }
      p.push({size(G[i]), i});
    }
    vector< bool > vis(n, false);
    set<ll> ansv;

    rep( i, 0, n){
      if( vis [ i] ) continue;
      vis[i] = true;
      rep( j , 0, size(G[i])) vis[G[i][j]] = true;
      ansv.insert( i+1);
    }
    while( !p.empty() && size(ansv) <n/2){
      ii x = p.top(); p.pop();
      ansv.insert( x.S );
    }
    cout << size(ansv) << endl;
    for( int x: ansv) cout << x << " "; cout <<endl;
  }

  return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define debug1( x ) cout << #x << " = " <<  x << endl;
#define debug2( x, y) cout <<#x << " = " << x << " , " <<#y << " = " << y <<endl;
#define F first
#define S second
#define PB push_back
#define size( x )   int( ( x ).size( ) )
#define endl '\n'
#define rep(i, a, b) for( __typeof(a) i =(a); i<(b);i++)
#define rept(i, a, b) for( __typeof(a) i =(a); i<=(b);i++)
#define all(x) x.begin(),x.end()

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

int main(){
  ios::sync_with_stdio( false );
  cin.tie( nullptr );
#ifdef LOCAL
  freopen("in", "r" , stdin);
#endif

  int n, m, t;cin >>t;
  while(t--){
    cin >> n >> m;
    vector< vi > G(n);
    int to ,from;

    rep( i, 0, m){
      cin >> to >> from; to--; from--;
      G[ from ].PB( to );
      G[ to ].PB( from );
    }
    int best = -1;
    rep( i, 0, n){
      if( size(G[i])> best ){
        best = size(G[i]);
        to = i;
      }
    }

    int ans =1;
    vector< bool > vis(n, false);
    vi ansv;
    ansv.PB(  to +1);
    vis[to] = true;
    rep(i, 0, size(G[to])){
      vis[G[to][i]] = true;
    }
    rep( i, 0, n){
      if( vis [ i] ) continue;
      vis[i] = true; ans++;
      rep( j , 0, size(G[i])) vis[G[i][j]] = true;
      ansv.PB( i+1);
    }
    cout << ans << endl;
    for( int x: ansv) cout << x << " "; cout <<endl;
  }

  return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define debug1( x ) cout << #x << " = " <<  x << endl;
#define debug2( x, y) cout <<#x << " = " << x << " , " <<#y << " = " << y <<endl;
#define F first
#define S second
#define PB push_back
#define size( x )   int( ( x ).size( ) )
#define endl '\n'
#define rep(i, a, b) for( __typeof(a) i =(a); i<(b);i++)
#define rept(i, a, b) for( __typeof(a) i =(a); i<=(b);i++)
#define all(x) x.begin(),x.end()

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

int main(){
  ios::sync_with_stdio( false );
  cin.tie( nullptr );
#ifdef LOCAL
  freopen("in", "r" , stdin);
#endif

  int n, m, t;cin >>t;
  while(t--){
    cin >> n >> m;
    vector< vi > G(n);
    int to ,from;

    rep( i, 0, m){
      cin >> to >> from; to--; from--;
      G[ from ].PB( to );
      G[ to ].PB( from );
    }
    priority_queue < pair<int, int> > p, q;
    rep( i, 0, n){
      p.push({size(G[i]), i});
    }
    vector< bool > vis(n, false);
    set<ll> ansv;

    while( !p.empty()){
      ii x = p.top(); p.pop();
      if( vis [ x.S] ) {
        continue;
      }
      vis[x.S] = true;
      rep( j , 0, size(G[x.S])) vis[G[x.S][j]] = true;
      ansv.insert( x.S+1 );
    }

    cout << size(ansv) << endl;
    for( int x: ansv) cout << x << " "; cout <<endl;
  }

  return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define debug1( x ) cout << #x << " = " <<  x << endl;
#define debug2( x, y) cout <<#x << " = " << x << " , " <<#y << " = " << y <<endl;
#define F first
#define S second
#define PB push_back
#define size( x )   int( ( x ).size( ) )
#define endl '\n'
#define rep(i, a, b) for( __typeof(a) i =(a); i<(b);i++)
#define rept(i, a, b) for( __typeof(a) i =(a); i<=(b);i++)
#define all(x) x.begin(),x.end()

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

int main(){
  ios::sync_with_stdio( false );
  cin.tie( nullptr );
#ifdef LOCAL
  freopen("in", "r" , stdin);
#endif

  int n, m, t;cin >>t;
  while(t--){
    cin >> n >> m;
    vector< vi > G(n);
    int to ,from;

    rep( i, 0, m){
      cin >> to >> from; to--; from--;
      G[ from ].PB( to );
      G[ to ].PB( from );
    }
    priority_queue < pair<int, int> > p, q;
    rep( i, 0, n){
      p.push({size(G[i]), i});
      q.push({size(G[i]), i});
    }
    vector< bool > vis(n, false);
    set<ll> ansv;

    while( !p.empty()){
      ii x = p.top(); p.pop();
      if( vis [ x.S] ) continue;
      vis[x.S] = true;
      rep( j , 0, size(G[x.S])) vis[G[x.S][j]] = true;
      ansv.insert( x.S );
    }

    if( size(ansv) < n/2)
    rep( i, 0, n){
      if( vis [ i] ) continue;
      vis[i] = true;
      rep( j , 0, size(G[i])) vis[G[i][j]] = true;
      ansv.insert( i+1);
    }

    while( !q.empty() && size(ansv) <n/2){
      ii x = q.top(); q.pop();
      ansv.insert( x.S );
    }

    cout << size(ansv) << endl;
    for( int x: ansv) cout << x << " "; cout <<endl;
  }

  return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define debug1( x ) cout << #x << " = " <<  x << endl;
#define debug2( x, y) cout <<#x << " = " << x << " , " <<#y << " = " << y <<endl;
#define F first
#define S second
#define PB push_back
#define size( x )   int( ( x ).size( ) )
#define endl '\n'
#define rep(i, a, b) for( __typeof(a) i =(a); i<(b);i++)
#define rept(i, a, b) for( __typeof(a) i =(a); i<=(b);i++)
#define all(x) x.begin(),x.end()

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

void bfs( int st, vector<vi> &G, int n){
  vector< int > ans, ans2;
  queue< int > q;
  q.push( st );
  vector<int> dist( n);
  vector<bool > vis(n, false);
  dist[st] = 0;
  vis[st] = true;
  while( !q.empty()){
    int t = q.front(); q.pop();
    if( dist[t]%2 ==0 ){
      ans.push_back( t+1 );
    }else{
      ans2.push_back( t+1);
    }
    for( int son: G[t]){
      dist[son] = dist[t] +1 ;
      if( !vis[son]){
        vis[son]  = true;
        q.push( son);
      }
    }
  }
  if( size(ans) < size(ans2)){
    cout << size(ans) <<endl;
    for( int x: ans) cout << x<< " "; cout <<endl;
  }else{
    cout << size(ans2) <<endl;
    for( int x: ans2) cout << x<< " "; cout <<endl;
  }

}

int main(){
  ios::sync_with_stdio( false );
  cin.tie( nullptr );
#ifdef LOCAL
  freopen("in", "r" , stdin);
#endif

  int n, m, t;cin >>t;
  while(t--){
    cin >> n >> m;
    vector< vi > G(n);
    int to ,from;

    rep( i, 0, m){
      cin >> to >> from; to--; from--;
      G[ from ].PB( to );
      G[ to ].PB( from );
    }

    bfs( 0, G, n);

  }

  return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define debug1( x ) cout << #x << " = " <<  x << endl;
#define debug2( x, y) cout <<#x << " = " << x << " , " <<#y << " = " << y <<endl;
#define F first
#define S second
#define PB push_back
#define size( x )   int( ( x ).size( ) )
#define endl '\n'
#define rep(i, a, b) for( __typeof(a) i =(a); i<(b);i++)
#define rept(i, a, b) for( __typeof(a) i =(a); i<=(b);i++)
#define all(x) x.begin(),x.end()

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

void bfs( int st, vector<vi> &G, int n){
  vector< int > ans, ans2;
  queue< int > q;
  q.push( st );
  vector<int> dist( n);
  vector<bool > vis(n, false);
  dist[st] = 0;
  vis[st] = true;
  while( !q.empty()){
    int t = q.front(); q.pop();
    if( dist[t]%2 ==0 ){
      ans.push_back( t+1 );
    }
    for( int son: G[t]){
      dist[son] = dist[st] +1 ;
      if( !vis[son]){
        vis[son]  = true;
        q.push( son);
      }
    }
  }
    cout << size(ans) <<endl;
    for( int x: ans) cout << x<< " "; cout <<endl;

}

int main(){
  ios::sync_with_stdio( false );
  cin.tie( nullptr );
#ifdef LOCAL
  freopen("in", "r" , stdin);
#endif

  int n, m, t;cin >>t;
  while(t--){
    cin >> n >> m;
    vector< vi > G(n);
    map< int, int > deg;
    int to ,from;
    int md =-1, bn =-1;

    rep( i, 0, m){
      cin >> to >> from; to--; from--;
      G[ from ].PB( to );
      G[ to ].PB( from );
      deg[from]++; deg[to]++;
      if( deg[from] > md) {
          md = deg[from];
          bn = from;
      }
      if( deg[to] > md) {
          md = deg[to];
          bn = to;
      }
    }

    bfs( bn , G, n);

  }

  return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define debug1( x ) cout << #x << " = " <<  x << endl;
#define debug2( x, y) cout <<#x << " = " << x << " , " <<#y << " = " << y <<endl;
#define F first
#define S second
#define PB push_back
#define size( x )   int( ( x ).size( ) )
#define endl '\n'
#define rep(i, a, b) for( __typeof(a) i =(a); i<(b);i++)
#define rept(i, a, b) for( __typeof(a) i =(a); i<=(b);i++)
#define all(x) x.begin(),x.end()

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

void bfs( int st, vector<vi> &G, int n){
  vector< int > ans, ans2;
  queue< int > q;
  q.push( st );
  vector<int> dist( n);
  vector<bool > vis(n, false);
  dist[st] = 0;
  vis[st] = true;
  while( !q.empty()){
    int t = q.front(); q.pop();
    if( dist[t]%2 ==0 ){
      ans.push_back( t+1 );
    }else{
      ans2.push_back( t+1);
    }
    for( int son: G[t]){
      dist[son] = dist[t] +1 ;
      if( !vis[son]){
        vis[son]  = true;
        q.push( son);
      }
    }
  }
  if( size(ans) < size(ans2)){
    cout << size(ans) <<endl;
    for( int x: ans) cout << x<< " "; cout <<endl;
  }else{
    cout << size(ans2) <<endl;
    for( int x: ans2) cout << x<< " "; cout <<endl;
  }

}

int main(){
  ios::sync_with_stdio( false );
  cin.tie( nullptr );
#ifdef LOCAL
  freopen("in", "r" , stdin);
#endif

  int n, m, t;cin >>t;
  while(t--){
    cin >> n >> m;
    vector< vi > G(n);
    map< int, int > deg;
    int to ,from;
    int md =-1, bn =-1;

    rep( i, 0, m){
      cin >> to >> from; to--; from--;
      G[ from ].PB( to );
      G[ to ].PB( from );
      deg[from]++; deg[to]++;
      if( deg[from] > md) {
          md = deg[from];
          bn = from;
      }
      if( deg[to] > md) {
          md = deg[to];
          bn = to;
      }
    }

    bfs( bn , G, n);

  }

  return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define debug1( x ) cout << #x << " = " <<  x << endl;
#define debug2( x, y) cout <<#x << " = " << x << " , " <<#y << " = " << y <<endl;
#define F first
#define S second
#define PB push_back
#define size( x )   int( ( x ).size( ) )
#define endl '\n'
#define rep(i, a, b) for( __typeof(a) i =(a); i<(b);i++)
#define rept(i, a, b) for( __typeof(a) i =(a); i<=(b);i++)
#define all(x) x.begin(),x.end()

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

void bfs( int st, vector<vi> &G, int n){
  vector< int > ans;
  queue< int > q;
  q.push( st );
  vector<int> dist( n);
  vector<bool > vis(n, false);
  dist[st] = 0;
  vis[st] = true;
  while( !q.empty()){
    int t = q.front(); q.pop();
    if( dist[t]%2 ==0 ){
      ans.push_back( t+1 );
    }
    for( int son: G[t]){
      dist[son] = dist[st]++;
      if( !vis[son]){
        vis[son]  = true;
        q.push( son);
      }
    }
  }
  cout << size(ans) <<endl;
  for( int x: ans) cout << x<< " "; cout <<endl;
}

int main(){
  ios::sync_with_stdio( false );
  cin.tie( nullptr );
#ifdef LOCAL
  freopen("in", "r" , stdin);
#endif

  int n, m, t;cin >>t;
  while(t--){
    cin >> n >> m;
    vector< vi > G(n);
    map< int, int > deg;
    int to ,from;
    int md =-1, bn =-1;

    rep( i, 0, m){
      cin >> to >> from; to--; from--;
      G[ from ].PB( to );
      G[ to ].PB( from );
      deg[from]++; deg[to]++;
      if( deg[from] > md) {
          md = deg[from];
          bn = from;
      }
      if( deg[to] > md) {
          md = deg[to];
          bn = to;
      }
    }

    bfs( bn , G, n);

  }

  return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define debug1( x ) cout << #x << " = " <<  x << endl;
#define debug2( x, y) cout <<#x << " = " << x << " , " <<#y << " = " << y <<endl;
#define F first
#define S second
#define PB push_back
#define size( x )   int( ( x ).size( ) )
#define endl '\n'
#define rep(i, a, b) for( __typeof(a) i =(a); i<(b);i++)
#define rept(i, a, b) for( __typeof(a) i =(a); i<=(b);i++)
#define all(x) x.begin(),x.end()

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

int arr[6] = {4, 8,15,16,23,42};

int main(){
 ios::sync_with_stdio( false );
 cin.tie( nullptr );
#ifdef LOCAL
  freopen("in", "r" , stdin);
#endif

ll n;
while( cin >>n){
  vi A(n);
  map<int, vi > cnt;
  map< int, int > c;

  rep( i, 0, n) {
    cin >>A[i];
    cnt[A[i]].PB(i);
    c[A[i]]++;
  }
  int ans = n;
  int mn = INT_MAX;
  rep(i, 0, 6){
    mn = min( mn, c[arr[i]]);
  }
  int j=0, k=0, l=0, m=0, n=0,o=0;
  rep( i,0, mn){
    while( j < size( cnt[8]) && cnt[4][j] > cnt[8][l] )l++;
    while( m < size( cnt[15]) &&  cnt[8][l] > cnt[15][m] )m++;
    while( n < size( cnt[23]) && cnt[15][m] > cnt[23][n] )n++;
    while( o < size( cnt[42]) && cnt[23][n] > cnt[42][o] )o++;
    l++, m++, n++, o++;
    ans -= 6;
  }
  cout << ans <<endl;

}

}


#include <bits/stdc++.h>
#define endl '\n'
#define debug1( x ) cout << #x << " = " <<  x << endl;
#define debug2( x, y) cout <<#x << " = " << x << " , " <<#y << " = " << y <<endl;
#define F first
#define S second
#define PB push_back
#define size( x )   int( ( x ).size( ) )
#define endl '\n'
#define rep(i, a, b) for( __typeof(a) i =(a); i<(b);i++)
#define rept(i, a, b) for( __typeof(a) i =(a); i<=(b);i++)
#define all(x) x.begin(),x.end()

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

void bfs( int st, vector<vi> &G, int n){
  vector< int > ans, ans2;
  queue< int > q;
  q.push( st );
  vector<int> dist( n);
  vector<bool > vis(n, false);
  dist[st] = 0;
  vis[st] = true;
  while( !q.empty()){
    int t = q.front(); q.pop();
    if( dist[t]%2 ==0 ){
      ans.push_back( t+1 );
    }else{
      ans2.push_back( t+1);
    }
    for( int son: G[t]){
      dist[son] = dist[st] +1 ;
      if( !vis[son]){
        vis[son]  = true;
        q.push( son);
      }
    }
  }
  if( size(ans) < size(ans2)){
    cout << size(ans) <<endl;
    for( int x: ans) cout << x<< " "; cout <<endl;
  }else{
    cout << size(ans2) <<endl;
    for( int x: ans2) cout << x<< " "; cout <<endl;
  }

}

int main(){
  ios::sync_with_stdio( false );
  cin.tie( nullptr );
#ifdef LOCAL
  freopen("in", "r" , stdin);
#endif

  int n, m, t;cin >>t;
  while(t--){
    cin >> n >> m;
    vector< vi > G(n);
    map< int, int > deg;
    int to ,from;
    int md =-1, bn =-1;

    rep( i, 0, m){
      cin >> to >> from; to--; from--;
      G[ from ].PB( to );
      G[ to ].PB( from );
      deg[from]++; deg[to]++;
      if( deg[from] > md) {
          md = deg[from];
          bn = from;
      }
      if( deg[to] > md) {
          md = deg[to];
          bn = to;
      }
    }

    bfs( bn , G, n);

  }

  return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define debug1( x ) cout << #x << " = " <<  x << endl;
#define debug2( x, y) cout <<#x << " = " << x << " , " <<#y << " = " << y <<endl;
#define F first
#define S second
#define PB push_back
#define size( x )   int( ( x ).size( ) )
#define endl '\n'
#define rep(i, a, b) for( __typeof(a) i =(a); i<(b);i++)
#define rept(i, a, b) for( __typeof(a) i =(a); i<=(b);i++)
#define all(x) x.begin(),x.end()

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

int main(){
  ios::sync_with_stdio( false );
  cin.tie( nullptr );
#ifdef LOCAL
  freopen("in", "r" , stdin);
#endif

  int n, m, t;cin >>t;
  while(t--){
     cin >> n >> m;
    vector< vi > G(n);
    int to ,from;
    rep( i, 0, m){
      cin >> to >> from; to--; from--;
      G[ from ].PB( to );
      G[ to ].PB( from );
    }
    int ans =0;
    vector< bool > vis(n, false);
    vi ansv;
    rep( i, 0, n){
      if( vis [ i] ) continue;
      vis[i] = true; ans++;
      rep( j , 0, size(G[i])) vis[G[i][j]] = true;
      ansv.PB( i+1);
    }
    cout << ans << endl;
    for( int x: ansv) cout << x << " "; cout <<endl;
  }

  return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define debug1( x ) cout << #x << " = " <<  x << endl;
#define debug2( x, y) cout <<#x << " = " << x << " , " <<#y << " = " << y <<endl;
#define F first
#define S second
#define PB push_back
#define size( x )   int( ( x ).size( ) )
#define endl '\n'
#define rep(i, a, b) for( __typeof(a) i =(a); i<(b);i++)
#define rept(i, a, b) for( __typeof(a) i =(a); i<=(b);i++)
#define all(x) x.begin(),x.end()

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

int main(){
  ios::sync_with_stdio( false );
  cin.tie( nullptr );
#ifdef LOCAL
  freopen("in", "r" , stdin);
#endif

  int n, m, t;cin >>t;
  while(t--){
    cin >> n >> m;
    vector< vi > G(n);
    int to ,from;

    rep( i, 0, m){
      cin >> to >> from; to--; from--;
      G[ from ].PB( to );
      G[ to ].PB( from );
    }
    priority_queue < pair<int, int> > p, q;
    rep( i, 0, n){
      p.push({size(G[i]), i});
    }
    vector< bool > vis(n, false);
    set<ll> ansv;

    while( !p.empty()){
      ii x = p.top(); p.pop();
      if( vis [ x.S] ) {
        q.push(x);continue;
      }
      vis[x.S] = true;
      rep( j , 0, size(G[x.S])) vis[G[x.S][j]] = true;
      ansv.insert( x.S+1 );
    }

    cout << size(ansv) << endl;
    for( int x: ansv) cout << x << " "; cout <<endl;
  }

  return 0;
}


#include <bits/stdc++.h>
#define N 200000 // 2 * 10^5

using namespace std;

int n, m;

queue<int> todo;
vector<int> edges [N + 1];
bool adjacent [N + 1];
bool seen [N + 1]; // add every vertex to the queue only once

vector<int> result;

void read_input(){
	cin >> n >> m;

	int u, v;
	for(int i = 0; i < m; i++){
		cin >> u >> v;
		edges[u].push_back(v);
		edges[v].push_back(u);
	}
}

void un_mark_adjacent (int i){
	for(int v : edges[i]){

		// mark as adjacent
		adjacent[v] = true;

		// already seen this vertex
		if(seen[v]) continue;
		seen[v] = true;

		// put vertex in the queue
		todo.push(v);
	}
}

void push_adjacent(int i){
	for(int v : edges[i]){

		// already seen this vertex
		if(seen[v]) continue;
		seen[v] = true;

		// put vertex in the queue
		todo.push(v);
	}
}

void never_mark_leaves(){
	for(int i = 0; i < n; i++){

		// vertex i is a leaf
		if(edges[i].size() == 1 && !seen[i]){

			// never mark leaves (unless there are only leaves)
			seen[i] = true;
			push_adjacent(i);
		}
	}
}

void add_best_vertex_if_todo_is_empty() {

	// only execute if todo is empty
	if(! todo.empty()) return;

	// mark the vertex with the most edges
	int max_vertex = 0;
	for(int i = 0; i < n; i++){
		if(edges[max_vertex].size() < edges[i].size()) max_vertex = i;
	}

	// push max_vertex in the queue
	seen[max_vertex] = true;
	todo.push(max_vertex);
}

void solve(){
	while(!todo.empty()){

		// get next vertex
		int v = todo.front();
		todo.pop();
		//cout << "adjacent[" << v << "]: " << adjacent[v] << endl;

		// vertex is adjacent to marked vertex
		if(adjacent[v]) {

			// push all adjacent vertexes of v
			push_adjacent(v);
		}

		// vertex is NOT adjacent to marked vertex
		else {

			// mark v
			result.push_back(v);

			// do not mark any adjacent vertexes
			un_mark_adjacent(v);
		}
	}
}

void print_result() {

	cout << result.size() << endl;

	for(int i : result) {
		cout << i << " ";
	}
	cout << endl;
}

void clear_structures() {

	result.clear();

	for(int i = 1; i <= n; i++){
		edges[i].clear();
		adjacent[i] = false;
		seen[i] = false;
	}
}

int main(){
	ios::sync_with_stdio(false); cin.tie(NULL);
	int t;
	cin >> t;

	while(t--) {

		read_input();

		never_mark_leaves();

		add_best_vertex_if_todo_is_empty();

		solve();

		print_result();

		clear_structures();
	}

	return 0;
}


#include <bits/stdc++.h>
#define N 200000
#define INF 0x3f3f3f3f // 0x3f3f3f3f3f3f3f3fll

using namespace std;

struct node {
	int index, num_edges;
};

int n, m; // # vertexes # edges

vector<int> edges [N + 1];
int num_edges [N + 1];
vector<int> result;

auto comp = [] (node n1, node n2){ return n1.num_edges < n2.num_edges; };
priority_queue<node, vector<node>, decltype(comp) > todo (comp);

void read_input(){
	cin >> n >> m;

	int u, v;
	for(int i = 1; i <= m; i++){
		cin >> u >> v;
		edges[u].push_back(v);
		edges[v].push_back(u);
	}

	num_edges[u] = edges[u].size();
	num_edges[v] = edges[v].size();
}

void push_nodes_to_queue() {

	for(int i = 1; i <= n; i++){
		todo.push({i, (int) edges[i].size()});
	}
}

void mark_nodes(){

	int i, num;
	while(! todo.empty()) {

		// get node
		i = todo.top().index;
		num = todo.top().num_edges;
		todo.pop();
		cout << "i: " << i << " num: " << num << endl;

		// nothing to do
		if(num <= 0) continue;

		// check if outdated
		if(num != num_edges[i]) {
			todo.push({i, num_edges[i]});
			continue;
		}

		//mark node
		result.push_back(i);
		num_edges[i] = 0;

		// remove this vertex from all adjacent vertexes
		for(int v : edges[i]){
			num_edges[v]--;

			// remove all adjacent vertexes from their neighbours
			for(int nei : edges[v]) {
				num_edges[nei]--;
			}
		}

	}
}

void print_result(){
	cout << result.size() << endl;
	for(int x : result) {
		cout << x << " ";
	}
	cout << endl;
}

void clear_structures(){

	for(int i = 1; i <= n; i++) {
		edges[i].clear();
		num_edges[i] = 0;
	}

	result.clear();

	// the priority queue will always be empty now
}

int main(){
	ios::sync_with_stdio(false); cin.tie(NULL);

	int t;
	cin >> t;

	while(t--) {

		read_input();

		push_nodes_to_queue();

		cout << "todo.size(): " << todo.size() << endl;

		mark_nodes();

		print_result();

		clear_structures();
	}

	return 0;
}


#include <bits/stdc++.h>
#define N 200000
#define INF 0x3f3f3f3f // 0x3f3f3f3f3f3f3f3fll

using namespace std;

int n, m;

vector<int> edges[N + 1];
bool paint [N + 1];
bool seen[N + 1];
queue<pair<int, bool>> todo;

void read_input() {

	scanf("%d%d", &n, &m);

	int u, v;
	for(int i = 1; i <= m; i++) {
		scanf("%d%d", &u, &v);
		edges[u].push_back(v);
		edges[v].push_back(u);
		//printf("edges[%d].push_back(%d)\n", u, v);
		//printf("edges[%d].push_back(%d)\n", v, u);
	}
}

void enqueue(int i, bool p) {
	if(!seen[i]) {
		seen[i] = true;
		todo.push({i, p});
		//printf("enqueue %d (%d)\n", i, p);
	}
}

int paint_vertexes() {

	enqueue(1, true);

	int cur, painted = 0;
	bool p;
	while(!todo.empty()) {

		// get next vertex
		cur = todo.front().first;
		p = todo.front().second;
		todo.pop();

		paint[cur] = p;
		if(p) painted++;

		//printf("cur: %d p: %d\n", cur, p);

		// check adjacent vertexes
		//printf("edges[%d].size(): %d\n", cur, (int) edges[cur].size());
		for(int adj : edges[cur]) {
			enqueue(adj, !p);
		}
	}

	return painted;
}

void print_result(int num_painted, bool painted) {
	printf("%d\n", num_painted);

	for(int i = 1; i <= n; i++) {
		if(paint[i] == painted) printf("%d ", i);
	}
	printf("\n");
}

void clear_structures() {

	for(int i = 1; i <= n; i++) {
		edges[i].clear();
		paint[i] = false;
		seen[i] = false;
	}
}

int main(){

	int t;
	scanf("%d", &t);

	while(t--){

		read_input();

		int painted = paint_vertexes();

		print_result(min(painted, n - painted), painted * 2 <= n);

		clear_structures();
	}

	return 0;
}


#include <bits/stdc++.h>
#define N 200000

using namespace std;

vector<int> res;
bool seen[N + 1];
vector<int> edges [N + 1];

void bfs(int vertex) {

	// choose this vertex
	if(!seen[vertex]) {

		// mark vertex as seen
		seen[vertex] = true;
		res.push_back(vertex);

		// mark all adjacent vertexes as seen
		for(int i : edges[vertex]) {
			seen[i] = true;
		}

		// bfs for all adjacent vertexes
		for(int i : edges[vertex]) {
			bfs(i);
		}

	}

	// vertex is adjacent to a chosen vertex
	else {

		// only run bfs for not seen vertices
		for(int i : edges[vertex]) {
			if(!seen[i]) bfs(i);
		}
	}
}

int main(){

	int t, n, m, u, v; // queries, vertices, edges
	cin >> t;
	while(t--) {

		// clear data structures
		res.clear();
		for(int i = 0; i < N + 1; i++) {
			seen[i] = false;
			edges[i].clear();
		}

		// read input
		cin >> n >> m;
		while(m--) {
			cin >> u >> v;
			edges[u].push_back(v);
			edges[v].push_back(u);
		}

		// start with the vertex that has the most edges
		int max_edges = 0, max_vertex = v;
		for(int i = 0; i < n; i++) {
			if(max_edges < edges[i].size()) {
				max_edges = edges[i].size();
				max_vertex = i;
			}
		}

		// select vertices
		bfs(max_vertex);

		// cout result
		cout << res.size() << endl;
		for(int i : res) cout << i << " ";
		cout << endl;
	}

	return 0;
}


#include <bits/stdc++.h>
#define N 200000

using namespace std;

vector<int> edges [N];
bool is_in_queue[N];
bool adjacent[N];
queue<int> todo;
vector<int> result;

void push(int x) {

	if(is_in_queue[x]) return;

	todo.push(x);
	is_in_queue[x] = true;
}

int main(){

	int t, n, m, u, v;
	cin >> t;
	while(t--) {

		//clear structures (todo will be emtpty)
		memset(edges, false, sizeof(edges));
		memset(is_in_queue, false, sizeof(is_in_queue));
		memset(adjacent, false, sizeof(adjacent));
		result.clear();

		// read n & m
		cin >> n >> m;

		// read edges
		for(int i = 0; i < m; i++) {
			cin >> u >> v;
			edges[u].push_back(v);
			edges[v].push_back(u);
		}

		// get the vertex with the most edges
		int i_max = 0;
		for(int i = 0; i < n; i++) {

			if(edges[i_max].size() < edges[i].size()) {
				i_max = i;
			}
		}

		// set up for search
		int cur;
		todo.push(i_max);
		is_in_queue[i_max] = true;

		while(!todo.empty()) {

			// get next vertex
			cur = todo.front();
			todo.pop();

			// current vertex is NOT adjacent to marked vertex
			if(! adjacent[cur]) {
				result.push_back(cur);

				for(int adj : edges[cur]) {

					adjacent[adj] = true;

					if(! is_in_queue[adj]) push(adj);
				}
			}

			// current vertex is adjacent to marked vertex
			else {
				for(int adj: edges[cur]) {

					if(! is_in_queue[adj]) push(adj);
				}
			}
		}

		//print answer
		cout << result.size() << endl;
		for(int r : result) cout << r << " ";
		cout << endl;
	}
}


#include <bits/stdc++.h>
#define N 200000

using namespace std;

vector<int> res;
bool seen[N + 1];
vector<int> edges [N + 1];

void bfs(int vertex) {

	// choose this vertex
	if(!seen[vertex]) {

		// mark vertex as seen
		seen[vertex] = true;
		res.push_back(vertex);

		// mark all adjacent vertexes as seen
		for(int i : edges[vertex]) {
			seen[i] = true;
		}

		// bfs for all adjacent vertexes
		for(int i : edges[vertex]) {
			bfs(i);
		}

	}

	// vertex is adjacent to a chosen vertex
	else {

		// only run bfs for not seen vertices
		for(int i : edges[vertex]) {
			if(!seen[i]) bfs(i);
		}
	}
}

int main(){

	int t, n, m, u, v; // queries, vertices, edges
	scanf("%d", &t);
	while(t--) {

		// clear data structures
		res.clear();
		for(int i = 0; i < n + 1; i++) {
			seen[i] = false;
			edges[i].clear();
		}

		// read input
		scanf("%d %d", &n, &m);
		while(m--) {
			scanf("%d %d", &u, &v);
			edges[u].push_back(v);
			edges[v].push_back(u);
		}

		// start with the vertex that has the most edges
		int max_edges = 0, max_vertex = v;
		for(int i = 0; i < n; i++) {
			if(max_edges < edges[i].size()) {
				max_edges = edges[i].size();
				max_vertex = i;
			}
		}

		// select vertices
		bfs(max_vertex);

		// print result
		printf("%d\n", (int) res.size());
		for(int i : res) printf("%d ", i);
		cout << endl;
	}

	return 0;
}


#include <bits/stdc++.h>
#define N 200000

using namespace std;

vector<int> res;
bool seen[N + 1];
vector<int> edges [N + 1];

void bfs(int vertex) {

	// choose this vertex
	if(!seen[vertex]) {

		// mark vertex as seen
		seen[vertex] = true;
		res.push_back(vertex);

		// mark all adjacent vertexes as seen
		for(int i : edges[vertex]) {
			seen[i] = true;
		}

		// bfs for all adjacent vertexes
		for(int i : edges[vertex]) {
			bfs(i);
		}

	}

	// vertex is adjacent to a chosen vertex
	else {

		// only run bfs for not seen vertices
		for(int i : edges[vertex]) {
			if(!seen[i]) bfs(i);
		}
	}
}

int main(){

	int t, n, m, u, v; // queries, vertices, edges
	scanf("%d", &t);
	while(t--) {

		// clear data structures
		res.clear();
		for(int i = 0; i < N + 1; i++) {
			seen[i] = false;
			edges[i].clear();
		}

		// read input
		scanf("%d %d", &n, &m);
		while(m--) {
			scanf("%d %d", &u, &v);
			edges[u].push_back(v);
			edges[v].push_back(u);
		}

		// start with the vertex that has the most edges
		int max_edges = 0, max_vertex = v;
		for(int i = 0; i < n; i++) {
			if(max_edges < edges[i].size()) {
				max_edges = edges[i].size();
				max_vertex = i;
			}
		}

		// select vertices
		bfs(max_vertex);

		// print result
		printf("%d\n", (int) res.size());
		for(int i : res) printf("%d ", i);
		cout << endl;
	}

	return 0;
}


#include <bits/stdc++.h>
#define N 200000

using namespace std;

vector<int> res;
bool seen[N + 1];
vector<int> edges [N + 1];

void bfs(int vertex) {

	// choose this vertex
	if(!seen[vertex]) {

		// mark vertex as seen
		seen[vertex] = true;
		res.push_back(vertex);

		// mark all adjacent vertexes as seen
		for(int i : edges[vertex]) {
			seen[i] = true;
		}

		// bfs for all adjacent vertexes
		for(int i : edges[vertex]) {
			bfs(i);
		}

	}

	// vertex is adjacent to a chosen vertex
	else {

		// only run bfs for not seen vertices
		for(int i : edges[vertex]) {
			if(!seen[i]) bfs(i);
		}
	}
}

int main(){

	int t, n, m, u, v; // queries, vertices, edges
	scanf("%d", &t);
	while(t--) {

		// read input
		scanf("%d %d", &n, &m);

		// read input
		int v_min = INT_MAX, v_max = 0;
		while(m--) {
			scanf("%d %d", &u, &v);
			edges[u].push_back(v);
			edges[v].push_back(u);

			v_min = min(v_min, v);
			v_min = min(v_min, u);
			v_max = max(v_max, v);
			v_max = max(v_max, u);
		}

		// start with the vertex that has the most edges
		int max_edges = 0, max_vertex = v;
		for(int i = 1; i < n; i++) {
			if(max_edges < edges[i].size()) {
				max_edges = edges[i].size();
				max_vertex = i;
			}
		}

		// select vertices
		bfs(max_vertex);

		// print result
		printf("%d\n", (int) res.size());
		for(int i : res) printf("%d ", i);
		cout << endl;

		// clear data structures
		res.clear();
		for(int i = v_min; i <= v_max; i++) {
			seen[i] = false;
			edges[i].clear();
		}
	}

	return 0;
}


#include <bits/stdc++.h>
#define N 200000
#define INF 0x3f3f3f3f // 0x3f3f3f3f3f3f3f3fll

using namespace std;

struct node {
	int index, num_edges;
};

int n, m; // # vertexes # edges

vector<int> edges [N + 1];
int num_edges [N + 1];
vector<int> result;

auto comp = [] (node n1, node n2){ return n1.num_edges < n2.num_edges; };
priority_queue<node, vector<node>, decltype(comp) > todo (comp);

void read_input(){
	cin >> n >> m;

	// read input
	int u, v;
	for(int i = 1; i <= m; i++){
		cin >> u >> v;
		edges[u].push_back(v);
		edges[v].push_back(u);
	}

	// set num_edges
	for(int i = 0; i < n; i++) {
		num_edges[i] = edges[i].size();
	}
}

void push_nodes_to_queue() {

	for(int i = 1; i <= n; i++){
		todo.push({i, (int) edges[i].size()});
	}
}

void mark_nodes(){

	int i, num;
	while(! todo.empty()) {

		// get node
		i = todo.top().index;
		num = todo.top().num_edges;
		todo.pop();
		// << "i: " << i << " num: " << num << endl;

		// nothing to do
		if(num <= 0) continue;

		// check if outdated
		if(num != num_edges[i]) {
			todo.push({i, num_edges[i]});
			continue;
		}

		//mark node
		result.push_back(i);
		num_edges[i] = 0;

		// remove this vertex from all adjacent vertexes
		for(int v : edges[i]){
			num_edges[v]--;

			// remove all adjacent vertexes from their neighbours
			for(int nei : edges[v]) {
				num_edges[nei]--;
			}
		}
/*
		cout << "number of edges: " << endl;
		for(int x = 0; x < n; x++){
			cout << x << ": " << num_edges[x] << endl;
		}*/

	}
}

void print_result(){
	cout << result.size() << endl;
	for(int x : result) {
		cout << x << " ";
	}
	cout << endl;
}

void clear_structures(){

	for(int i = 1; i <= n; i++) {
		edges[i].clear();
		num_edges[i] = 0;
	}

	result.clear();

	// the priority queue will always be empty now
}

int main(){
	ios::sync_with_stdio(false); cin.tie(NULL);

	int t;
	cin >> t;

	while(t--) {

		read_input();

		push_nodes_to_queue();

		//cout << "todo.size(): " << todo.size() << endl;
		/*cout << "number of edges: " << endl;
		for(int x = 0; x < n; x++){
			cout << x << ": " << num_edges[x] << endl;
		}*/

		mark_nodes();

		print_result();

		clear_structures();
	}

	return 0;
}


#include <bits/stdc++.h>
#define N 200000
#define INF 0x3f3f3f3f // 0x3f3f3f3f3f3f3f3fll

using namespace std;

struct node {
	int index, num_edges;
};

int n, m; // # vertexes # edges

vector<int> edges [N + 1];
int num_edges [N + 1];
bool done [N + 1];
vector<int> result;

auto comp = [] (node n1, node n2){ return n1.num_edges < n2.num_edges; };
priority_queue<node, vector<node>, decltype(comp) > todo (comp);

void read_input(){
	cin >> n >> m;

	// read input
	int u, v;
	for(int i = 1; i <= m; i++){
		cin >> u >> v;
		edges[u].push_back(v);
		edges[v].push_back(u);
	}

	// set num_edges
	for(int i = 0; i < n; i++) {
		num_edges[i] = edges[i].size();
	}
}

void push_nodes_to_queue() {

	for(int i = 1; i <= n; i++){
		todo.push({i, (int) edges[i].size()});
	}
}

void mark_nodes(){

	int i, num;
	while(! todo.empty()) {

		// get node
		i = todo.top().index;
		num = todo.top().num_edges;
		todo.pop();
		// << "i: " << i << " num: " << num << endl;

		// nothing to do
		if(num <= 0) {
			if(!done[i]) {
				result.push_back(i);
			}
			continue;
		}

		// check if outdated
		if(num != num_edges[i]) {
			todo.push({i, num_edges[i]});
			continue;
		}

		//mark node
		result.push_back(i);
		done[i] = true;
		num_edges[i] = 0;

		// remove this vertex from all adjacent vertexes
		for(int v : edges[i]){
			num_edges[v]--;
			done[v] = true;

			// remove all adjacent vertexes from their neighbours
			for(int nei : edges[v]) {
				num_edges[nei]--;
			}
		}
/*
		cout << "number of edges: " << endl;
		for(int x = 0; x < n; x++){
			cout << x << ": " << num_edges[x] << endl;
		}*/

	}
}

void print_result(){
	cout << result.size() << endl;
	for(int x : result) {
		cout << x << " ";
	}
	cout << endl;
}

void clear_structures(){

	for(int i = 1; i <= n; i++) {
		edges[i].clear();
		num_edges[i] = 0;
		done[i] = false;
	}

	result.clear();

	// the priority queue will always be empty now
}

int main(){
	ios::sync_with_stdio(false); cin.tie(NULL);

	int t;
	cin >> t;

	while(t--) {

		read_input();

		push_nodes_to_queue();

		//cout << "todo.size(): " << todo.size() << endl;
		/*cout << "number of edges: " << endl;
		for(int x = 0; x < n; x++){
			cout << x << ": " << num_edges[x] << endl;
		}*/

		mark_nodes();

		print_result();

		clear_structures();
	}

	return 0;
}


#include <bits/stdc++.h>
#define N 200000

using namespace std;

vector<int> res;
bool seen[N + 1];
vector<int> edges [N + 1];

void bfs(int vertex) {

	// choose this vertex
	if(!seen[vertex]) {

		// mark vertex as seen
		seen[vertex] = true;
		res.push_back(vertex);

		// mark all adjacent vertexes as seen
		for(int i : edges[vertex]) {
			seen[i] = true;
		}

		// bfs for all adjacent vertexes
		for(int i : edges[vertex]) {
			bfs(i);
		}

	}

	// vertex is adjacent to a chosen vertex
	else {

		// only run bfs for not seen vertices
		for(int i : edges[vertex]) {
			if(!seen[i]) bfs(i);
		}
	}
}

int main(){

	int t, n, m, u, v; // queries, vertices, edges
	scanf("%d", &t);
	while(t--) {

		// clear data structures
		res.clear();
		for(int i = 0; i < N + 1; i++) {
			seen[i] = false;
			edges[i].clear();
		}

		// read input
		scanf("%d %d", &n, &m);
		while(m--) {
			scanf("%d %d", &u, &v);
			edges[u].push_back(v);
			edges[v].push_back(u);
		}

		if(n < 2) {
			printf("1 1\n");
			continue;
		}

		// start with the vertex that has the most edges
		int max_edges = 0, max_vertex = v;
		for(int i = 0; i < n; i++) {
			if(max_edges < edges[i].size()) {
				max_edges = edges[i].size();
				max_vertex = i;
			}
		}

		// select vertices
		bfs(max_vertex);

		// print result
		printf("%d\n", (int) res.size());
		for(int i : res) printf("%d ", i);
		cout << endl;
	}

	return 0;
}


#include <bits/stdc++.h>
#define N 200000 // 2 * 10^5

using namespace std;

int n, m;

queue<int> todo;
vector<int> edges [N + 1];
bool adjacent [N + 1];
bool seen [N + 1]; // add every vertex to the queue only once

vector<int> vertexes;
vector<int> result;

void read_input(){
	cin >> n >> m;

	int u, v;
	for(int i = 0; i < m; i++){
		cin >> u >> v;
		edges[u].push_back(v);
		edges[v].push_back(u);
	}
}

void un_mark_adjacent (int i){
	for(int v : edges[i]){

		// mark as adjacent
		adjacent[v] = true;
	}
}

void sort_and_add_vertexes() {

	// add all vertexes
	for(int i = 1; i <= n; i++){
		vertexes.push_back(i);
	}

	// sort them by the number of edges
	sort(vertexes.begin(), vertexes.end(), [] (int v1, int v2) {
		return edges[v1].size() > edges[v2].size();
	});

	// add all vertexes to the queue
	for(int v : vertexes) todo.push(v);
}

void solve(){
	while(!todo.empty()){

		// get next vertex
		int v = todo.front();
		todo.pop();

		// vertex is NOT adjacent to marked vertex
		if(! adjacent[v]) {

			// mark v
			result.push_back(v);

			// do not mark any adjacent vertexes
			un_mark_adjacent(v);
		}
	}
}

void print_result() {

	cout << result.size() << endl;

	for(int i : result) {
		cout << i << " ";
	}
	cout << endl;
}

void clear_structures() {

	result.clear();
	vertexes.clear();

	for(int i = 1; i <= n; i++){
		edges[i].clear();
		adjacent[i] = false;
		seen[i] = false;
	}
}

int main(){
	ios::sync_with_stdio(false); cin.tie(NULL);
	int t;
	cin >> t;

	while(t--) {

		read_input();

		sort_and_add_vertexes();

		solve();

		print_result();

		clear_structures();
	}

	return 0;
}


#include <bits/stdc++.h>
#define N 200000

using namespace std;

vector<int> res;
bool seen[N + 1];
vector<int> edges [N + 1];

void bfs(int vertex) {

	// choose this vertex
	if(!seen[vertex]) {

		// mark vertex as seen
		seen[vertex] = true;
		res.push_back(vertex);

		// mark all adjacent vertexes as seen
		for(int i : edges[vertex]) {
			seen[i] = true;
		}

		// bfs for all adjacent vertexes
		for(int i : edges[vertex]) {
			bfs(i);
		}

	}

	// vertex is adjacent to a chosen vertex
	else {

		// only run bfs for not seen vertices
		for(int i : edges[vertex]) {
			if(!seen[i]) bfs(i);
		}
	}
}

int main(){

	int t, n, m, u, v; // queries, vertices, edges
	scanf("%d", &t);
	while(t--) {

		// read input
		scanf("%d %d", &n, &m);

		// clear data structures
		res.clear();
		for(int i = 1; i < n + 1; i++) {
			seen[i] = false;
			edges[i].clear();
		}

		// read input
		while(m--) {
			scanf("%d %d", &u, &v);
			edges[u].push_back(v);
			edges[v].push_back(u);
		}

		// colour any vertex
		if(n < 3) {
			printf("1 %d", v);
			continue;
		}

		// start with the vertex that has the most edges
		int max_edges = 0, max_vertex = v;
		for(int i = 1; i < n; i++) {
			if(max_edges < edges[i].size()) {
				max_edges = edges[i].size();
				max_vertex = i;
			}
		}

		// select vertices
		bfs(max_vertex);

		// print result
		printf("%d\n", (int) res.size());
		for(int i : res) printf("%d ", i);
		cout << endl;
	}

	return 0;
}


#include <bits/stdc++.h>
#define N 200000

using namespace std;

vector<int> res;
map<int, bool> seen;
map<int, vector<int>> edges;

void bfs(int vertex) {

	// choose this vertex
	if(!seen[vertex]) {

		// mark vertex as seen
		seen[vertex] = true;
		res.push_back(vertex);

		// mark all adjacent vertexes as seen
		for(int i : edges[vertex]) {
			seen[i] = true;
		}

		// bfs for all adjacent vertexes
		for(int i : edges[vertex]) {
			bfs(i);
		}

	}

	// vertex is adjacent to a chosen vertex
	else {

		// only run bfs for not seen vertices
		for(int i : edges[vertex]) {
			if(!seen[i]) bfs(i);
		}
	}
}

int main(){

	int t, n, m, u, v; // queries, vertices, edges
	scanf("%d", &t);
	while(t--) {

		// clear data structures
		res.clear();
		seen.clear();
		edges.clear();

		// read input
		scanf("%d %d", &n, &m);
		while(m--) {
			scanf("%d %d", &u, &v);
			edges[u].push_back(v);
			edges[v].push_back(u);
		}

		// start with the vertex that has the most edges
		int max_edges = 0, max_vertex = v;
		for(int i = 1; i < n; i++) {
			if(max_edges < edges[i].size()) {
				max_edges = edges[i].size();
				max_vertex = i;
			}
		}

		if(n < 4) {
			printf("1 %d", max_vertex);
			continue;
		}

		// select vertices
		bfs(max_vertex);

		// print result
		printf("%d\n", (int) res.size());
		for(int i : res) printf("%d ", i);
		cout << endl;
	}

	return 0;
}


#include <bits/stdc++.h>
#define N 200000

using namespace std;

vector<int> res;
bool seen[N + 1];
vector<int> edges [N + 1];

void bfs(int vertex) {

	// choose this vertex
	if(!seen[vertex]) {

		// mark vertex as seen
		seen[vertex] = true;
		res.push_back(vertex);

		// mark all adjacent vertexes as seen
		for(int i : edges[vertex]) {
			seen[i] = true;
		}

		// bfs for all adjacent vertexes
		for(int i : edges[vertex]) {
			bfs(i);
		}

	}

	// vertex is adjacent to a chosen vertex
	else {

		// only run bfs for not seen vertices
		for(int i : edges[vertex]) {
			if(!seen[i]) bfs(i);
		}
	}
}

int main(){

	int t, n, m, u, v; // queries, vertices, edges
	scanf("%d", &t);
	while(t--) {

		// read input
		scanf("%d %d", &n, &m);

		// clear data structures
		res.clear();
		for(int i = 0; i < n + 1; i++) {
			seen[i] = false;
			edges[i].clear();
		}

		// read input
		while(m--) {
			scanf("%d %d", &u, &v);
			edges[u].push_back(v);
			edges[v].push_back(u);
		}

		// start with the vertex that has the most edges
		int max_edges = 0, max_vertex = v;
		for(int i = 0; i < n; i++) {
			if(max_edges < edges[i].size()) {
				max_edges = edges[i].size();
				max_vertex = i;
			}
		}

		// select vertices
		bfs(max_vertex);

		// print result
		printf("%d\n", (int) res.size());
		for(int i : res) printf("%d ", i);
		cout << endl;
	}

	return 0;
}


#include <bits/stdc++.h>
#define N 200000
#define INF 0x3f3f3f3f // 0x3f3f3f3f3f3f3f3fll

using namespace std;

int n, m;

vector<int> edges[N + 1];
bool paint [N + 1];
bool seen[N + 1];
queue<pair<int, bool>> todo;

void read_input() {

	scanf("%d%d", &n, &m);

	int u, v;
	for(int i = 1; i <= m; i++) {
		scanf("%d%d", &u, &v);
		edges[u].push_back(v);
		edges[v].push_back(u);
	}
}

void enqueue(int i, bool p) {
	if(!seen[i]) {
		seen[i] = true;
		todo.push({i, p});
	}
}

int paint_vertexes() {

	enqueue(1, true);

	int cur, painted = 0;
	bool p;
	while(!todo.empty()) {

		// get next vertex
		cur = todo.front().first;
		p = todo.front().second;
		todo.pop();

		paint[cur] = p;
		if(p) painted++;

		// check adjacent vertexes
		for(int adj : edges[cur]) {
			enqueue(adj, !p);
		}
	}

	return painted;
}

void print_result(int num_painted, bool painted) {
	printf("%d\n", num_painted);

	for(int i = 1; i <= n; i++) {
		if(paint[i] == painted) printf("%d ", i);
	}
	printf("\n");
}

void clear_structures() {

	for(int i = 1; i <= n; i++) {
		edges[i].clear();
		paint[i] = false;
		seen[i] = false;
	}
}

int main(){

	int t;
	scanf("%d", &t);

	while(t--){

		read_input();

		int painted = paint_vertexes();

		print_result(min(painted, n - painted), painted * 2 <= n);

		clear_structures();
	}

	return 0;
}


#include <bits/stdc++.h>
#define N 200000

using namespace std;

vector<int> edges [N + 1];
bool is_in_queue[N + 1];
bool adjacent[N + 1];
queue<int> todo;
vector<int> result;

void push(int x) {

	if(is_in_queue[x]) return;

	todo.push(x);
	is_in_queue[x] = true;
}

int main(){

	int t, n, m, u, v;
	cin >> t;
	while(t--) {

		// read n & m
		cin >> n >> m;

		// read edges
		for(int i = 0; i < m; i++) {
			cin >> u >> v;
			edges[u].push_back(v);
			edges[v].push_back(u);
		}

		// get the vertex with the most edges
		int i_max = 1;
		for(int i = 1; i <= n; i++) {

			if(edges[i_max].size() < edges[i].size()) {
				i_max = i;
			}
		}

		// set up for search
		int cur;
		todo.push(i_max);
		is_in_queue[i_max] = true;

		while(!todo.empty()) {

			// get next vertex
			cur = todo.front();
			todo.pop();

			// current vertex is NOT adjacent to marked vertex
			if(! adjacent[cur]) {
				result.push_back(cur);

				for(int adj : edges[cur]) {

					adjacent[adj] = true;

					if(! is_in_queue[adj]) push(adj);
				}
			}

			// current vertex is adjacent to marked vertex
			else {
				for(int adj: edges[cur]) {

					if(! is_in_queue[adj]) push(adj);
				}
			}
		}

		//print answer
		cout << result.size() << endl;
		for(int r : result) cout << r << " ";
		cout << endl;

		//clear structures (todo will be emtpty)
		for(int i = 1; i <= n; i++) {
			edges[i].clear();
			is_in_queue[i] = false;
			adjacent[i] = false;
		}
		result.clear();

	}
}


#include <bits/stdc++.h>
#define N 200000

using namespace std;

vector<int> res;
map<int, bool> seen;
map<int, vector<int>> edges;

void bfs(int vertex) {

	// choose this vertex
	if(!seen[vertex]) {

		// mark vertex as seen
		seen[vertex] = true;
		res.push_back(vertex);

		// mark all adjacent vertexes as seen
		for(int i : edges[vertex]) {
			seen[i] = true;
		}

		// bfs for all adjacent vertexes
		for(int i : edges[vertex]) {
			bfs(i);
		}

	}

	// vertex is adjacent to a chosen vertex
	else {

		// only run bfs for not seen vertices
		for(int i : edges[vertex]) {
			if(!seen[i]) bfs(i);
		}
	}
}

int main(){

	int t, n, m, u, v; // queries, vertices, edges
	scanf("%d", &t);
	while(t--) {

		// clear data structures
		res.clear();
		seen.clear();
		edges.clear();

		// read input
		scanf("%d %d", &n, &m);
		while(m--) {
			scanf("%d %d", &u, &v);
			edges[u].push_back(v);
			edges[v].push_back(u);
		}

		// start with the vertex that has the most edges
		int max_edges = 0, max_vertex = v;
		for(int i = 1; i < n; i++) {
			if(max_edges < edges[i].size()) {
				max_edges = edges[i].size();
				max_vertex = i;
			}
		}

		// select vertices
		bfs(max_vertex);

		// print result
		printf("%d\n", (int) res.size());
		for(int i : res) printf("%d ", i);
		cout << endl;
	}

	return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;

ll mod = 1e9+7;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	cin >> t;
	for (int x=0;x<t;x++){
		ll n,m;
		cin >> n >> m;
		vector <vector<ll>> graph(n+1);
		for (int z=0;z<m;z++){
			ll u,v;
			cin >> u >> v;
			graph[u].push_back(v);
			graph[v].push_back(u);
		}
		vector <ll> inside(n+1,false);
		for (int z=1;z<=n;z++){
			if (graph[z].size() == 1) {
				inside[graph[z][0]] = true;
			}
		}
		for (int z=1;z<=n;z++){
			bool ok = false;
			for (int x=0;x<graph[z].size();x++){
				if (inside[graph[z][x]]) {
					ok = true;
					break;
				}
			}
			if (!ok) inside[z] = true;
		}
		vector <ll> ans;
		for (int z=0;z<=n;z++){
			if (inside[z]) ans.push_back(z);
		}
		cout << ans.size() << endl;
		for (ll i : ans){
			cout << i << " ";
		} cout << endl;
	}
	cin >> t;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;

ll mod = 1e9+7;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	cin >> t;
	for (int q=0;q<t;q++){
		ll n,m;
		cin >> n >> m;
		vector <vector<ll>> graph(n+1);
		for (int z=0;z<m;z++){
			ll u,v;
			cin >> u >> v;
			graph[u].push_back(v);
			graph[v].push_back(u);
		}
		vector <ll> inside(n+1,false);
		for (int z=1;z<=n;z++){
			if (graph[z].size() == 1) {
				if (graph[graph[z][0]].size() != 1)
				inside[graph[z][0]] = true;
			}
		}
		for (int z=1;z<=n;z++){
			bool ok = false;
			for (int x=0;x<graph[z].size();x++){
				if (inside[graph[z][x]]) {
					ok = true;
					break;
				}
			}
			if (!ok) inside[z] = true;
		}
		vector <ll> ans;
		for (int z=0;z<=n;z++){
			if (inside[z]) ans.push_back(z);
		}
		cout << ans.size() << endl;
		for (ll i : ans){
			cout << i << " ";
		} cout << endl;
	}
	cin >> t;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;

ll mod = 1e9+7;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	cin >> t;
	for (int x=0;x<t;x++){
		ll n,m;
		cin >> n >> m;
		vector <vector<ll>> graph(n+1);
		for (int z=0;z<m;z++){
			ll u,v;
			cin >> u >> v;
			graph[u].push_back(v);
			graph[v].push_back(u);
		}
		queue <ll> que;
		vector <ll> ans;
		ll maxi = 0;
		ll pos = 0;
		for (int z=1;z<=n;z++){
			if (graph[z].size() >maxi){
				maxi = graph[z].size();
				pos = z;
			}
		}
		for (int z=0;z<graph[pos].size();z++){
			que.push(graph[pos][z]);
		}
		ans.push_back(pos);
		vector <ll> visited(n+1,false);
		vector <ll> inside(n+1,false);
		visited[pos] = true;
		inside[pos] = true;
 		queue <ll> que2;
		bool turn = false;
		do{
			while (!que.empty()){
				ll v = que.front();
				que.pop();
				if (visited[v]) continue;
				visited[v] = true;
				if (turn && !inside[v]) {
					inside[v] = true;
					ans.push_back(v);
				}
				for (int z=0;z<graph[v].size();z++){
					if (visited[graph[v][z]]) continue;
					que2.push(graph[v][z]);
				}
			}
			que = que2;
			queue <ll> temp;
			que2 = temp;
			turn = !turn;
		} while(!que.empty());
		cout << ans.size() << endl;
		for (ll i : ans){
			cout << i << " ";
		} cout << endl;
	}
	cin >> t;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;

ll mod = 1e9+7;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	cin >> t;
	for (int q=0;q<t;q++){
		ll n,m;
		cin >> n >> m;
		vector <vector<ll>> graph(n+1);
		for (int z=0;z<m;z++){
			ll u,v;
			cin >> u >> v;
			graph[u].push_back(v);
			graph[v].push_back(u);
		}
		vector <ll> inside(n+1,false);
		ll pos = 0;
		ll maxi = 0;
		for (int z=1;z<=n;z++){
			if (graph[z].size() > maxi){
				maxi = graph[z].size();
				pos = z;
			}
			if (graph[z].size() == 1) {
				if (graph[graph[z][0]].size() != 1)
				inside[graph[z][0]] = true;
			}
		}
		bool ok = false;
		for (int z=0;z<graph[pos].size();z++){
			if (inside[graph[pos][z]]){
				ok = true;
				break;
			}
		}
		if (!ok) inside[pos] = true;
		for (int z=1;z<=n;z++){
			ok = false;
			for (int x=0;x<graph[z].size();x++){
				if (inside[graph[z][x]]) {
					ok = true;
					break;
				}
			}
			if (!ok) inside[z] = true;
		}
		vector <ll> ans;
		for (int z=0;z<=n;z++){
			if (inside[z]) ans.push_back(z);
		}
		cout << ans.size() << endl;
		for (ll i : ans){
			cout << i << " ";
		} cout << endl;
	}
	cin >> t;
}


import sys
strings = []
for st in sys.stdin:
    strings.append(st)

frame_length = len(max(strings))
last_right = True
print('*'*(frame_length+2))
for st in strings:
    diff = frame_length-len(st)
    start_spaces = 0
    end_spaces = 0
    if diff % 2 == 1:
        if last_right:
            start_spaces = diff//2
            end_spaces =  (diff+1)//2
            last_right = False
        else:
            end_spaces = diff//2
            start_spaces = (diff+1)//2
            last_right = True
    else:
        start_spaces,end_spaces = [diff//2]*2
    print("*",end='')
    print(" "*start_spaces,end='')
    print(st,end='')
    print(" "*end_spaces,end='')
    print("*")
print('*'*(frame_length+2))


import sys
strings = []
for st in sys.stdin:
    strings.append(st.strip())

frame_length = len(max(strings,key=lambda x: len(x)))
last_right = True
print('*'*(frame_length+2))
for st in strings:
    diff = frame_length-len(st)
    start_spaces = 0
    end_spaces = 0
    if diff % 2 == 1:
        if last_right:
            start_spaces = diff//2
            end_spaces =  (diff+1)//2
            last_right = False
        else:
            end_spaces = diff//2
            start_spaces = (diff+1)//2
            last_right = True
    else:
        start_spaces,end_spaces = [diff//2]*2
    print("*",end='')
    print(" "*start_spaces,end='')
    print(st,end='')
    print(" "*end_spaces,end='')
    print("*")
print('*'*(frame_length+2))


import sys

n = 0
S = []
Sl = []
for request in sys.__stdin__:
    S.append(request[:-1])
    Sl.append(len(S[-1]))
    n += 1

width = max(Sl)

So = []

for i in range(n):
    if Sl[i] % 2 == width % 2:
        So.append("*" + " " * ((width - Sl[i]) // 2) + S[i] + " " * ((width - Sl[i]) // 2) + "*")
    else:
        So.append("*" + " " * ((width - Sl[i]) // 2 + 1) + S[i] + " " * ((width - Sl[i]) // 2) + "*")
print("*" * (width + 2))
print(*So, sep="\n")
print("*" * (width + 2))


import sys

n = 0
S = []
Sl = []
for request in sys.__stdin__:
    S.append(request[:[-1]])
    Sl.append(len(S[-1]))
    n += 1

width = max(Sl)

So = []

for i in range(n):
    if Sl[i] % 2 == width % 2:
        So.append("*" + " " * ((width - Sl[i]) // 2) + S[i] + " " * ((width - Sl[i]) // 2) + "*")
    else:
        So.append("*" + " " * ((width - Sl[i]) // 2 + 1) + S[i] + " " * ((width - Sl[i]) // 2) + "*")
print("*" * (width + 2))
print(*So, sep="\n")
print("*" * (width + 2))


import sys

n = 0
S = []
Sl = []
for request in sys.__stdin__:
    S.append(request[:-1])
    Sl.append(len(S[-1]))
    n += 1

width = max(Sl)

So = []
align = False

for i in range(n):
    if Sl[i] % 2 == width % 2:
        So.append("*" + " " * ((width - Sl[i]) // 2) + S[i] + " " * ((width - Sl[i]) // 2) + "*")
    else:
        So.append("*" + " " * ((width - Sl[i]) // 2 + int(align)) + S[i] + " " * ((width - Sl[i]) // 2 +
                  int(not align)) + "*")
        align = not align
print("*" * (width + 2))
print(*So, sep="\n")
print("*" * (width + 2))


import sys

def transfer(maxi,x):
	back_space = int((maxi-len(x))/2)
	front_space = maxi-len(x)-back_space
	tmp_line = "*"
	for i in range(front_space):
		tmp_line = tmp_line+' '
	tmp_line = tmp_line+x
	for i in range(back_space):
		tmp_line = tmp_line+' '
	tmp_line = tmp_line+'*'
	print(tmp_line)
	return tmp_line

if __name__ =="__main__":
	tmp =[]
	maxi = 0
	for i in sys.stdin:
		tmp.append(i[:-1])
		if len(i)-1>maxi:
			maxi = len(i)-1
	top = ''
	for i in range(maxi+2):
		top = top+"*"
	print(top)
	for i in tmp:
		transfer(maxi,i)
	print(top)


import sys

def transfer(maxi,x,left):
	if left:
		front_space = int((maxi-len(x))/2)
		back_space= maxi-len(x)-front_space
	else:
		back_space = int((maxi-len(x))/2)
		front_space= maxi-len(x)-back_space

	tmp_line = "*"
	for i in range(front_space):
		tmp_line = tmp_line+' '
	tmp_line = tmp_line+x
	for i in range(back_space):
		tmp_line = tmp_line+' '
	tmp_line = tmp_line+'*'
	print(tmp_line)
	return tmp_line

if __name__ =="__main__":
	tmp =[]
	maxi = 0
	left = True
	for i in sys.stdin:
		tmp.append(i[:-1])
		if len(i)-1>maxi:
			maxi = len(i)-1
	top = ''
	for i in range(maxi+2):
		top = top+"*"
	print(top)
	for i in tmp:
		transfer(maxi,i,left)
		if(len(i)%2==1):
			left = not left
	print(top)


import sys

def transfer(maxi,x,left):
	if left:
		front_space = int((maxi-len(x))/2)
		back_space= maxi-len(x)-front_space
	else:
		back_space = int((maxi-len(x))/2)
		front_space= maxi-len(x)-back_space

	tmp_line = "*"
	for i in range(front_space):
		tmp_line = tmp_line+' '
	tmp_line = tmp_line+x
	for i in range(back_space):
		tmp_line = tmp_line+' '
	tmp_line = tmp_line+'*'
	print(tmp_line)
	return tmp_line

if __name__ =="__main__":
	tmp =[]
	maxi = 0
	left = True
	for i in sys.stdin:
		tmp.append(i[:-1])
		if len(i)-1>maxi:
			maxi = len(i)-1
	top = ''
	for i in range(maxi+2):
		top = top+"*"
	print(top)
	for i in tmp:
		transfer(maxi,i,left)
		if not len(i)%2==maxi%2:
			left = not left
	print(top)


import sys

def transfer(maxi,x):
	front_space = int((maxi-len(x))/2)
	back_space = maxi-len(x)-front_space
	tmp_line = "*"
	for i in range(front_space):
		tmp_line = tmp_line+' '
	tmp_line = tmp_line+x
	for i in range(back_space):
		tmp_line = tmp_line+' '
	tmp_line = tmp_line+'*'
	print(tmp_line)
	return tmp_line

if __name__ =="__main__":
	tmp =[]
	maxi = 0
	for i in sys.stdin:
		tmp.append(i[:-1])
		if len(i)-1>maxi:
			maxi = len(i)-1
	top = ''
	for i in range(maxi+2):
		top = top+"*"
	print(top)
	for i in tmp:
		transfer(maxi,i)
	print(top)


#!/usr/bin/env python

def main():
    lines = list()
    try:
        while True:
            lines.append(input())
    except EOFError:
        width = max(map(len, lines))
        left = True
        stars = "*" * (width + 2)
        space = " " * width
        print(stars)
        for line in lines:
            center = ["*"]
            fill = width - len(line)
            if not fill:
                center.append(line)
            elif fill == width:
                center.append(space)
            else:
                sp = space[:fill // 2]
                if fill & 1:
                    if left:
                        center += sp, line, sp, " "
                    else:
                        center += " ", sp, line, sp
                    left = not left
                else:
                    center += sp, line, sp
            center.append("*")
            print(*center, sep="")
        print(stars)

if __name__ == '__main__':
    main()


#!/usr/bin/env python

def main():
    lines = list()
    try:
        while True:
            lines.append(input())
    except EOFError:
        width = max(map(len, lines))
        left = True
        stars = "*" * (width + 2)
        print(stars)
        for line in lines:
            fill = width - len(line)
            if fill == width:
                center = " " * fill
            elif fill:
                fill0 = fill // 2
                fill -= fill0
                if left:
                    center = (" " * fill0) + line + (" " * fill)
                else:
                    center = (" " * fill) + line + (" " * fill0)
                left = not left
            else:
                center = line

            print("*", center, "*", sep="")
        print(stars)

if __name__ == '__main__':
    main()


import math
l = []
try:
    while True:
        a = input()
        l.append(a)
except:
    pass

big = len(max(l,key=len))
print(("*"*big)+"**")
left = True
for i in l:
    sep = (big-len(i))/2
    if sep == math.floor(sep):
        sep = int(sep)
        print("*"+" "*sep+i+" "*sep+"*")
    else:
        sep = math.ceil(sep)
        if left:
            print("*"+" "*(sep-1)+i+" "*sep+"*")
            left = False
        else:
            print("*"+" "*(sep)+i+" "*(sep-1)+"*")
            left = True

print("*"*big+"**")


text, maxLength = [], 0

while True:
    try:
        t = input()
        text.append(t)
        if len(t) > maxLength:
            maxLength = len(t)
    except EOFError:
        break

print("*" * (maxLength + 2))
i = 0
for t in text:
    if (maxLength - len(t)) % 2 == 0:
        print("*" + " " * int(((maxLength - len(t)) / 2)) + t + " " * int(((maxLength - len(t)) / 2)) + "*")
    else:
        if i == 0:
            print("*" + " " * int(((maxLength - len(t)) / 2)) + t + " " * (int(((maxLength - len(t)) / 2)) + 1)  + "*")
            i = 1
        else:
            print("*" + " " * (int(((maxLength - len(t)) / 2)) + 1) + t + " " * int(((maxLength - len(t)) / 2))  + "*")
            i = 0
print("*" * (maxLength + 2))


from sys import stdin
text = stdin.read().split("\n")[:-1]
maxi = 0

for line in text:
	if len(line) > maxi: maxi = len(line)
output = ['*'*(maxi+2)]
rightturn = False
for lines in text:
	line = lines
	if len(line) % 2 != maxi % 2:
		if rightturn: line = " "+line
		else: line = line + ""
		rightturn = not rightturn
	output.append('*' + '{txt:^{width}}'.format(txt = line, width = maxi) + '*')
output.append('*'*(maxi+2))
print("\n".join(output))

"""
'*     5    *'
'*    5     *'

*      and
*     *

"""


from sys import stdin
text = stdin.read().split("\n")[:-1]
maxi = 0

for line in text:
	if len(line) > maxi: maxi = len(line)
output = ['*'*(maxi+2)]
for line in text:
	output.append('*' + '{txt:^{width}}'.format(txt = line, width = maxi) + '*')
output.append('*'*(maxi+2))
print("\n".join(output))


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy

ORDA = 97
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return [int(i) for i in input().split()]
def lcm(a, b): return abs(a * b) // math.gcd(a, b)
def revn(n): return str(n)[::-1]
def dd(): return collections.defaultdict(int)
def ddl(): return collections.defaultdict(list)
def sieve(n):
    if n < 2: return list()
    prime = [True for _ in range(n + 1)]
    p = 3
    while p * p <= n:
        if prime[p]:
            for i in range(p * 2, n + 1, p):
                prime[i] = False
        p += 2
    r = [2]
    for p in range(3, n + 1, 2):
        if prime[p]:
            r.append(p)
    return r
def divs(n, start=1):
    r = []
    for i in range(start, int(math.sqrt(n) + 1)):
        if (n % i == 0):
            if (n / i == i):
                r.append(i)
            else:
                r.extend([i, n // i])
    return r
def divn(n, primes):
    divs_number = 1
    for i in primes:
        if n == 1:
            return divs_number
        t = 1
        while n % i == 0:
            t += 1
            n //= i
        divs_number *= t
def prime(n):
    if n == 2: return True
    if n % 2 == 0 or n <= 1: return False
    sqr = int(math.sqrt(n)) + 1
    for d in range(3, sqr, 2):
        if n % d == 0: return False
    return True
def convn(number, base):
    newnumber = 0
    while number > 0:
        newnumber += number % base
        number //= base
    return newnumber
def cdiv(n, k): return n // k + (n % k != 0)

arr = []
for line in fileinput.input():
    arr.append(line)
max_ = max(map(len, arr))
print('*' * (max_ + 2))
for i in arr:
    if (max_ - len(i)) & 1:
        print('*' + ' ' * ((max_ - len(i)) // 2) + i + ' ' * ((max_ - len(i)) // 2 + 1) + '*')
    else:
        print('*' + ' ' * ((max_ - len(i)) // 2) + i + ' ' * ((max_ - len(i)) // 2) + '*')
print('*' * (max_ + 2))


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy

ORDA = 97
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return [int(i) for i in input().split()]
def lcm(a, b): return abs(a * b) // math.gcd(a, b)
def revn(n): return str(n)[::-1]
def dd(): return collections.defaultdict(int)
def ddl(): return collections.defaultdict(list)
def sieve(n):
    if n < 2: return list()
    prime = [True for _ in range(n + 1)]
    p = 3
    while p * p <= n:
        if prime[p]:
            for i in range(p * 2, n + 1, p):
                prime[i] = False
        p += 2
    r = [2]
    for p in range(3, n + 1, 2):
        if prime[p]:
            r.append(p)
    return r
def divs(n, start=1):
    r = []
    for i in range(start, int(math.sqrt(n) + 1)):
        if (n % i == 0):
            if (n / i == i):
                r.append(i)
            else:
                r.extend([i, n // i])
    return r
def divn(n, primes):
    divs_number = 1
    for i in primes:
        if n == 1:
            return divs_number
        t = 1
        while n % i == 0:
            t += 1
            n //= i
        divs_number *= t
def prime(n):
    if n == 2: return True
    if n % 2 == 0 or n <= 1: return False
    sqr = int(math.sqrt(n)) + 1
    for d in range(3, sqr, 2):
        if n % d == 0: return False
    return True
def convn(number, base):
    newnumber = 0
    while number > 0:
        newnumber += number % base
        number //= base
    return newnumber
def cdiv(n, k): return n // k + (n % k != 0)

arr = []
for line in fileinput.input():
    arr.append(line.strip())
max_ = max(map(len, arr))
print('*' * (max_ + 2))
f = True
for i in arr:
    if (max_ - len(i)) & 1:
        if f:
            print('*' + ' ' * ((max_ - len(i)) // 2) + i + ' ' * ((max_ - len(i)) // 2 + 1) + '*')
            f = False
        else:
            print('*' + ' ' * ((max_ - len(i)) // 2 + 1) + i + ' ' * ((max_ - len(i)) // 2) + '*')
            f = True
    else:
        print('*' + ' ' * ((max_ - len(i)) // 2) + i + ' ' * ((max_ - len(i)) // 2) + '*')
        f = True
print('*' * (max_ + 2))


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy

ORDA = 97
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return [int(i) for i in input().split()]
def lcm(a, b): return abs(a * b) // math.gcd(a, b)
def revn(n): return str(n)[::-1]
def dd(): return collections.defaultdict(int)
def ddl(): return collections.defaultdict(list)
def sieve(n):
    if n < 2: return list()
    prime = [True for _ in range(n + 1)]
    p = 3
    while p * p <= n:
        if prime[p]:
            for i in range(p * 2, n + 1, p):
                prime[i] = False
        p += 2
    r = [2]
    for p in range(3, n + 1, 2):
        if prime[p]:
            r.append(p)
    return r
def divs(n, start=1):
    r = []
    for i in range(start, int(math.sqrt(n) + 1)):
        if (n % i == 0):
            if (n / i == i):
                r.append(i)
            else:
                r.extend([i, n // i])
    return r
def divn(n, primes):
    divs_number = 1
    for i in primes:
        if n == 1:
            return divs_number
        t = 1
        while n % i == 0:
            t += 1
            n //= i
        divs_number *= t
def prime(n):
    if n == 2: return True
    if n % 2 == 0 or n <= 1: return False
    sqr = int(math.sqrt(n)) + 1
    for d in range(3, sqr, 2):
        if n % d == 0: return False
    return True
def convn(number, base):
    newnumber = 0
    while number > 0:
        newnumber += number % base
        number //= base
    return newnumber
def cdiv(n, k): return n // k + (n % k != 0)

arr = []
for line in fileinput.input():
    arr.append(line.strip())
max_ = max(map(len, arr))
print('*' * (max_ + 2))
f = True
for i in arr:
    if (max_ - len(i)) & 1:
        if f:
            print('*' + ' ' * ((max_ - len(i)) // 2) + i + ' ' * ((max_ - len(i)) // 2 + 1) + '*')
            f = False
        else:
            print('*' + ' ' * ((max_ - len(i)) // 2 + 1) + i + ' ' * ((max_ - len(i)) // 2) + '*')
            f = True
    else:
        print('*' + ' ' * ((max_ - len(i)) // 2) + i + ' ' * ((max_ - len(i)) // 2) + '*')
print('*' * (max_ + 2))


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy

ORDA = 97
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return [int(i) for i in input().split()]
def lcm(a, b): return abs(a * b) // math.gcd(a, b)
def revn(n): return str(n)[::-1]
def dd(): return collections.defaultdict(int)
def ddl(): return collections.defaultdict(list)
def sieve(n):
    if n < 2: return list()
    prime = [True for _ in range(n + 1)]
    p = 3
    while p * p <= n:
        if prime[p]:
            for i in range(p * 2, n + 1, p):
                prime[i] = False
        p += 2
    r = [2]
    for p in range(3, n + 1, 2):
        if prime[p]:
            r.append(p)
    return r
def divs(n, start=1):
    r = []
    for i in range(start, int(math.sqrt(n) + 1)):
        if (n % i == 0):
            if (n / i == i):
                r.append(i)
            else:
                r.extend([i, n // i])
    return r
def divn(n, primes):
    divs_number = 1
    for i in primes:
        if n == 1:
            return divs_number
        t = 1
        while n % i == 0:
            t += 1
            n //= i
        divs_number *= t
def prime(n):
    if n == 2: return True
    if n % 2 == 0 or n <= 1: return False
    sqr = int(math.sqrt(n)) + 1
    for d in range(3, sqr, 2):
        if n % d == 0: return False
    return True
def convn(number, base):
    newnumber = 0
    while number > 0:
        newnumber += number % base
        number //= base
    return newnumber
def cdiv(n, k): return n // k + (n % k != 0)

arr = []
for line in fileinput.input():
    arr.append(line.strip())
max_ = max(map(len, arr))
print('*' * (max_ + 2))
for i in arr:
    if (max_ - len(i)) & 1:
        print('*' + ' ' * ((max_ - len(i)) // 2) + i + ' ' * ((max_ - len(i)) // 2 + 1) + '*')
    else:
        print('*' + ' ' * ((max_ - len(i)) // 2) + i + ' ' * ((max_ - len(i)) // 2) + '*')
print('*' * (max_ + 2))


text = []
res = []
direction = "l"
while True:
    try:
        text.append(input())
    except:
        break

_len = len(sorted(text, key = lambda s: len(s))[-1])

print("*" * (_len+2))
for s in text:
    if len(s)%2 != _len%2:
        if direction == "l":
            s += " "
            direction = "r"
        else:
            s = " " + s
            direction = "l"
    print( "*" + s.center(_len, " ") + "*")

print("*" * (_len+2))


text = []
res = []
while True:
    try:
        text.append(input())
    except:
        break

_len = len(sorted(text, key = lambda s: len(s))[-1])

print("*" * (_len+2))
for s in text:
    print( "*" + s.center(_len, " ") + "*")

print("*" * (_len+2))


# -*- coding: utf-8 -*-
"""
Created on Wed Sep 19 10:14:01 2018

@author: haoqianqiong

Keep going !!! Walking to Lose Weight!!!
"""

import sys

a = [];b=[]
for s in sys.stdin:
    a.append(s.strip('\n'))
    b.append(len(s)-1)
c = max(b)
e = 0
print('*' * (c+2))
for i in a:
    print('*',end='')
    d = 0
    if (c-len(i))%2==1:
        e +=1
        d = (c-len(i)+(-1)**e) // 2
        print(' ' * d + i + ' ' * (c-len(i)-d),end='')
    else:
        d = (c-len(i)) // 2
        print(' ' * d + i + ' ' * (c-len(i)-d),end='')
    print('*')
print('*' * (c+2))


# -*- coding: utf-8 -*-
"""
Created on Wed Sep 19 10:14:01 2018

@author: haoqianqiong

Keep going !!! Walking to Lose Weight!!!
"""

import sys

a = [];b=[]
for s in sys.stdin:
    a.append(s)
    b.append(len(s)-1)
c = max(b)
print('*' * (c+2))
for i in a:
    print('*',end='')
    d = (c-len(i))//2
    print(' ' * d + i + ' ' * (c-len(i)-d),end='')
    print('*')
print('*' * (c+2))


# -*- coding: utf-8 -*-
"""
Created on Wed Sep 19 10:14:01 2018

@author: haoqianqiong

Keep going !!! Walking to Lose Weight!!!
"""

import sys

a = [];b=[]
for s in sys.stdin:
    a.append(s.strip('\n'))
    b.append(len(s)-1)
c = max(b)
print('*' * (c+2))
for i in a:
    print('*',end='')
    d = (c-len(i))//2
    print(' ' * d + i + ' ' * (c-len(i)-d),end='')
    print('*')
print('*' * (c+2))


# -*- coding: utf-8 -*-
"""
Created on Wed Sep 19 10:14:01 2018

@author: haoqianqiong

Keep going !!! Walking to Lose Weight!!!
"""

import sys

a = [];b=[]
for s in sys.stdin:
    a.append(s)
    b.append(len(s)-1)
c = max(b)
print('*' * (c+2))
for i in a:
    print('*',end='')
    for j in range(c):
        d = (c-len(i))//2
        print(' ' * d + i + ' ' * (c-len(i)-d),end='')
    print('*')
print('*' * (c+2))


# -*- coding: utf-8 -*-
"""
Created on Wed Sep 19 10:14:01 2018

@author: haoqianqiong

Keep going !!! Walking to Lose Weight!!!
"""

import sys

a = [];b=[]
for s in sys.stdin:
    a.append(s.strip('\n'))
    b.append(len(s)-1)
c = max(b)
print('*' * (c+2))
for i in a:
    print('*',end='')
    d = (c-len(i)+1)//2
    print(' ' * d + i + ' ' * (c-len(i)-d),end='')
    print('*')
print('*' * (c+2))


import sys

def main():
    lines = [line.strip() for line in sys.stdin]
    w = max(len(l) for l in lines) + 2
    print('*' * w)
    flag = True
    for line in lines:
        extra = w - 2 - len(line)
        if extra % 2 != 0:
            if flag:
                left = extra  // 2
                right = extra - left
            else:
                right = extra // 2
                left = extra - right

            flag = not flag
        else:
            left = extra // 2
            right = extra // 2

        print('*' + ' ' * left + line + ' ' * right + '*')
    print('*' * w)

main()


from sys import stdin
def main():
  inputText =[]
  lengths = []
  for line in stdin:
    #in this way we removed \n
    inputText.append(line[0:len(line)-1])
    #-1 because we don't want to count \n char
    lengths.append(len(line)-1)
  #get the maximum Length
  maxLength = max(lengths)
  #print the first line of **********
  for i in range(maxLength+2):
    print('*',end="")
  #print new line
  print()
  #this boolean variable will help us to position text with one space to left or to right
  #if it is not possible to center it perfectely, we use it because we have to alternate
  #the first line which can't be centered exactly has to be one space to the left, the next one, one space to right
  left = True
  for i in range(len(lengths)):
    #if both are even or both are not even, then we can center text exactely
    if (lengths[i]%2 == 0 and maxLength%2 == 0) or (lengths[i]%2 != 0 and maxLength%2 != 0):
      spaces = (maxLength - lengths[i])//2
      print('*',' '*spaces,inputText[i],' '*spaces,'*',sep='')
    else:
      if left:
        spaces = (maxLength - lengths[i] - 1)//2
        left = False
        print('*',' '*spaces,inputText[i],' '*(spaces+1),'*',sep='')
      else:
        spaces = (maxLength - lengths[i] + 1)//2
        left = True
        print('*',' '*spaces,inputText[i],' '*(spaces-1),'*',sep='')
  #print the last line of *************************
  for i in range(maxLength+2):
    print('*',end="")
main()


from sys import stdin
def main():
  inputText =[]
  lengths = []
  for line in stdin:
    #in this way we removed \n
    inputText.append(line[0:len(line)-1])
    lengths.append(len(line)-1)
  maxLength = max(lengths)
  for i in range(maxLength+2):
    print('*',end="")
  print()
  left = True
  for i in range(len(lengths)):
    #if both are even or both are not even, then we can center text exactely
    if (lengths[i]%2 == 0 and maxLength%2 == 0) or (lengths[i]%2 != 0 and maxLength%2 != 0):
      spaces = (maxLength - lengths[i])//2
      print('*',' '*spaces,inputText[i],' '*spaces,'*',sep='')
    else:
      if left:
        spaces = (maxLength - lengths[i] - 1)//2
        left = False
        print('*',' '*spaces,inputText[i],' '*(spaces+1),'*',sep='')
      else:
        spaces = (maxLength - lengths[i] + 1)//2
        left = True
        print('*',' '*spaces,inputText[i],' '*(spaces-1),'*',sep='')

  for i in range(maxLength+2):
    print('*',end="")
main()


from sys import stdin
def main():
  inputText =[]
  lengths = []
  for line in stdin:
    #in this way we removed \n
    inputText.append(line[0:len(line)-1])
    lengths.append(len(line)-1)
  maxLength = max(lengths)
  print(lengths)
  for i in range(maxLength+2):
    print('*',end="")
  print()
  left = True
  for i in range(len(lengths)):
    #if both are even or both are not even, then we can center text exactely
    if (lengths[i]%2 == 0 and maxLength%2 == 0) or (lengths[i]%2 != 0 and maxLength%2 != 0):
      spaces = (maxLength - lengths[i])//2
      print('*',' '*spaces,inputText[i],' '*spaces,'*',sep='')
    else:
      if left:
        spaces = (maxLength - lengths[i] - 1)//2
        left = False
        print('*',' '*spaces,inputText[i],' '*(spaces+1),'*',sep='')
      else:
        spaces = (maxLength - lengths[i] + 1)//2
        left = True
        print('*',' '*spaces,inputText[i],' '*(spaces-1),'*',sep='')

  for i in range(maxLength+2):
    print('*',end="")
main()


import sys
max_string_len = 0
raw_string = []
flag_l = True

for st in sys.stdin.read().splitlines():
    raw_string.append([st, len(st)])
    if len(st) > max_string_len:
        max_string_len = len(st)
max_len = max_string_len + 2

print('*' * max_len)

for st in raw_string:
    tmp_add =  max_string_len - st[1]
    if st[1] == 0:
         print('*'+' '*max_string_len+'*')
         continue
    if tmp_add == 0:
        print('*'+st[0]+'*')
        continue
    else:
        sum_l1 = tmp_add//2
        if (tmp_add % 2) == 0:
            l1 = sum_l1
            print('*'+' '*l1 + st[0] + ' '*l1+ '*')
        else :
            if flag_l:
                l1 = sum_l1
                l2 = sum_l1 + 1
            else:
                l1 = sum_l1+ 1
                l2 = sum_l1
            flag_l = not flag_l
            print( '*'+' '*l1 + st[0] + ' '*l2+ '*')

print('*' * max_len)


import sys
max_string_len = 0
raw_string = []
flag_l = True

for st in sys.stdin.read().splitlines():
    raw_string.append([st, len(st)])
    if len(st) > max_string_len:
        max_string_len = len(st)
max_len = max_string_len + 2

print('*' * max_len)

for st in raw_string:
    tmp_add =  max_string_len - st[1]
    if st[1] == 0:
         print('*'+' '*max_string_len+'*')
         continue
    if tmp_add == 0:
        print('*'+st[0]+'*')
        continue
    else:
        sum_l1 = tmp_add//2
        if (tmp_add % 2) == 0:
            l1 = sum_l1
            print('*'+' '*l1 + st[0] + ' '*l1+ '*')
        if tmp_add % 2 > 0 :
            if flag_l:
                l1 = sum_l1
                l2 = sum_l1 + 1
            if (not flag_l):
                l1 = sum_l1+ 1
                l2 = sum_l1
            flag_l = not flag_l
            print( '*'+' '*l1 + st[0] + ' '*l2+ '*')

print('*' * max_len)
#print(raw_string)


def change(i):
    global a;global flag;
    l=len(a[i]);
    tmp="";
    space=maxlen-l;
    for j in range(space//2):tmp+=' ';
    if(space%2==0):
        a[i]='*'+tmp+a[i]+tmp+'*';
    else:
        if(flag==0):a[i]='*'+tmp+a[i]+tmp+' *';
        else:       a[i]='*'+tmp+' '+a[i]+tmp+'*';
        flag^=1;
a=[];
maxlen=0;
while(1):
    try:
        tmp=input();
        le=len(tmp);
        if(le>maxlen):maxlen=le;
        a.append(tmp);
    except:
        break;
cnt=len(a);
flag=0;
for i in range(cnt):
    change(i);
tmp="";
for i in range(maxlen+2):tmp+='*';
a.insert(0,tmp);a.append(tmp);
for i in a:print(i);


import sys
a = [l.strip() for l in sys.stdin]
w,c = max(len(l) for l in a), 0
print('*' * (w+2))
for l in a:
    s = [(w-len(l))//2] * 2
    if len(l) % 2 != w % 2:
        c = 1-c
        s[c] += 1
    print('*'+' '*s[0] + l + ' '*s[1] +'*')
print('*' * (w+2))


import sys
a = [l.strip() for l in sys.stdin]
w,c = max(len(l) for l in a), 0  #find max width nd count
#Print top
print('*' * (w+2))
for l in a:
    s = [(w-len(l))//2] * 2
    #Check total blank spaces and divide it into left and right part
    if len(l) % 2 != w % 2:
        #If the spaces are not even then start alternatively
        c = 1-c
        s[c] += 1
    print('*'+' '*s[0] + l + ' '*s[1] +'*')
print('*' * (w+2))

#Nice Answer ####


a = []
m_len = 0
try:
    while 1:
        a.append(input())
        m_len = max(m_len, len(a[-1]))
except EOFError:
    print('*' * (m_len + 2))
    flag = 0
    for i in range(len(a)):
        l = len(a[i])
        space = (m_len - l) // 2
        if l % 2 == m_len % 2:
            print('*' + ' ' * space + a[i] + ' ' * space + '*')
        else:
            print('*' + ' ' * (space + flag) + a[i] + ' ' * (space + 1 - flag) + '*')
            flag = 1 - flag
    print('*' * (m_len + 2))


a = []
m_len = 0
try:
    while 1:
        a.append(input())
        m_len = max(m_len, len(a[-1]))
except EOFError:
    print('*' * (m_len + 2))
    flag = 0
    for i in range(len(a)):
        l = len(a[i])
        space = (m_len - l) // 2
        if l % 2 == m_len % 2:
            print('*' + ' ' * space + a[i] + ' ' * space + '*')
        else:
            print('*' + ' ' * (space + flag) + a[i] + ' ' * (space + 1 - flag) + '*')
            flag = 1 - flag


import sys

l = 0;
strs = [];
for s in sys.stdin:
    s1 = s.strip()
    l = max(l, len(s1))
    strs.append(s1)

print('*' * (l + 2))

i = 0
for s in strs:
    print('*', end='')
    a = 0; b = 0;
    val = l - len(s)
    if(val % 2 == 0):
        a = val // 2
        b = a
    else:
        if(i == 1):
            a = val // 2
            b = a + 1
        else:
            b = val // 2
            a = b + 1
        i = 1 - i
    print(' ' * a, end='')
    print(s, end='')
    print(' ' * b, end='')
    print('*')

print('*' * (l + 2))


import sys

l = 0;
strs = [];
for s in sys.stdin:
    l = max(l, len(s) - 1)
    strs.append(s[:len(s) - 2])

print('*' * (l + 2))

i = 0
for s in strs:
    print('*', end='')
    a = l - len(s); b = a // 2; c = a - b;
    if(i == 1):
        b, c = c, b
    i = 1 - i
    print(' ' * b, end='')
    print(s, end='')
    print(' ' * c, end='')
    print('*')

print('*' * (l + 2))


import sys

l = 0;
strs = [];
for s in sys.stdin:
    s1 = s.strip()
    l = max(l, len(s1))
    strs.append(s1)

print('*' * (l + 2))

i = 0
for s in strs:
    print('*', end='')
    a = 0; b = 0;
    val = l - len(s)
    if(val % 2 == 0):
        a = val // 2
        b = a
    else:
        if(i == 0):
            a = val // 2
            b = a + 1
        else:
            b = val // 2
            a = b + 1
        i = 1 - i
    print(' ' * a, end='')
    print(s, end='')
    print(' ' * b, end='')
    print('*')

print('*' * (l + 2))


import sys

l = 0;
strs = [];
for s in sys.stdin:
    l = max(l, len(s) - 1)
    strs.append(s[:len(s) - 1])

print('*' * (l + 2))

for s in strs:
    print('*', end='')
    a = l - len(s); b = a // 2; c = a - b;
    print(' ' * b, end='')
    print(s, end='')
    print(' ' * c, end='')
    print('*')

print('*' * (l + 2))


import sys

l = 0;
strs = [];
for s in sys.stdin:
    s1 = s.strip()
    l = max(l, len(s1))
    strs.append(s1)

print('*' * (l + 2))

i = 0
for s in strs:
    print('*', end='')
    a = l - len(s); b = a // 2; c = a - b;
    if(i == 1):
        b, c = c, b
        i = 1 - i
    print(' ' * b, end='')
    print(s, end='')
    print(' ' * c, end='')
    print('*')

print('*' * (l + 2))


import sys

l = 0;
strs = [];
for s in sys.stdin:
    l = max(l, len(s) - 1)
    strs.append(s[:len(s) - 2])

print('*' * (l + 2))

i = 0
for s in strs:
    print('*', end='')
    a = l - len(s); b = a // 2; c = a - b;
    if(i == 1):
        b, c = c, b
        i = 1 - i
    print(' ' * b, end='')
    print(s, end='')
    print(' ' * c, end='')
    print('*')

print('*' * (l + 2))


s,n=[],0
while True:
    try:
        s.append(input())
        n+=1
    except EOFError:
        break
m=len(sorted(s,key=lambda x:len(x))[-1])
print("*"*(m+2))
for i in range (n):
    print("*",end="")
    x=len(s[i])
    if (m-x)%2==0:
        print(" "*int((m-x)/2),end="")
    else :
        print(" "*int((m-x)+1)/2,end="")
    print(s[i],end="")
    print(" "*int((m-x)/2),end="")
    print("*")
print("*"*(m+2))


s,n=[],0
while True:
    try:
        s.append(input())
        n+=1
    except EOFError:
        break
m=len(sorted(s,key=lambda x:len(x))[-1])
f=0
print("*"*(m+2))
for i in range (n):
    print("*",end="")
    x=len(s[i])
    if (m-x)%2!=0 and f==0:
        print(" "*int((m-x)+1/2),end="")
        f=1
    else:
        print(" "*int((m-x)/2),end="")
    print(s[i],end="")
    if (m-x)%2!=0 and f==1:
        print(" "*int((m-x)+1/2),end="")
        f=0
    else :
        print(" "*int((m-x)/2),end="")
    print("*")
print("*"*(m+2))


s,n=[],0
while True:
    try:
        s.append(input())
        n+=1
    except EOFError:
        break
m=len(sorted(s,key=lambda x:len(x))[-1])
f=0
print("*"*(m+2))
for i in range (n):
    x=len(s[i])
    print("*",end="")
    if (m-x)%2!=0 and f==0:
        print(" "*int((m-x+1)/2),end="")
        print(s[i])
        print(" "*int((m-x)/2),end="")
        f=1
    elif (m-x)%2!=0 and f==1:
        print(" "*int((m-x)/2),end="")
        print(s[i])
        print(" "*int((m-x+1)/2),end="")
        f=0
    else :
        print(" "*int((m-x)/2),end="")
        print(s[i])
        print(" "*int((m-x)/2),end="")
    print("*")
print("*"*(m+2))


s,n=[],0
while True:
    try:
        s.append(input())
        n+=1
    except EOFError:
        break
m=len(sorted(s,key=lambda x:len(x))[-1])
print("*"*(m+2))
for i in range (n):
    print("*",end="")
    x=len(s[i])
    if (m-x)%2==0:
        print(" "*int((m-x)/2),end="")
    else :
        print(" "*int((m-x)+1)/2,end="")
    print(s[i],end="")
    print(" "*(m-x),end="")
    print("*")
print("*"*(m+2))


s,n=[],0
while True:
    try:
        s.append(input())
        n+=1
    except EOFError:
        break
m=len(sorted(s,key=lambda x:len(x))[-1])
f=0
print("*"*(m+2))
for i in range (n):
    print("*",end="")
    x=len(s[i])
    if (m-x)%2!=0 and f==0:
        print(" "*int((m-x+1)/2),end="")
        f=1
    else:
        print(" "*int((m-x)/2),end="")
    print(s[i],end="")
    if (m-x)%2!=0 and f==1:
        print(" "*int((m-x+1)/2),end="")
        f=0
    else :
        print(" "*int((m-x)/2),end="")
    print("*")
print("*"*(m+2))


s,n=[],0
while True:
    try:
        s.append(input())
        n+=1
    except EOFError:
        break
m=len(sorted(s,key=lambda x:len(x))[-1])
print("*"*(m+2))
for i in range (n):
    print("*",end="")
    x=len(s[i])
    if (m-x)%2==0:
        print(" "*((m-x)/2),end="")
    else :
        print(" "*((m-x)+1)/2,end="")
    print(s[i],end="")
    print(" "*(m-x),end="")
    print("*")
print("*"*(m+2))


s,n=[],0
while True:
    try:
        s.append(input())
        n+=1
    except EOFError:
        break
m=len(sorted(s,key=lambda x:len(x))[-1])
f=0
print("*"*(m+2))
for i in range (n):
    x=len(s[i])
    print("*",end="")
    if (m-x)%2!=0 and f==0:
        print(" "*int((m-x)/2),end="")
        print(s[i],end="")
        print(" "*int((m-x+1)/2),end="")
        f=1
    elif (m-x)%2!=0 and f==1:
        print(" "*int((m-x+1)/2),end="")
        print(s[i],end="")
        print(" "*int((m-x)/2),end="")
        f=0
    else :
        print(" "*int((m-x)/2),end="")
        print(s[i],end="")
        print(" "*int((m-x)/2),end="")
    print("*")
print("*"*(m+2))


s,n=[],0
while True:
    try:
        s.append(input())
        n+=1
    except EOFError:
        break
m=len(sorted(s,key=lambda x:len(x))[-1])
print("*"*m)
for i in range (n):
    print("*")
    s[i].center(m-1," ")
    print("*")


s,n=[],0
while True:
    try:
        s.append(input())
        n+=1
    except EOFError:
        break
m=len(sorted(s,key=lambda x:len(x))[-1])
print(m,n)
for i in range (n):
    if i == 0 or i == (n-1):
        s[i].center(m,"*")
    else :
        print("*")
        s[i].center(m-1," ")
        print("*")


s,n=[],0
while True:
    try:
        s.append(input())
        n+=1
    except EOFError:
        break
m=len(sorted(s,key=lambda x:len(x))[-1])
print("*"*m)
for i in range (n):
    print("*",end="")
    s[i].center(m-1," ")
    print("*")
print("*"*m)


s,n=[],0
while True:
    try:
        s.append(input())
        n+=1
    except EOFError:
        break
m=len(sorted(s,key=lambda x:len(x))[-1])
f=0
print("*"*(m+2))
for i in range (n):
    print("*",end="")
    x=len(s[i])
    if (m-x)%2!=0 and f==0:
        print(" "*int((m-x)+1/2),end="")
        f=1
    else:
        print(" "*int((m-x))/2,end="")
        f=1
    print(s[i],end="")
    if (m-x)%2!=0 and f==1:
        print(" "*int((m-x)+1/2),end="")
        f=0
    else :
        print(" "*int((m-x))/2,end="")
        f=0
    print("*")
print("*"*(m+2))


s,n=[],0
while True:
    try:
        s.append(input())
        n+=1
    except EOFError:
        break
m=len(sorted(s,key=lambda x:len(x))[-1])
f=0
print("*"*(m+2))
for i in range (n):
    x=len(s[i])
    print("*",end="")
    if (m-x)%2!=0 and f==0:
        print(" "*int((m-x+1)/2),end="")
        print(s[i],end="")
        print(" "*int((m-x)/2),end="")
        f=1
    elif (m-x)%2!=0 and f==1:
        print(" "*int((m-x)/2),end="")
        print(s[i],end="")
        print(" "*int((m-x+1)/2),end="")
        f=0
    else :
        print(" "*int((m-x)/2),end="")
        print(s[i],end="")
        print(" "*int((m-x)/2),end="")
    print("*")
print("*"*(m+2))


s,n=[],0
while True:
    try:
        s.append(input())
        n+=1
    except EOFError:
        break
m=len(sorted(s,key=lambda x:len(x))[-1])
print("*"*m)
for i in range (n):
    print("*",end="")
    x=len(s[i])
    if (m-x)%2==0:
        print(" "*(m-x+1),end="")
    else :
        print(" "*(m-x),end="")
    print(s[i],end="")
    print(" "*(m-x))
    print("*")
print("*"*m)


from sys import stdin
from math import ceil, floor

doc = [line.strip() for line in stdin]
max_len = max(len(line) for line in doc)
counter = 1
print('*' * (max_len+2))
for line in doc:
    line_diff = (max_len-len(line))//2
    if (max_len-len(line)) % 2 != 0:
        counter = 1-counter
        pre_space, post_space = (line_diff+counter, line_diff+(1-counter))
    else:
        pre_space, post_space = (line_diff, line_diff)

    print('*' + ' ' * pre_space + line + ' ' * post_space + '*')

print('*' * (max_len+2))


from sys import stdin
max_len = 0
empty_lines = 0
lines = []
for i in range(1000):
    line = stdin.readline().strip()
    if not line:
        empty_lines += 1
        continue
    if empty_lines:
        for i in range(empty_lines): lines.append('')
        empty_lines = 0
    lines.append(line)
    if len(line) > max_len: max_len = len(line)
if empty_lines:
    for i in range(empty_lines): lines.append('')
left = True
print('*' * (max_len + 2))
for line in lines:
    half = (max_len - len(line)) // 2
    if max_len - len(line) & 1:
        temp = half * ' ' + line + (half + 1) * ' ' if left else (half + 1) * ' ' + line + half * ' '
        print('*%s*' %(temp))
        left = not left
    else:
        print('*%s*' %(half * ' ' + line + half * ' '))
print('*' * (max_len + 2))


from sys import stdin
max_len = 0
empty_lines = 0
lines = []
for i in range(1000):
    line = stdin.readline()
    if not line: break
    lines.append(line.strip())
    if len(line) > max_len: max_len = len(line)
left = True
print('*' * (max_len + 2))
for line in lines:
    half = (max_len - len(line)) // 2
    if max_len - len(line) & 1:
        temp = half * ' ' + line + (half + 1) * ' ' if left else (half + 1) * ' ' + line + half * ' '
        print('*%s*' %(temp))
        left = not left
    else:
        print('*%s*' %(half * ' ' + line + half * ' '))
print('*' * (max_len + 2))


from sys import stdin
max_len = 0
empty_lines = 0
lines = []
for i in range(1000):
    line = stdin.readline().strip()
    if not line:
        empty_lines += 1
        continue
    if empty_lines:
        for i in range(empty_lines): lines.append('')
        empty_lines = 0
    lines.append(line)
    if len(line) > max_len: max_len = len(line)
left = True
print('*' * (max_len + 2))
for line in lines:
    half = (max_len - len(line)) // 2
    if max_len - len(line) & 1:
        temp = half * ' ' + line + (half + 1) * ' ' if left else (half + 1) * ' ' + line + half * ' '
        print('*%s*' %(temp))
        left = not left
    else:
        print('*%s*' %(half * ' ' + line + half * ' '))
print('*' * (max_len + 2))


from sys import stdin
lines = [i.strip() for i in stdin.readlines()]
max_len = max(lines, len)
print('*' * (max_len + 2))
for line in lines: print('*%s*' %(line.center(max_len)))
print('*' * (max_len + 2))


from sys import stdin
max_len = 2
empty_lines = 0
lines = []
for i in range(5):
    line = stdin.readline()
    if not line: break
    lines.append(line.strip())
    if len(line) > max_len: max_len = len(line)
left = True
print('*' * (max_len + 2))
for line in lines:
    half = (max_len - len(line)) // 2
    if max_len - len(line) & 1:
        temp = half * ' ' + line + (half + 1) * ' ' if left else (half + 1) * ' ' + line + half * ' '
        print('*%s*' %(temp))
        left = not left
    else:
        print('*%s*' %(half * ' ' + line + half * ' '))
print('*' * (max_len + 2))


from sys import stdin
max_len = 0
lines = []
for i in range(1000):
    line = stdin.readline().strip()
    if not line:
        line = stdin.readline().strip()
        if not line: break
        lines.append('')
    lines.append(line)
    if len(line) > max_len: max_len = len(line)
left = True
print('*' * (max_len + 2))
for line in lines:
    half = (max_len - len(line)) // 2
    if max_len - len(line) & 1:
        temp = half * ' ' + line + (half + 1) * ' ' if left else (half + 1) * ' ' + line + half * ' '
        print('*%s*' %(temp))
        left = not left
    else:
        print('*%s*' %(half * ' ' + line + half * ' '))
print('*' * (max_len + 2))


from sys import stdin
max_len = 0
lines = []
for i in range(1000):
    line = stdin.readline().strip()
    if not line: break
    lines.append(line)
    if len(line) > max_len: max_len = len(line)
print('*' * (max_len + 2))
for line in lines: print('*%s*' %(line.center(max_len)))
print('*' * (max_len + 2))


from sys import stdin
max_len = 2
empty_lines = 0
lines = 0
with open('test.txt', encoding='utf-8') as f:
    print(f.readlines())
    lines = [line.strip() for line in f.readlines()]
for i in range(1000):
    line = stdin.readline()
    if not line: break
    lines.append(line.strip())
    if len(line) > max_len: max_len = len(line)
left = True
print('*' * (max_len + 2))
for line in lines:
    half = (max_len - len(line)) // 2
    if max_len - len(line) & 1:
        temp = half * ' ' + line + (half + 1) * ' ' if left else (half + 1) * ' ' + line + half * ' '
        print('*%s*' %(temp))
        left = not left
    else:
        print('*%s*' %(half * ' ' + line + half * ' '))
print('*' * (max_len + 2))


from sys import stdin
max_len = 0
empty_lines = 0
lines = []
for i in range(1000):
    line = stdin.readline().strip()
    if not line:
        empty_lines += 1
        continue
    if empty_lines:
        for i in range(empty_lines): lines.append('')
    lines.append(line)
    if len(line) > max_len: max_len = len(line)
left = True
print('*' * (max_len + 2))
for line in lines:
    half = (max_len - len(line)) // 2
    if max_len - len(line) & 1:
        temp = half * ' ' + line + (half + 1) * ' ' if left else (half + 1) * ' ' + line + half * ' '
        print('*%s*' %(temp))
        left = not left
    else:
        print('*%s*' %(half * ' ' + line + half * ' '))
print('*' * (max_len + 2))


from sys import stdin
max_len = 0
empty_lines = 0
lines = []
for i in range(1000):
    line = stdin.readline()
    if not line: break
    lines.append(line.strip())
    if len(line.strip()) > max_len:
        max_len = len(line.strip())
left = True
print('*' * (max_len + 2))
for line in lines:
    half = (max_len - len(line)) // 2
    if max_len - len(line) & 1:
        temp = half * ' ' + line + (half + 1) * ' ' if left else (half + 1) * ' ' + line + half * ' '
        print('*%s*' %(temp))
        left = not left
    else:
        print('*%s*' %(half * ' ' + line + half * ' '))
print('*' * (max_len + 2))


from sys import stdin
max_len = 0
lines = []
for i in range(1000):
    line = stdin.readline().strip()
    if not line:
        line = stdin.readline().strip()
        if not line: break
    lines.append(line)
    if len(line) > max_len: max_len = len(line)
print('*' * (max_len + 2))
for line in lines: print('*%s*' %(line.center(max_len)))
print('*' * (max_len + 2))


from sys import stdin
max_len = 0
lines = []
for i in range(1000):
    line = stdin.readline().strip()
    if not line:
        line = stdin.readline().strip()
        if not line: break
        lines.append('')
    lines.append(line)
    if len(line) > max_len: max_len = len(line)
print('*' * (max_len + 2))
for line in lines: print('*%s*' %(line.center(max_len)))
print('*' * (max_len + 2))


from sys import stdin
from math import ceil, floor

doc = [line.strip() for line in stdin]
max_len = max(len(line) for line in doc)
print('*' * (max_len+2))
for line in doc:
    line_diff = max_len-len(line)
    pre_space = line_diff//2 if line_diff % 2 == 0 else (line_diff//2)+1
    post_space = line_diff//2

    print('*' + ' ' * pre_space + line + ' ' * post_space + '*')

print('*' * (max_len+2))


from sys import stdin
from math import ceil, floor

doc = [line.strip() for line in stdin]
max_len = max(len(line) for line in doc)
print('*' * (max_len+2))
for line in doc:
    line_diff = max_len-len(line)
    print('*'+(' ' * ceil(line_diff/2)) +
          line + (' ' * floor(line_diff/2)) + '*')

print('*' * (max_len+2))


from sys import stdin
from math import ceil, floor

doc = [line.strip() for line in stdin]
max_len = max(len(line) for line in doc)
counter = 0
print('*' * (max_len+2))
for line in doc:
    line_diff = (max_len-len(line))//2
    if (max_len-len(line)) % 2 != 0:
        counter = 1-counter
        pre_space, post_space = (line_diff+counter, line_diff+(1-counter))
    else:
        pre_space, post_space = (line_diff, line_diff)

    print('*' + ' ' * pre_space + line + ' ' * post_space + '*')

print('*' * (max_len+2))


from sys import stdin
from math import ceil, floor

doc = [line.strip() for line in stdin]
max_len = max(len(line) for line in doc)
print('*' * (max_len+2))
for line in doc:
    line_diff = max_len-len(line)
    post_space = line_diff//2 if line_diff % 2 == 0 else (line_diff//2)+1
    pre_space = line_diff//2

    print('*' + ' ' * pre_space + line + ' ' * post_space + '*')

print('*' * (max_len+2))


import sys
a = [l.strip() for l in sys.stdin]
w,c = max(len(l) for l in a), 0
print('*' * (w+2))
for l in a:
    s = [(w-len(l))//2] * 2
    if len(l) % 2 != w % 2:
        c = 1-c
        s[c] += 1
    print('*'+' '*s[0] + l + ' '*s[1] +'*')
print('*' * (w+2))


import sys

txt = [line.strip() for line in sys.stdin]
maxLen = max( [len(line) for line in txt] )
#print(txt)
print('*' * (maxLen+2))

flag = 1
for line in txt:
    #print(line)
    a = maxLen - len(line)
    if a % 2 != 0:
        if flag:
            b = a // 2
        else:
            b = a // 2 + 1
        flag = 1 - flag
    else:
        b = a // 2
    #print(a, b)
    print('*' + ' ' * b + line + ' ' * (a-b) + '*')

print('*' * (maxLen+2))