#include <iostream>
#include <map>
using namespace std;

int n;
pair<int, int> stamp[100000];
map<int, bool> used;
map<int, int> adj;
map<int, int> cnt;
int st = -1, fin = -1;

int main()
{
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> stamp[i].first >> stamp[i].second;
        if (!used[stamp[i].first])
        {
            used[stamp[i].first] = true;
            adj[stamp[i].first] = stamp[i].second;
        }
        else
        {
            used[stamp[i].second] = true;
            adj[stamp[i].second] = stamp[i].first;
        }
        ++cnt[stamp[i].first];
        ++cnt[stamp[i].second];
    }
    for (map<int, int>::iterator it = cnt.begin(); it != cnt.end(); ++it)
    {
        if (it->second == 1)
            if (st < 0)
                st = it->first;
            else fin = it->first;
    }
    if (!adj[st])
        swap(st, fin);
    int x = st;
    while (x)
    {
        printf("%d ", x);
        x = adj[x];
    }
    puts("");
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;

const int MAXN = 200020 + 1;

pair <int, int> stamp[MAXN];
int n, dis0, dis[MAXN];
vector <int> edge[MAXN];

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &stamp[i].first, &stamp[i].second);
		dis[i << 1] = stamp[i].first;
		dis[(i << 1) | 1] = stamp[i].second;
	}
	sort(dis, dis + (n << 1));
	dis0 = unique(dis, dis + (n << 1)) - dis;
	for (int i = 0; i < n; i++) {
		int x = lower_bound(dis, dis + dis0, stamp[i].first) - dis;
		int y = lower_bound(dis, dis + dis0, stamp[i].second) - dis;
		edge[x].push_back(y);
		edge[y].push_back(x);
	}
	int st = 0;
	for (int i = 0; i < n; i++) {
		if ((int)edge[i].size() == 1) {
			st = i;
			break;
		}
	}
	printf("%d ", dis[st]);
	int pre = -1;
	for (int i = n - 1; i >= 0; i--) {
		for (int j = 0; j < (int)edge[st].size(); j++) {
			if (edge[st][j] == pre) continue;
			pre = st;
			st = edge[st][j];
			break;
		}
		printf("%d%c", dis[st], i ? ' ' : '\n');
	}
	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <iomanip>

using namespace std;

//#define DBG

vector <int> edge[100010];

int main() {
#ifdef DBG
	freopen ("input.txt", "r", stdin);
	freopen ("output.txt", "w", stdout);
#endif
	int n;
	int mm = 0;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int u, v;
		cin >> u >> v;
		mm = max(mm, max(u, v));
		edge[u].push_back(v);
		edge[v].push_back(u);
	}
	int st = 0;
	for (int i = 0; i <= mm; ++i) {
		if (edge[i].size() == 1)
			st = i;
	}
	int ct = 0;
	while (ct != n - 1) {
		cout << st << ' ';
		int next = edge[st][0];
		if (edge[next][0] == st) {
			edge[next][0] = edge[next][1];
		}
		++ct;
		st = next;

	}
	cout << st << ' ' << edge[st][0];
	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <utility>

using namespace std;

//#define DBG

vector <int> numbers;
int a[100005], b[100005];
vector <int> edge[100005];

int find(int num) {
	int l = 0;
	int r = numbers.size();
	while (r - l > 1) {
		int m = (r + l) / 2;
		if (numbers[m] <= num)
			l = m;
		else
			r = m;
	}
	return l;
}

int main() {
#ifdef DBG
	freopen ("input.txt", "r", stdin);
	freopen ("output.txt", "w", stdout);
#endif
	int n;
	cin >> n;
	for (int i = 0 ;i < n; ++i) {
		cin >> a[i] >> b[i];
		numbers.push_back(a[i]);
		numbers.push_back(b[i]);
	}
	sort (numbers.begin(), numbers.end());
	numbers.erase(unique(numbers.begin(), numbers.end()), numbers.end());
	for (int i = 0; i < n; ++i) {
		int u = find(a[i]);
		int v = find(b[i]);
		edge[u].push_back(v);
		edge[v].push_back(u);
	}
	int s = 0;
	for (int i = 0; i < numbers.size(); ++i) {
		if (edge[i].size() == 1)
			s = i;
	}
	int ct = 0;
	while (ct != n - 1) {
		cout << numbers[s] << ' ';
		int next = edge[s][0];
		if (edge[next][0] == s)
			edge[next][0] = edge[next][1];
		s = next;
		++ct;
	}
	cout << numbers[s] << ' ' << numbers[edge[s][0]];
	return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int i,a[1000000],n,m,x[1000000],y[1000000],k,res[100011],j,kk;
void sort1(int l,int r)
{
 int i,j,xx,yy;
 i=l;j=r;
 xx=x[(i+j)/2];
 while(i<=j)
 {
     while(x[i]<xx)i++;
     while(xx<x[j])j--;
     if(i<=j)
     {
         yy=x[i];x[i]=x[j];x[j]=yy;
         yy=y[i];y[i]=y[j];y[j]=yy;

         i++;j--;
     }
 }
 if(i<r)sort1(i,r);
 if(l<j)sort1(l,j);
}
int f(int l,int r,int ll)
{
	int t;
	t=(l+r)/2;
	if(l==r)return l;else
		if(x[t]>=ll)return f(l,t,ll);else
			return f(t+1,r,ll);
}
int main()
{
   //freopen("input.txt","r",stdin);
   cin>>n;
   m=0;
   for(i=0;i<n;i++){scanf("%d %d",&a[2*i],&a[2*i+1]);m++;x[m]=a[2*i];y[m]=a[2*i+1];m++;x[m]=a[2*i+1];y[m]=a[2*i];}
   sort(a,a+2*n);

   i=0;
   while(i<2*n){if(a[i]!=a[i+1]){kk=i;break;}i+=2;}
   sort1(1,m);

   //for(i=1;i<=m;i++)cout<<x[i]<<" "<<y[i]<<endl;

   res[1]=a[kk];

   for(i=1;i<=n;i++)
   {

	   k=f(1,m,res[i]);
	   //cout<<k<<endl;

	   for(j=k-2;j<=k+2;j++)
		   if(j>=1 && j<=m && y[j]!=res[i] && x[j]==res[i]){kk=j;break;}

	   res[i+1]=y[kk];

   }
   for(i=1;i<=n;i++)printf("%d ",res[i]);
   cout<<res[n+1]<<endl;
}


#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int i,a[1000000],n,m,x[1000000],y[1000000],k,res[100001],j,kk;
void sort1(int l,int r)
{
 int i,j,xx,yy;
 i=l;j=r;
 xx=x[(i+j)/2];
 while(i<=j)
 {
     while(x[i]<xx)i++;
     while(xx<x[j])j--;
     if(i<=j)
     {
         yy=x[i];x[i]=x[j];x[j]=yy;
         yy=y[i];y[i]=y[j];y[j]=yy;

         i++;j--;
     }
 }
 if(i<r)sort1(i,r);
 if(l<j)sort1(l,j);
}
int f(int l,int r,int ll)
{
    int t;
    t=(l+r)/2;
    if(l==r)return l;else
    if(x[t]==ll)return t;else
        if(x[t]>ll)return f(l,t,l);else
            return f(t+1,r,l);
}
int main()
{

   cin>>n;
   m=0;
   for(i=0;i<n;i++){scanf("%d %d\n",&a[2*i],&a[2*i+1]);m++;x[m]=a[2*i];y[m]=a[2*i+1];m++;x[m]=a[2*i+1];y[m]=a[2*i];}
   sort(a,a+2*n);

   i=0;
   while(i<2*n){if(a[i]!=a[i+1]){kk=i;break;}i+=2;}
   sort1(1,m);

   //for(i=1;i<=m;i++)cout<<x[i]<<" "<<y[i]<<endl;

   res[1]=a[kk];

   for(i=1;i<=n;i++)
   {

       k=f(1,m,res[i]);
       //cout<<k<<endl;

       for(j=k-2;j<=k+2;j++)
           if(j>=1 && j<=m && y[j]!=res[i] && x[j]==res[i]){kk=j;break;}

       res[i+1]=y[kk];

   }
   for(i=1;i<=n;i++)printf("%d ",res[i]);
   cout<<res[n+1]<<endl;
}


#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<sstream>
#include<deque>
#include<math.h>
#include<cstring>
#include <bitset>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>

#define all(v) v.begin(),v.end()
#define mpair make_pair

using namespace std;
typedef long double ld;
const ld epsilon = 1e-9;
typedef long long ll;

int main()
{
	//freopen("bobi.in", "r", stdin);
	int n;
	map<int, int> m;
	cin >> n;
	vector<vector<int> > neighbours(n + 1);
	vector<int> rev;
	int x, y;
	int idx = 0;
	int id1, id2;
	for(int i = 0; i < n; i++)
	{
		cin >> x >> y;
		if(m.find(x) == m.end())
		{
			id1 = idx;
			m[x] = idx++;
			rev.push_back(x);
		}
		else
			id1 = m[x];
		if(m.find(y) == m.end())
		{
			id2 = idx;
			m[y] = idx++;
			rev.push_back(y);
		}
		else
			id2 = m[y];

		neighbours[id1].push_back(id2);
		neighbours[id2].push_back(id1);

	}
	vector<int> path;
	vector<int> vis(n + 1, false);
	for(int i = 0; i < n + 1; i++)
	{
		if(neighbours[i].size() == 1)
		{
			idx = i;
			break;
		}
	}

	queue<int> toProcess;
	toProcess.push(idx);
	vis[idx] = true;
	path.push_back(idx);
	int cur;
	while(!toProcess.empty())
	{
		cur = toProcess.front();
		toProcess.pop();

		for(int i = 0; i < neighbours[cur].size(); i++)
		{
			if(!vis[neighbours[cur][i]])
			{
				vis[neighbours[cur][i]] = true;
				path.push_back(neighbours[cur][i]);
				toProcess.push(neighbours[cur][i]);
			}
		}
	}
	cout << rev[path[0]];
	for(int i = 1; i < n + 1; i++)
	{
		printf(" %d", rev[path[i]]);
	}
	cout << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <map>

using namespace std;

int stamp[100010][4] = {0};

void _insert(int a, int b);

int main()
{
	int n;
	int i;
	int a, b;
	cin >> n;
	for (i = 0; i < n; i++)
	{
		cin >> a >> b;
		_insert(a, b);

	}
	int pos,tmppos;
	for (int i = 0; i < 100010; i++)
	{
		if (stamp[i][3] == 1)
		{
			pos = i;
			break;
		}

	}
	for (i = 1; i <= n + 1; i++)
	{
		printf("%d ", stamp[pos][0]);
		tmppos = pos;
		if (stamp[tmppos][1] != -1)
		{

			pos = stamp[tmppos][1];
			if (stamp[pos][1] == tmppos)
			{
				stamp[pos][1] = -1;
			}
			else
			{
				stamp[pos][2] = -1;
			}
		}
		else if (stamp[tmppos][2] != -1)
		{
			pos = stamp[tmppos][2];
			if (stamp[pos][1] == tmppos)
			{
				stamp[pos][1] = -1;
			}
			else
			{
				stamp[pos][2] = -1;
			}
		}
	}
	return 0;
}

void _insert(int a, int b)
{
	int i=0;
	int flag1 = -1;
	int flag2 = -1;
	for (i = 0; i < 100010; i++)
	{
		if (stamp[i][0] == 0)
			break;
		if (stamp[i][0] == a)
			flag1 = i;
		if (stamp[i][0] == b)
			flag2 = i;
		if (flag1 != -1 && flag2 != -1)
			break;
	}

	if (flag1 == -1)
	{
		flag1 = i;
		stamp[flag1][0] = a;
		stamp[flag1][1] = -1;
		stamp[flag1][2] = -1;
		i++;
	}
	if (flag2 == -1)
	{
		flag2 = i;
		stamp[flag2][0] = b;
		stamp[flag2][1] = -1;
		stamp[flag2][2] = -1;
	}

	if (stamp[flag1][3] == 0)
	{
		stamp[flag1][1] = flag2;
		stamp[flag1][3]++;
	}
	else if (stamp[flag1][3] == 1)
	{
		stamp[flag1][2] = flag2;
		stamp[flag1][3]++;
	}
	else
	{
	//	printf("68 -- ���������⣡");
	}

	if (stamp[flag2][3] == 0)
	{
		stamp[flag2][1] = flag1;
		stamp[flag2][3]++;
	}
	else if (stamp[flag2][3] == 1)
	{
		stamp[flag2][2] = flag1;
		stamp[flag2][3]++;
	}
	else
	{
	//	printf("110 -- ���������⣡");
	}
}


#include <iostream>
#include <vector>
#include <set>
#include <map>

using namespace std;

int stamp[10010][4] = {0};

void _insert(int a, int b);

int main()
{
	int n;
	int i;
	int a, b;
	cin >> n;
	for (i = 0; i < n; i++)
	{
		cin >> a >> b;
		_insert(a, b);

	}
	int pos;
	for (int i = 0; i < 10010; i++)
	{
		if (stamp[i][3] == 1)
		{
			pos = i;
			break;
		}

	}
	for (i = 1; i <= n + 1; i++)
	{
		printf("%d ", stamp[pos][0]);
		if (stamp[pos][1] != -1)
		{
			pos = stamp[pos][1];
			stamp[pos][1] = -1;
		}
		else if (stamp[pos][2] != -1)
		{
			pos = stamp[pos][2];
			stamp[pos][2] = -1;
		}
	}
	return 0;
}

void _insert(int a, int b)
{
	int i=0;
	int flag1 = -1;
	int flag2 = -1;
	for (i = 0; i < 10010; i++)
	{
		if (stamp[i][0] == 0)
			break;
		if (stamp[i][0] == a)
			flag1 = i;
		if (stamp[i][0] == b)
			flag2 = i;
		if (flag1 != -1 && flag2 != -1)
			break;
	}

	if (flag1 == -1)
	{
		flag1 = i;
		stamp[flag1][0] = a;
		i++;
	}
	if (flag2 == -1)
	{
		flag2 = i;
		stamp[flag2][0] = b;
	}

	if (stamp[flag1][3] == 0)
	{
		stamp[flag1][1] = flag2;
		stamp[flag1][3]++;
	}
	else if (stamp[flag1][3] == 1)
	{
		stamp[flag1][2] = flag2;
		stamp[flag1][3]++;
	}
	else
	{
		printf("68 -- ���������⣡");
	}

	if (stamp[flag2][3] == 0)
	{
		stamp[flag2][1] = flag1;
		stamp[flag2][3]++;
	}
	else if (stamp[flag2][3] == 1)
	{
		stamp[flag2][2] = flag1;
		stamp[flag2][3]++;
	}
	else
	{
		printf("110 -- ���������⣡");
	}
}


#include <iostream>
#include <vector>
#include <set>
#include <map>

using namespace std;

int stamp[100010][4] = {0};

void _insert(int a, int b);

int main()
{
	int n;
	int i;
	int a, b;
	cin >> n;
	for (i = 0; i < n; i++)
	{
		cin >> a >> b;
		_insert(a, b);

	}
	int pos,tmppos;
	for (int i = 0; i < 100010; i++)
	{
		if (stamp[i][3] == 1)
		{
			pos = i;
			break;
		}

	}
	for (i = 1; i <= n + 1; i++)
	{
		printf("%d ", stamp[pos][0]);
		tmppos = pos;
		if (stamp[tmppos][1] != -1)
		{

			pos = stamp[tmppos][1];
			if (stamp[pos][1] == tmppos)
			{
				stamp[pos][1] = -1;
			}
			else
			{
				stamp[pos][2] = -1;
			}
		}
		else if (stamp[tmppos][2] != -1)
		{
			pos = stamp[tmppos][2];
			if (stamp[pos][1] == tmppos)
			{
				stamp[pos][1] = -1;
			}
			else
			{
				stamp[pos][2] = -1;
			}
		}
	}
	return 0;
}

void _insert(int a, int b)
{
	int i=0;
	int flag1 = -1;
	int flag2 = -1;
	for (i = 0; i < 10010; i++)
	{
		if (stamp[i][0] == 0)
			break;
		if (stamp[i][0] == a)
			flag1 = i;
		if (stamp[i][0] == b)
			flag2 = i;
		if (flag1 != -1 && flag2 != -1)
			break;
	}

	if (flag1 == -1)
	{
		flag1 = i;
		stamp[flag1][0] = a;
		stamp[flag1][1] = -1;
		stamp[flag1][2] = -1;
		i++;
	}
	if (flag2 == -1)
	{
		flag2 = i;
		stamp[flag2][0] = b;
		stamp[flag2][1] = -1;
		stamp[flag2][2] = -1;
	}

	if (stamp[flag1][3] == 0)
	{
		stamp[flag1][1] = flag2;
		stamp[flag1][3]++;
	}
	else if (stamp[flag1][3] == 1)
	{
		stamp[flag1][2] = flag2;
		stamp[flag1][3]++;
	}
	else
	{
	//	printf("68 -- ���������⣡");
	}

	if (stamp[flag2][3] == 0)
	{
		stamp[flag2][1] = flag1;
		stamp[flag2][3]++;
	}
	else if (stamp[flag2][3] == 1)
	{
		stamp[flag2][2] = flag1;
		stamp[flag2][3]++;
	}
	else
	{
	//	printf("110 -- ���������⣡");
	}
}


#include <iostream>
#include <map>
#include <vector>

using namespace std;

#define mm  100010

vector<int> g[mm];
int via[mm];
map<int, int> mp;
int f[mm];
int pos;

bool dfs(int u, int n)
{
	if (n == pos){
		printf("%d ", f[u]); return 1;
	}
	for (int i = 0; i < g[u].size(); i++)
	{
		if (!via[g[u][i]])
		{
			via[g[u][i]] = 1;
			dfs(g[u][i], n + 1);
			printf("%d ", f[u]);
			return 1;
		}
	}
}

int main()
{
	int n;
	cin >> n;
	int a, b;
	int i;
	pos = 0;
	mp.clear();
	for (int i = 0; i < mm; i++)
	{
		g[i].clear();
	}
	for(i = 0; i < n; i++)
	{
		cin >> a >> b;
		if (mp[a] == 0) mp[a] = ++pos, f[pos] = a;
		if (mp[b] == 0)  mp[b] = ++pos, f[pos] = b;
		g[mp[a]].push_back(mp[b]);
		g[mp[b]].push_back(mp[a]);
	}
	int tmppos = 1;
	for (i = 1; i <= pos; i++)
	{
		if (g[i].size() == 1)
		{
			tmppos = i;
			break;
		}
	}
	via[tmppos] = 1;
	dfs(tmppos, 1);
}


#include <iostream>
#include <vector>
#include <set>
#include <map>

using namespace std;

int stamp[100010][4] = {0};

void _insert(int a, int b);

int main()
{
	int n;
	int i;
	int a, b;
	cin >> n;
	for (i = 0; i < n; i++)
	{
		cin >> a >> b;
		_insert(a, b);

	}
	int pos,tmppos;
	for (int i = 0; i < 10010; i++)
	{
		if (stamp[i][3] == 1)
		{
			pos = i;
			break;
		}

	}
	for (i = 1; i <= n + 1; i++)
	{
		printf("%d ", stamp[pos][0]);
		tmppos = pos;
		if (stamp[tmppos][1] != -1)
		{

			pos = stamp[tmppos][1];
			if (stamp[pos][1] == tmppos)
			{
				stamp[pos][1] = -1;
			}
			else
			{
				stamp[pos][2] = -1;
			}
		}
		else if (stamp[tmppos][2] != -1)
		{
			pos = stamp[tmppos][2];
			if (stamp[pos][1] == tmppos)
			{
				stamp[pos][1] = -1;
			}
			else
			{
				stamp[pos][2] = -1;
			}
		}
	}
	return 0;
}

void _insert(int a, int b)
{
	int i=0;
	int flag1 = -1;
	int flag2 = -1;
	for (i = 0; i < 10010; i++)
	{
		if (stamp[i][0] == 0)
			break;
		if (stamp[i][0] == a)
			flag1 = i;
		if (stamp[i][0] == b)
			flag2 = i;
		if (flag1 != -1 && flag2 != -1)
			break;
	}

	if (flag1 == -1)
	{
		flag1 = i;
		stamp[flag1][0] = a;
		stamp[flag1][1] = -1;
		stamp[flag1][2] = -1;
		i++;
	}
	if (flag2 == -1)
	{
		flag2 = i;
		stamp[flag2][0] = b;
		stamp[flag2][1] = -1;
		stamp[flag2][2] = -1;
	}

	if (stamp[flag1][3] == 0)
	{
		stamp[flag1][1] = flag2;
		stamp[flag1][3]++;
	}
	else if (stamp[flag1][3] == 1)
	{
		stamp[flag1][2] = flag2;
		stamp[flag1][3]++;
	}
	else
	{
		printf("68 -- ���������⣡");
	}

	if (stamp[flag2][3] == 0)
	{
		stamp[flag2][1] = flag1;
		stamp[flag2][3]++;
	}
	else if (stamp[flag2][3] == 1)
	{
		stamp[flag2][2] = flag1;
		stamp[flag2][3]++;
	}
	else
	{
		printf("110 -- ���������⣡");
	}
}


#include <iostream>
#include <vector>
#include <set>
#include <map>

using namespace std;

int stamp[10010][4] = {0};

void _insert(int a, int b);

int main()
{
	int n;
	int i;
	int a, b;
	cin >> n;
	for (i = 0; i < n; i++)
	{
		cin >> a >> b;
		_insert(a, b);

	}
	int pos,tmppos;
	for (int i = 0; i < 10010; i++)
	{
		if (stamp[i][3] == 1)
		{
			pos = i;
			break;
		}

	}
	for (i = 1; i <= n + 1; i++)
	{
		printf("%d ", stamp[pos][0]);
		tmppos = pos;
		if (stamp[tmppos][1] != -1)
		{

			pos = stamp[tmppos][1];
			if (stamp[pos][1] == tmppos)
			{
				stamp[pos][1] = -1;
			}
			else
			{
				stamp[pos][2] = -1;
			}
		}
		else if (stamp[tmppos][2] != -1)
		{
			pos = stamp[tmppos][2];
			if (stamp[pos][1] == tmppos)
			{
				stamp[pos][1] = -1;
			}
			else
			{
				stamp[pos][2] = -1;
			}
		}
	}
	return 0;
}

void _insert(int a, int b)
{
	int i=0;
	int flag1 = -1;
	int flag2 = -1;
	for (i = 0; i < 10010; i++)
	{
		if (stamp[i][0] == 0)
			break;
		if (stamp[i][0] == a)
			flag1 = i;
		if (stamp[i][0] == b)
			flag2 = i;
		if (flag1 != -1 && flag2 != -1)
			break;
	}

	if (flag1 == -1)
	{
		flag1 = i;
		stamp[flag1][0] = a;
		stamp[flag1][1] = -1;
		stamp[flag1][2] = -1;
		i++;
	}
	if (flag2 == -1)
	{
		flag2 = i;
		stamp[flag2][0] = b;
		stamp[flag2][1] = -1;
		stamp[flag2][2] = -1;
	}

	if (stamp[flag1][3] == 0)
	{
		stamp[flag1][1] = flag2;
		stamp[flag1][3]++;
	}
	else if (stamp[flag1][3] == 1)
	{
		stamp[flag1][2] = flag2;
		stamp[flag1][3]++;
	}
	else
	{
		printf("68 -- ���������⣡");
	}

	if (stamp[flag2][3] == 0)
	{
		stamp[flag2][1] = flag1;
		stamp[flag2][3]++;
	}
	else if (stamp[flag2][3] == 1)
	{
		stamp[flag2][2] = flag1;
		stamp[flag2][3]++;
	}
	else
	{
		printf("110 -- ���������⣡");
	}
}


#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<map>
#include<string>
#include<string.h>
#include<vector>
#include<stdio.h>
#include <cstdio>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <sstream>
#include <cmath>
#include <bitset>
#include <limits.h>
#include <limits>
#include <utility>
#include <time.h>
#include <set>
#include <numeric>
#include <functional>
#define LL long long int
#define R(i) freopen(i,"r",stdin)
#define W(i) freopen(i,"w",stdout)
#define R_W R("i.txt"),W("o.txt");
#define FOR(i,f,t) for(int i=f;i<t;i++)
#define r(e) for(int i=0;i<e;i++)
#define oo (LL)numeric_limits<int>::max()
#define readVector(n,in,v) r(n){cin>>in;v.push_back(in);}
#define readGrid(n,m,data) r(n)FOR(j,0,m){cin>>data[i][j];}
#define DFS_WHITE -1
#define DFS_GRAY 0
#define DFS_BLACK 1
#define pp pair<bool,bool>
#define all(x) x.begin(),x.end()
using namespace std;
#define vi vector<int>
typedef pair<int, int> ii;
#define  vii vector< ii >
vector< vi > g;
map<int,int> table;
map<int,int> retable;
 int v=0;
int idx(int u){
    if(!table.count(u)){
           table[u]=v;
           retable[v++]=u;
           g.push_back(vi());
    }
    return table[u];
}
int main(){
   ///R_W;
   int n;
   cin>>n;
   g.assign(n,vi());
   int  start=0;
   map<int,int> counter;
   r(n){
       int from,to;
       cin>>from>>to;
       counter[from]++;
       counter[to]++;
       if(counter[from]==1)start=from;
       else if(counter[to]==1) start=to;
       int u=idx(from);
       int v=idx(to);
       if(v<u) swap(u,v);
       g[u].push_back(v);
       g[v].push_back(u);
   }
   int s=table[start];
   queue<int> q;
   q.push(s);
   map<int,int>dist;
   cout<<start;
   while(q.size()){
       int u=q.front();
       if(u!=s) cout<<" "<<retable[u];
       q.pop();
       for(int i=0;i<g[u].size();i++)
       {
           int v=g[u][i];
           if(!dist.count(v)){
               dist[v]=dist[u]+1;
               q.push(v);
           }
       }
   }
   cout<<endl;
   return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<map>
#include<string>
#include<string.h>
#include<vector>
#include<stdio.h>
#include <cstdio>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <sstream>
#include <cmath>
#include <bitset>
#include <limits.h>
#include <limits>
#include <utility>
#include <time.h>
#include <set>
#include <numeric>
#include <functional>
#define LL long long int
#define R(i) freopen(i,"r",stdin)
#define W(i) freopen(i,"w",stdout)
#define R_W R("i.txt"),W("o.txt");
#define FOR(i,f,t) for(int i=f;i<t;i++)
#define r(e) for(int i=0;i<e;i++)
#define oo (LL)numeric_limits<int>::max()
#define readVector(n,in,v) r(n){cin>>in;v.push_back(in);}
#define readGrid(n,m,data) r(n)FOR(j,0,m){cin>>data[i][j];}
#define DFS_WHITE -1
#define DFS_GRAY 0
#define DFS_BLACK 1
#define pp pair<bool,bool>
#define all(x) x.begin(),x.end()
using namespace std;
#define vi vector<int>
typedef pair<int, int> ii;
#define  vii vector< ii >
vector< vi > g;
map<int,int> table;
map<int,int> retable;
 int v=0;
 vi data;
int idx(int u){
    if(!table.count(u)){
           table[u]=v;
           retable[v++]=u;
           g.push_back(vi());
           data.push_back(u);
    }
    return table[u];
}
int main(){
   /////R_W;
   int n;
   cin>>n;
   g.assign(n,vi());
   int  start=0;
   map<int,int> counter;

   r(n){
       int from,to;
       cin>>from>>to;
       counter[from]++;
       counter[to]++;

       int u=idx(from);
       int v=idx(to);
       if(v<u) swap(u,v);
       g[u].push_back(v);
       g[v].push_back(u);
   }
   r(data.size()){
       if(counter[data[i]]==1){
           start=data[i];
           break;
       }
   }
   int s=table[start];
   queue<int> q;
   q.push(s);
   map<int,int>dist;
   cout<<start;
   while(q.size()){
       int u=q.front();
       if(u!=s) cout<<" "<<retable[u];
       q.pop();
       for(int i=0;i<g[u].size();i++)
       {
           int v=g[u][i];
           if(!dist.count(v)){
               dist[v]=dist[u]+1;
               q.push(v);
           }
       }
   }
   cout<<endl;
   return 0;
}


#include<iostream>
#include<utility>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
  int n;
  cin>>n;
  map<long int,long int>m1;
  map<long int,long int>m2;
  int x,y;
 for(int i=0;i<n;i++)
  {
      cin>>x>>y;
      if(m1[x]==0){
        m1[x]=y;
        m2[x]=-1;
        }
        else
       m2[x]=y;
      if(m1[y]==0){
        m1[y]=x;
        m2[y]=-1;
        }
        else
       m2[y]=x;

  }

       map<long int,long int>::iterator it;
     map<long int,long int>::iterator t=m2.begin();
    int hold;
    for(it=m1.begin();it!=m1.end();it++)
    {
        if(it->second==-1)
        {
            hold=it->first;
            break;
        }
        if(t->second==-1)
        {
            hold=t->first;
            break;
        }
        t++;
    }
    int temp;

    cout<<hold<<" ";
    if(m1[hold]!=0){
        cout<<m1[hold]<<" ";
        temp=m1[hold];
        }
        else {cout<<m2[hold]<<" ";
        temp=m2[hold];}
    for(int i=1;i<n;i++)
    {
       if(m1[temp]!=hold){
        cout<<m1[temp]<<" ";
        hold=temp;
        temp=m1[temp];

        }
       else {
        cout<<m2[temp]<<" ";
        hold=temp;
        temp=m2[temp];

        }

    }
        }


#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<iostream>
#include<string>
#include<cstdlib>
#include<iomanip>
#include<iterator>
#include<utility>
#include<algorithm>
#include<set>
#include<cmath>
#include<sstream>
#include<queue>
using namespace std;

void dfs(long long int node, map<long long int, vector<long long int>>v,map<long long int,int>visited)
{

    visited[node] = 1;
    cout << node << " ";
    for (int i = 0; i < v[node].size(); ++i)
    {
        long long int x = v[node][i];
        if (!visited[x])
        {

            dfs(x, v,visited);
        }
    }

}

int main()
{
    int n;
    cin >> n;
    map<long long int,vector<long long int>>v;
    long long int max = 0;
    long long int x, y;
    for (int i = 0; i < n; ++i)
    {
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);

    }
    long long int node;
    map<long long int, int>visited;
    map<long long int, vector<long long int>>::iterator it;
    for (it = v.begin(); it != v.end(); ++it)
    {

        if (it->second.size() == 1)

            node = it->first;
        if (it->first > max)
            max = it->first;

    }

    dfs(node, v,visited);

}


include<iostream>
#include<vector>
#include<map>
#include<set>
#include<iostream>
#include<string>
#include<cstdlib>
#include<iomanip>
#include<iterator>
#include<utility>
#include<algorithm>
#include<set>
#include<cmath>
#include<sstream>
#include<queue>
using namespace std;

map< long int, int>visited;
void dfs(long int node, map< long int, vector< long int>>v)
{

    visited[node] = 1;
    cout << node << " ";
    for (int i = 0; i < v[node].size(); ++i)
    {
        long long int x = v[node][i];
        if (!visited[x])
        {

            dfs(x, v);
        }
    }

}

int main()
{
    int n;
    cin >> n;
    map< long int,vector< long int>>v;

    for (int i = 0; i < n; ++i)
    {
        long long int x, y;
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);

    }
    long int node;

    map< long int, vector< long int>>::iterator it;
    for (it = v.begin(); it != v.end(); ++it)
    {

        if (it->second.size() == 1){

            node = it->first;
            break;

        }
    }

    dfs(node, v);

}


#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<iostream>
#include<string>
#include<cstdlib>
#include<iomanip>
#include<iterator>
#include<utility>
#include<algorithm>
#include<set>
#include<cmath>
#include<sstream>
#include<queue>
using namespace std;
int visited[1000002] = { 0 };

void dfs(int node, map<int, vector<long long int>>v)
{
    visited[node] = 1;
    cout << node << " ";
    for (int i = 0; i < v[node].size(); ++i)
    {
        long long int x = v[node][i];
        if (!visited[x])
        {

            dfs(x, v);
        }
    }

}

int main()
{
    int n;
    cin >> n;
    map<int,vector<long long int>>v;
    long long int x, y;
    for (int i = 0; i < n; ++i)
    {
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    long long int node;
    map<int, vector<long long int>>::iterator it;
    for (it = v.begin(); it != v.end(); ++it)
    {
        if (it->second.size() == 1)

            node = it->first;

    }

    dfs(node, v);

}


#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<iostream>
#include<string>
#include<cstdlib>
#include<iomanip>
#include<iterator>
#include<utility>
#include<algorithm>
#include<set>
#include<cmath>
#include<sstream>
#include<queue>
using namespace std;

map<long long int, int>visited;
void dfs(long long int node, map<long long int, vector<long long int>>v)
{

    visited[node] = 1;
    cout << node << " ";
    for (int i = 0; i < v[node].size(); ++i)
    {
        long long int x = v[node][i];
        if (!visited[x])
        {

            dfs(x, v);
        }
    }

}

int main()
{
    int n;
    cin >> n;
    map<long long int,vector<long long int>>v;

    for (int i = 0; i < n; ++i)
    {
        long long int x, y;
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);

    }
    long long int node;

    map<long long int, vector<long long int>>::iterator it;
    for (it = v.begin(); it != v.end(); ++it)
    {

        if (it->second.size() == 1){

            node = it->first;
            break;

        }
    }

    dfs(node, v);

}


#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<iostream>
#include<string>
#include<cstdlib>
#include<iomanip>
#include<iterator>
#include<utility>
#include<algorithm>
#include<set>
#include<cmath>
#include<sstream>
#include<queue>
using namespace std;

map<  int, int>visited;
void dfs( int node, map<int, vector<int>>v)
{

    visited[node] = 1;
    cout << node << " ";
    for (int i = 0; i < v[node].size(); ++i)
    {
         long int x = v[node][i];
        if (!visited[x])
        {

            dfs(x, v);
        }
    }

}

int main()
{
    int n;
    cin >> n;
    map<  int,vector<int>>v;

    for (int i = 0; i < n; ++i)
    {
         int x, y;
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);

    }
    long int node;

    map<int, vector<int>>::iterator it;
    for (it = v.begin(); it != v.end(); ++it)
    {

        if (it->second.size() == 1){

            node = it->first;
            break;

        }
    }

    dfs(node, v);

}


#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<iostream>
#include<string>
#include<cstdlib>
#include<iomanip>
#include<iterator>
#include<utility>
#include<algorithm>
#include<set>
#include<cmath>
#include<sstream>
#include<queue>
using namespace std;

map< long int, int>visited;
void dfs(long int node, map< long int, vector< long int>>v)
{

    visited[node] = 1;
    cout << node << " ";
    for (int i = 0; i < v[node].size(); ++i)
    {
         long int x = v[node][i];
        if (!visited[x])
        {

            dfs(x, v);
        }
    }

}

int main()
{
    int n;
    cin >> n;
    map< long int,vector< long int>>v;

    for (int i = 0; i < n; ++i)
    {
        long long int x, y;
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);

    }
    long int node;

    map< long int, vector< long int>>::iterator it;
    for (it = v.begin(); it != v.end(); ++it)
    {

        if (it->second.size() == 1){

            node = it->first;
            break;

        }
    }

    dfs(node, v);

}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory>
#include <queue>
#include <list>
#include <numeric>

using namespace std;

#define MAX 1000000000
#define MIN INT_MIN
#define FOR(i,a,n) for(int i = a; i < n; ++i)
#define ll long long
#define sqr ((x) * (x))
#define pi 3.14159265

vector<int> g[100007];
int cnt[100007];
vector<int> ans;
void dfs(int root,int parent)
{
	ans.push_back(root);
	FOR(i,0,g[root].size())
	{
		int to = g[root][i];
		if(to != parent)
		{
			dfs(to,root);
		}
	}
}

int main()
{
	int n;
	cin>>n;
	map<int,int> mp,rmp;
	map<int,int> :: iterator it;
	int a,b,last = 0;
	FOR(i,0,n)
	{
		cin>>a>>b;
		if(mp.find(a) == mp.end())
		{
			mp[a] = last++;
			rmp[last-1] = a;
		}

		if(mp.find(b) == mp.end())
		{
			mp[b] = last++;
			rmp[last-1] = b;
		}
		g[mp[a]].push_back(mp[b]);
		g[mp[b]].push_back(mp[a]);
		cnt[mp[a]]++;
		cnt[mp[b]]++;
	}

	int st = 0;
	FOR(i,0,last)
	{
		if(cnt[i] == 1)
		{
			st = i;
			break;
		}
	}

	dfs(st,-1);
	FOR(i,0,ans.size())
	{
		cout<<rmp[ans[i]]<<' ';
	}
	cout<<endl;

	return 0;
}


def main():
    count=int(input())
    arr=[]
    for x in range(count):
        store=input().split()
        store[0]=int(store[0])
        store[1]=int(store[1])
        arr.append(store)
        previous=len(arr)-1
        #print(arr)
        while True:
            bo=True
            for y in range(len(arr)):
                if y!=previous:
                    if arr[y][0]==arr[previous][0]:
                        arr[y]=arr[previous][-1:0:-1]+arr[y]
                        del arr[previous]
                        bo=False
                        if y<previous:
                            previous=y
                        else:
                            previous=y-1
                        break
                    elif arr[y][0]==arr[previous][-1]:
                        arr[y]=arr[previous][:-1:1]+arr[y]
                        del arr[previous]
                        bo=False
                        if y<previous:
                            previous=y
                        else:
                            previous=y-1
                        break
                    elif arr[y][-1]==arr[previous][0]:
                        arr[y]=arr[y]+arr[previous][1::1]
                        del arr[previous]
                        bo=False
                        if y<previous:
                            previous=y
                        else:
                            previous=y-1
                        break
                    elif arr[y][-1]==arr[previous][-1]:
                        arr[y]=arr[y]+arr[previous][-2::-1]
                        del arr[previous]
                        bo=False
                        if y<previous:
                            previous=y
                        else:
                            previous=y-1
                        break
            #print(arr)
            if bo or len(arr)==1:
                break
    string=""
    for x in arr[0]:
        string+=str(x)+" "
    print(string)
main()


def main():
    count=int(input())
    arr=[]
    for x in range(count):
        store=input().split()
        store[0]=int(store[0])
        store[1]=int(store[1])
        arr.append(store)
        previous=len(arr)-1
        while True:
            bo=True
            for y in range(len(arr)):
                if y!=previous:
                    if arr[y][0]==arr[previous][0]:
                        arr[y]=arr[previous][-1:0:-1]+arr[y]
                        del arr[previous]
                        bo=False
                        previous=y
                        break
                    elif arr[y][0]==arr[previous][-1]:
                        arr[y]=arr[previous][0::1]+arr[y]
                        del arr[previous]
                        bo=False
                        previous=y
                        break
                    elif arr[y][-1]==arr[previous][0]:
                        arr[y]=arr[y]+arr[previous][1::1]
                        del arr[previous]
                        bo=False
                        previous=y
                        break
                    elif arr[y][-1]==arr[previous][-1]:
                        arr[y]=arr[y]+arr[previous][-1:0:-1]
                        del arr[previous]
                        bo=False
                        previous=y
                        break
            if bo or len(arr)==1:
                break
    string=""
    for x in arr[0]:
        string+=str(x)+" "
    print(string)
main()


n=int(input())
tree={}
for x in range(n):
  arr=input().split()
  arr[0]=int(arr[0])
  arr[1]=int(arr[1])
  if arr[0] in tree:
    tree[arr[0]].append(arr[1])
  else:
    tree[arr[0]]=[arr[1]]
  if arr[1] in tree:
    tree[arr[1]].append(arr[1])
  else:
    tree[arr[1]]=[arr[0]]
#print(tree)

for x in tree:
  if len(tree[x])==1:
    print(x,end=" ")
    nex=tree[x][0]
    pre=x
    while len(tree[nex])!=1:
      print(nex,end=" ")
      if tree[nex][0]!=pre:
        pre,nex=nex,tree[nex][0]
      else:
        pre,nex=nex,tree[nex][1]
    print(nex)
    break


def main():
    count=int(input())
    arr=[]
    for x in range(count):
        store=input().split()
        store[0]=int(store[0])
        store[1]=int(store[1])
        arr.append(store)
        previous=len(arr)-1
        while True:
            bo=True
            for y in range(len(arr)):
                if y!=previous:
                    if arr[y][0]==arr[previous][0]:
                        arr[y]=arr[previous][-1:0:-1]+arr[y]
                        del arr[previous]
                        bo=False
                        previous=y
                        break
                    elif arr[y][0]==arr[previous][-1]:
                        arr[y]=arr[previous][0::1]+arr[y]
                        del arr[previous]
                        bo=False
                        previous=y
                        break
                    elif arr[y][-1]==arr[previous][0]:
                        arr[y]=arr[y]+arr[previous][1::1]
                        del arr[previous]
                        bo=False
                        previous=y
                        break
                    elif arr[y][-1]==arr[previous][-1]:
                        arr[y]=arr[y]+arr[previous][-2::-1]
                        del arr[previous]
                        bo=False
                        previous=y
                        break
            #print(arr)
            if bo or len(arr)==1:
                break
    string=""
    for x in arr[0]:
        string+=str(x)+" "
    print(string)
main()


n=int(input())
tree={}
for x in range(n):
  arr=input().split()
  arr[0]=int(arr[0])
  arr[1]=int(arr[1])
  if arr[0] in tree:
    tree[arr[0]].append(arr[1])
  else:
    tree[arr[0]]=[arr[1]]
  if arr[1] in tree:
    tree[arr[1]].append(arr[0])
  else:
    tree[arr[1]]=[arr[0]]
#print(tree)

for x in tree:
  if len(tree[x])==1:
    print(x,end=" ")
    nex=tree[x][0]
    pre=x
    while len(tree[nex])==2:
      print(nex,end=" ")
      if tree[nex][0]!=pre:
        pre,nex=nex,tree[nex][0]
      else:
        assert pre==tree[nex][0]
        pre,nex=nex,tree[nex][1]
    print(nex)
    break


from collections import defaultdict
from typing import List, Tuple

def solve(n: int, stamps: List[Tuple[int, int]]) -> str:
    visited = set()            # type: Set
    graph = defaultdict(list)  # type: Dict[int, List[int]]
    path = []                  # type: List[int]
    for u, v in stamps:
        graph[u].append(v)
        graph[v].append(u)
    start = [node for node in graph if len(graph[node]) == 1][0]
    stack = [start]
    while stack:
        curr = stack.pop()
        visited.add(curr)
        path.append(curr)
        for adj_node in graph[curr]:
            if adj_node not in visited:
                stack.append(adj_node)
    return ' '.join(map(str, path))

n = int(input())
stamps = [tuple(map(int, input().split())) for _ in range(n)]
print(solve(n, stamps))


dict_route = {}
cnt = int(input("").strip())

for i in range(cnt):
    peer = input("").strip().split()
    for p in peer:
        if not dict_route.get(p):
            dict_route[p] = []
        peer_copy = peer.copy()
        peer_copy.remove(p)
        dict_route[p] += peer_copy

start_end_keys = []
for key, val in dict_route.items():
    if len(val) == 1:
        start_end_keys.append(key)

start_key = start_end_keys[-1]
end_key = start_end_keys[0]

possible_routes = []
while True:
    possible_routes.append(start_key)
    if start_key == end_key:
        break
    next_key = dict_route[start_key][0]
    dict_route[next_key].remove(start_key)
    start_key = next_key

print(' '.join(possible_routes))


from collections import *
d, c =defaultdict(int), []
for i in range(int(input())):
    x, y = map(int, input().split())
    c += [x, y]
    d[x] += y
    d[y] += x
a, b = [q for q, k in Counter(c).items() if k == 1]
q = 0
while a != b:
    print(a)
    q, a = a, d[a] - q
print(a)


from collections import *
d, c = defaultdict(int), []
for i in range(int(input())):
    x, y = map(int, input().split())
    c += [x, y]
    d[x] += y
    d[y] += x
a, b = [q for q, k in Counter(c).items() if k == 1]
q = 0
while a != b:
    print(a)
    q, a = a, d[a] - q
print(a)


n=int(input())
d={}
for i in range(n):
    a,b=map(int,input().split())
    if a in d:
        d[a].append(b)
    else:
        d[a]=[b]
    if b in d:
        d[b].append(a)
    else:
        d[b]=[a]
ans=[]
for el in d:
    if len(d[el])==1:
        ans.append(el)
        root=el
        break
cur=root
while True:
    for el in d[cur]:
        if el==ans[-1]:continue
        if cur!=root:ans.append(cur)
        cur=el
        break
    if len(d[cur])==1:
        ans.append(cur)
        break
print(*ans)


d1,d2,d3 = {},{},{}
n = int(input())
for i in range(n):
    a,b = map(int,input().split())
    if a in d1.keys():
        d1[a] += 1
    else: d1[a] = 1
    if b in d1.keys():
        d1[b] += 1
    else: d1[b] = 1

    if a in d2.keys():
        d3[a] = b
    else: d2[a] = b
    if b in d2.keys():
        d3[b] = a
    else: d2[b] = a
first,last = 0,0
for i in d1.keys():
    if d1[i] == 1:
        if first == 0: first = i
        else: last=i

ans = [first]
i = first

cont = 0
while(i != last):
    if i in d2.keys() and d2[i] != cont:
        ans.append(d2[i])
        cont = i
        i = d2[i]
    elif i in d3.keys() and d3[i] != cont:
        ans.append(d3[i])
        cont = i
        i = d3[i]

print(*ans,sep=' ')


d1,d2,d3 = {},{},{}
n = int(input())

for i in range(n):
    a,b = map(int,input().split())
    if a in d1.keys(): d1[a] += 1
    else : d1[a] = 1
    if b in d1.keys(): d1[b] += 1
    else : d1[b] = 1
    if a in d2.keys(): d3[a] = b
    else : d2[a] = b

first,last = 0,0
for i in d1.keys():
    if d1[i] == 1:
        if first == 0 : first = i
        else: last = i
ans = [first]
j = first

while( j != last):

    if j in d2.keys() and d2[j] != 0:
        m = j
        ans.append(d2[j])
        j = d2[j]
        d2[m] = 0
    elif j in d3.keys() and d3[j] != 0:
        m = j
        ans.append(d3[j])
        j = d3[j]
        d3[m] = 0
    elif j in d2.values():
        for i in d2.keys():
            if d2[i] == j:
                m = i
                ans.append(i)
                j = i
                d2[i] = 0
    elif j in d3.values():
        for i in d3.keys():
            if d3[i] == j:
                ans.append(i)
                j = i
                d3[i] = 0

print(*ans,sep = ' ')


d1 = {}
d2 = {}

n = int(input())

for i in range(n):
    a,b = map(int,input().split())
    if a in d1.keys(): d1[a] += 1
    else: d1[a] = 1
    if b in d1.keys(): d1[b] += 1
    else: d1[b] = 1

    if a in d2.keys():
        if b in d2.keys():
            m = d2[a]
            n = d2[b]
            if m not in d2.keys() and m != a:
                d2[m] = a
                d2[a] = b
            elif n not in d2.keys() and n != b:
                d2[n] = b
                d2[b] = a
        else:
            d2[b] = a
    elif b in d2.values():
        if a in d2.values():
            for i in d2.keys():
                if d2[i] == a: m = i
                if d2[i] == b: n = i
            if m not in d2.values() and m != a:
                d2[a] = m
                d2[b] = a
            elif n not in d2.values and n != b:
                d2[b] = n
                d2[a] = b
        else: d2[b] = a
    else :
        d2[a] = b

for i in d2.keys():
    if d1[i] == 1:
        starting = i
ans = [starting]
for i in d2.values():
    if d1[i] == 1:   ending = i

j = starting
count = 1
while(j != ending):
    ans.append(d2[j])
    j = d2[j]

print(*ans,sep=' ')


dic = {}
for notused in range(int(input())):
	i1, i2 = list(map(int, input().split(" ")))
	if i1 in dic: dic[i1].append(i2)
	else: dic[i1] = [i2]
	if i2 in dic: dic[i2].append(i1)
	else: dic[i2] = [i1]
start,end = -1,-1
for key in dic.keys():
	if len(dic[key]) == 1:
		if start == -1: start = key
		else: end = key

seq = start
prev = -1
print(seq, end=' ')
while seq != end:
	arr = dic[seq]
	if arr[0] != prev: temp = arr[0]
	else: temp = arr[1]
	prev,seq = seq,temp
	print(seq, end =' ')
print()


dic,start = {},[]
for notused in range(int(input())):
	i1, i2 = list(map(int, input().split(" ")))
	if i1 in dic:
		dic[i1].append(i2)
		start.remove(i1)
	else:
		dic[i1] = [i2]
		start.append(i1)
	if i2 in dic:
		dic[i2].append(i1)
		start.remove(i2)
	else:
		dic[i2] = [i1]
		start.append	(i2)
seq = [start[0]]
while seq[-1] != start[1]:
	arr = dic[seq[-1]]
	if arr[0] not in seq: seq.append(arr[0])
	else: seq.append(arr[1])
print(" ".join([str(x) for x in seq]))


dic = {}
for notused in range(int(input())):
	i1, i2 = list(map(int, input().split(" ")))
	if i1 in dic: dic[i1].append(i2)
	else: dic[i1] = [i2]
	if i2 in dic: dic[i2].append(i1)
	else: dic[i2] = [i1]
start,end = -1,-1
for key in dic.keys():
	if len(dic[key]) == 1:
		if start == -1: start = key
		else: end = key

seq = start
prev = -1
while seq != end:
	arr = dic[seq]
	if arr[0] != prev: temp = arr[0]
	else: temp = arr[1]
	prev,seq = seq,temp
	print(seq, end =' ')
print()


dic = {}
for notused in range(int(input())):
	i1, i2 = list(map(int, input().split(" ")))
	if i1 in dic: dic[i1].append(i2)
	else: dic[i1] = [i2]
	if i2 in dic: dic[i2].append(i1)
	else: dic[i2] = [i1]
start,end = -1,-1
for key in dic.keys():
	if len(dic[key]) == 1:
		if start == -1: start = key
		else: end = key
seq = [start]
while seq[-1] != end:
	arr = dic[seq[-1]]
	if arr[0] not in seq: seq.append(arr[0])
	else: seq.append(arr[1])
print(" ".join([str(x) for x in seq]))


#include <stdio.h>
#include <string.h>

int main()
{
    int n,i;
    scanf("%d",&n);
    fflush(stdin);
    char word[n][100];
    for(i=0;i<n;i++)
    {
        gets(word[i]);
        fflush(stdin);
    }
    for(i=0;i<n;i++){

        if(strlen(word[i])>10){
            printf("%c",word[i][0]);
            printf("%d",strlen(word[i]));
            printf("%c",word[i][strlen(word[i])-1]);
            printf("\n");
        }
        else
        {
            printf(word[i]);
            printf("\n");
        }
    }
}


#include <stdio.h>
#include <string.h>

int main()
{
    int n,i,v;
    scanf("%d",&n);
    fflush(stdin);
    char word[n][100];
    for(i=0;i<n;i++)
    {
        gets(word[i]);
        fflush(stdin);
    }

    for(i=0;i<n;i++){

        if(strlen(word[i])>10){
            v=strlen(word[i]);
            printf("%c%d%c\n",word[i][0],v-2,word[i][v-1]);

        }
        else if(strlen(word[i])<=10)
        {
            printf("%s\n",word[i]);

        }
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    int n,i,v;
    scanf("%d",&n);
    char str[n+1][1000];
    for(i=0;i<=n;i++)
    {
        gets(str[i]);
    }
     for(i=0;i<=n;i++)
    {
        if(strlen(str[i])<=10)
        {
            printf("%s",str[i]);
            printf("\n");
        }
        else if(strlen(str[i])>10)
        {
            v=strlen(str[i]);
            printf("%c%d%c",str[i][0],v-2,str[i][v-1]);
            printf("\n");
        }
    }
    return 0;
}


#include <stdio.h>
#include <string.h>
#include <conio.h>

int main()
{
    int n,i,length;
    scanf("%d",&n);

    char word[n+1][100];
    for(i=0;i<=n;i++)
    {
        gets(word[i]);

    }

    for(i=0;i<=n;i++){

        if(strlen(word[i])>10){
            length=strlen(word[i]);
            printf("%c%d%c\n",word[i][0],length-2,word[i][length-1]);

        }
        else if(strlen(word[i])<=10)
        {
            printf("%s\n",word[i]);

        }
    }
    return 0;
}


#include <stdio.h>
#include <string.h>

int main()
{
    int n,i,length;
    scanf("%d",&n);

    char word[n+1][1000];
    for(i=0;i<=n;i++)
    {
        gets(word[i]);

    }

    for(i=0;i<=n;i++){

        if(strlen(word[i])>10){
            length=strlen(word[i]);
            printf("%c%d%c\n",word[i][0],length-2,word[i][length-1]);

        }
        else if(strlen(word[i])<=10)
        {
            printf("%s",word[i]);
            printf("\n");

        }
    }
    return 0;
}


#include <stdio.h>
#include <string.h>

int main()
{
    int n,i;
    scanf("%d",&n);
    fflush(stdin);
    char word[n][100];
    for(i=0;i<n;i++)
    {
        gets(word[i]);
        fflush(stdin);
    }

    for(i=0;i<n;i++){

        if(strlen(word[i])>10){
            printf("%c",word[i][0]);
            printf("%d",strlen(word[i])-2);
            printf("%c",word[i][strlen(word[i])-1]);
            printf("\n");
        }
        else
        {
            printf(word[i]);
            printf("\n");
        }
    }
    return 0;
}


#include <stdio.h>
#include <string.h>

int main()
{
    int n,i,length;
    scanf("%d",&n);

    char word[n+1][100];
    for(i=0;i<=n;i++)
    {
        gets(word[i]);

    }

    for(i=0;i<=n;i++){

        if(strlen(word[i])>10){
            length=strlen(word[i]);
            printf("%c%d%c\n",word[i][0],length-2,word[i][length-1]);

        }
        else if(strlen(word[i])<=10)
        {
            printf("%s\n",word[i]);

        }
    }
    return 0;
}


#include <stdio.h>
#include <string.h>

int main()
{
    int n,i;
    scanf("%d",&n);
    fflush(stdin);
    char word[n][100];
    for(i=0;i<n;i++)
    {
        gets(word[i]);
        fflush(stdin);
    }
    for(i=0;i<n;i++){

        if(strlen(word[i])>10){
            printf("%c",word[i][0]);
            printf("%d",strlen(word[i])-2);
            printf("%c",word[i][strlen(word[i])-1]);
            printf("\n");
        }
        else
        {
            printf(word[i]);
            printf("\n");
        }
    }
    return 0;
}


#include <stdio.h>
#include <string.h>

int main()
{
    int n,i,v;
    scanf("%d",&n);
    fflush(stdin);
    char word[n][100];
    for(i=0;i<n;i++)
    {
        gets(word[i]);
        fflush(stdin);
    }

    for(i=0;i<n;i++){

        if(strlen(word[i])>10){
            v=strlen(word[i]);
            printf("%c",word[i][0]);
            printf("%d",v-2);
            printf("%c",word[i][v-1]);
            printf("\n");
        }
        else if(strlen(word[i])<=10)
        {
            printf(word[i]);
            printf("\n");
        }
    }
    return 0;
}


#include<stdio.h>
int main()
{
    char str[100];
    gets(str);
    if(strlen(str)<10)
        puts(str);
    else
        printf("%c%d%c",str[0],strlen(str)-2,str[strlen(str)-1]);

    return 0;
}


#include<stdio.h>
int main()
{
    char str[100];
    gets(str);
    if(strlen(str)<10)
        puts(str);
    else{
        printf("%c%d%c",str[0],strlen(str)-2,str[strlen(str)-1]);

    }
    return 0;
}


#include<stdio.h>
int main()
{
    char str[100];
    gets(str);
    if(strlen(str)<10)
        printf("%s"str);
    else
        printf("%c%d%c",str[0],strlen(str)-2,str[strlen(str)-1]);

    return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    char str[100];
    gets(str);
    if(strlen(str)<10)
        puts(str);
    else
        printf("%c%d%c",str[0],strlen(str)-2,str[strlen(str)-1]);

    return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    char str[100];
    gets(str);
    int l=strlen(str);
    if(l<10)
        printf("%s",str);
    else
        printf("%c%d%c",str[0],l-2,str[l-1]);

    return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    char s[100];
    int n,i;
    scanf("%d%*c",&n);
    int l;
    for(i=0;i<n;i++){
        gets(s);
        l=strlen(s);
        if(l>10)
        {
            printf("%c%d%c\n",s[0],l-2,s[l-1]);
        }

        else
            puts(s);

    }

    return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    char str[100];
    gets(str);
    int l=strlen(str);

    if(l>10)
        printf("%c%d%c",str[0],l-2,str[l-1]);
    else
        printf("%s",str);

    return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    char s[100];
    int n,i;
    scanf("%d%*c",&n);
    int l;
    for(i=0;i<n;i++){
        gets(s);
        l=strlen(s);
        if(l>10)
        {
            printf("%c%d%c\n",s[0],l-1,s[l-1]);
        }

        else
            puts(s);

    }

    return 0;
}


#include<stdio.h>
int main()
{
    char str[100];
    gets(str);
    if(strlen(str)<10)
        printf("%s",str);
    else
        printf("%c%d%c",str[0],strlen(str)-2,str[strlen(str)-1]);

    return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    char str[100];
    gets(str);
    int l=strlen(str);
    if(l<10)
        puts(str);
    else
        printf("%c%d%c",str[0],l-2,str[l-1]);

    return 0;
}


#include <stdio.h>
#include <string.h>

int main()
{
    char words[105];
    int cases, i, length;

    scanf("%d",&cases);
    while(cases--)
    {
        fflush(stdin);
        gets(words);
        if(strlen(words) > 10)
            printf("%c%d%c", words[0], strlen(words)-2, words[strlen(words)-1]);
        else
            printf("%s",words);
        printf("\n");
    }

    return 0;
}


#include <stdio.h>
#include <string.h>

int
main()
{

  int cases, casenum, length;
  char str[101];

  scanf("%d",&cases);
  casenum = 0;

  while (casenum < cases){
	scanf("%s", str);
	length = strlen(str);

	if(length > 10){
	  printf("%c%d%c\n",str[0],length-2,str[length-1]);
	}
	else{
	  printf("%s\n", str);
	}
	casenum++;
  }
  return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
    char **words;
    int cases, i, length;

    scanf("%d",&cases);

    words = (char **)calloc(cases,sizeof(char *));

    for(i=0; i<cases; i++)
        words[i] = (char *)calloc(101,sizeof(char));

    for(i=0; i<cases; i++)
    {
        fflush(stdin);
        gets(words[i]);
    }
    printf("\n");
    for(i=0; i<cases; i++)
    {
        length = strlen(words[i]);
        if(length > 10)
            printf("%c%d%c", words[i][0], length-2, words[i][length-1]);
        else
            printf("%s", words[i]);

        if(i != cases - 1)
            printf("\n");
    }

    return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
    char **words;
    int cases, i, length;

    scanf("%d",&cases);

    words = (char **)calloc(cases,sizeof(char *));

    for(i=0; i<cases; i++)
        words[i] = (char *)calloc(101,sizeof(char));

    for(i=0; i<cases; i++)
    {
        fflush(stdin);
        gets(words[i]);
    }

    for(i=0; i<cases; i++)
    {
        length = strlen(words[i]) - 2;
        if(length + 2 > 10)
            printf("%c%d%c\n", words[i][0], length, words[i][length+1]);
        else
            printf("%s\n", words[i]);
    }

    return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
    char **words;
    int cases, i, length;

    scanf("%d",&cases);

    words = (char **)calloc(cases,sizeof(char *));

    for(i=0; i<cases; i++)
        words[i] = (char *)calloc(101,sizeof(char));

    for(i=0; i<cases; i++)
    {
        fflush(stdin);
        gets(words[i]);
    }

    for(i=0; i<cases; i++)
    {
        length = strlen(words[i]);
        if(length > 10)
            printf("%c%d%c", words[i][0], length-2, words[i][length-1]);
        else
            printf("%s", words[i]);
    }

    return 0;
}


#include <stdio.h>
#include <string.h>

int main()
{
    char words[105];
    int cases, i, length;

    scanf("%d",&cases);
    while(cases--)
    {
        fflush(stdin);
        gets(words);
        if(strlen(words) > 10)
            printf("%c%d%c", words[0], strlen(words)-2, words[strlen(words)-1]);
        else
            printf("%s",words);
    }

    return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
    char **words;
    int cases, i, length;

    scanf("%d",&cases);

    words = (char **)calloc(cases,sizeof(char *));

    for(i=0; i<cases; i++)
        words[i] = (char *)calloc(101,sizeof(char));

    for(i=0; i<cases; i++)
    {
        fflush(stdin);
        gets(words[i]);
    }

    for(i=0; i<cases; i++)
    {
        length = strlen(words[i]);
        if(length > 10)
            printf("%c%d%c", words[i][0], length-2, words[i][length-1]);
        else
            printf("%s", words[i]);

        if(i != cases - 1)
            printf("\n");
    }

    return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
    char **words;
    int cases, i, length;

    scanf("%d",&cases);

    words = (char **)calloc(cases,sizeof(char *));

    for(i=0; i<cases; i++)
        words[i] = (char *)calloc(105,sizeof(char));

    for(i=0; i<cases; i++)
    {
        fflush(stdin);
        gets(words[i]);
    }

    for(i=0; i<cases; i++)
    {
        length = strlen(words[i]);
        if(length > 10)
            printf("%c%d%c\n", words[i][0], length-2, words[i][length-1]);
        else
            printf("%s\n", words[i]);
    }

    return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
    char **words;
    int cases, i, length;

    scanf("%d",&cases);

    words = (char **)calloc(cases+1,sizeof(char *));

    for(i=0; i<cases; i++)
        words[i] = (char *)calloc(101,sizeof(char));

    for(i=0; i<cases; i++)
    {
        fflush(stdin);
        gets(words[i]);
    }

    for(i=0; i<cases; i++)
    {
        length = strlen(words[i]) - 2;
        if(length + 2 > 10)
            printf("%c%d%c\n", words[i][0], length, words[i][length+1]);
        else
            printf("%s\n", words[i]);
    }

    return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
    char **words;
    int cases, i, length;

    scanf("%d",&cases);

    words = (char **)calloc(cases,sizeof(char *));

    for(i=0; i<cases; i++)
        words[i] = (char *)calloc(101,sizeof(char));

    for(i=0; i<cases; i++)
    {
        fflush(stdin);
        gets(words[i]);
    }

    for(i=0; i<cases; i++)
    {
        fflush(stdin);
        length = strlen(words[i]);
        if(length > 10)
            printf("%c%d%c", words[i][0], length-2, words[i][length-1]);
        else
            printf("%s", words[i]);

        if(i != cases - 1)
            printf("\n");
    }

    return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
    char **words;
    int cases, i, length;

    scanf("%d",&cases);

    words = (char **)calloc(cases,sizeof(char *));

    for(i=0; i<cases; i++)
        words[i] = (char *)calloc(101,sizeof(char));

    for(i=0; i<cases; i++)
    {
        fflush(stdin);
        gets(words[i]);
    }

    for(i=0; i<cases; i++)
    {
        fflush(stdout);
        length = strlen(words[i]);
        if(length > 10)
            printf("%c%d%c", words[i][0], length-2, words[i][length-1]);
        else
            printf("%s", words[i]);

        if(i != cases - 1)
            printf("\n");
    }

    return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
main(){
    int n,i,j,l=0;
    scanf("%d",&n);
    char s[n][1000];
    for(i=0;i<n;i++)
    {
        scanf("%s\n",s);
        getchar();
    }
    for(i=0;i<n;i++)
    {
        int l=0;
        for(j=0;s[i][j]!='\0';j++)
    {
        l=l+1;
    }
        if(l>10)
        printf("%c%d%c\n",s[i][0],(l-2),s[i][j-1]);
        else printf("%s\n",s[i]);
    }
}


#include<stdio.h>
#include<string.h>
main(){
    int n,i,j,l;
    scanf("%d",&n);
    char s[n][1000];
    for(i=0;i<n;i++)
    {
        scanf("%s",s);
        getchar();
    }
    for(i=0;i<n;i++)
    {
        l=strlen(s[i][1000]);
        if(l<=10)
        printf("%s",s[i]);
        else printf("%c%d%c",s[i][0],(l-2),s[i][l-1]);
    }
}


#include<stdio.h>
#include<strings.h>
#include<stdlib.h>
main(){
    int n,i,j,l=0;
    scanf("%d",&n);
    char s[n][1000];
    for(i=0;i<n;i++)
    {
        scanf("%s\n",s);
        getchar();
    }
    for(i=0;i<n;i++)
    {
        int l=0;
        for(j=0;s[i][j]!='\0';j++)
    {
        l=l+1;
    }
        if(l>10)
        printf("%c%d%c\n",s[i][0],(l-2),s[i][j-1]);
        else printf("%s\n",s[i]);
    }
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(){
    int n,i,j,l=0;
    scanf("%d",&n);
    char s[n][1000];
    for(i=0;i<n;i++)
    {
        scanf("%s\n",s);
        getchar();
    }
    for(i=0;i<n;i++)
    {
        int l=0;
        for(j=0;s[i][j]!='\0';j++)
    {
        l=l+1;
    }
        if(l>10)
        printf("%c%d%c\n",s[i][0],(l-2),s[i][j-1]);
        else if(l<=10)
        printf("%s\n",s[i]);
    }
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<strings.h>
int main(){
int n,i,j,l;

scanf("%d",&n);
char ch[n][1000];
for(i=0;i<n;i++)
{
scanf("%s",ch[i]);
getchar();
}
for(j=0;j<n;j++)
{l=0;
for(i=0;ch[j][i]!='\0';i++)
{l++;
}
if(l>10)
printf("%c%d%c\n",ch[j][0],(l-2),ch[j][i-1]);

else if(l<=10)
printf("%s\n",ch[j]);
}
return 0;
}


#include <stdio.h>
#include <string.h>
main (){
    int n,i,l,m;
    char s [100]];
    scanf("%d",n);
    for (i=0;i<n;i++)
    {
        scanf("%s",s);
        l=strlen(s);
        m=l-2;
        printf ("%c%d%c",s[0],m,s[l]);
    }
}


#include <stdio.h>
#include <string.h>
main(){
    int n,i,l,m;
    char s[100]];
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%s",s);
        l=strlen(s);
        m=l-2;
        printf("%c%d%c",s[0],m,s[l]);
    }
}


#include<stdio.h>
#include<strings.h>
main(){
    int n,i,j,l;
    scanf("%d",&n);
    char s[n][1000];
    for(i=0;i<n;i++)
    {
        scanf("%s",s);
        getchar();
    }
    for(i=0;i<n;i++)
    {
        l=strlen(s[i]);
        if(l<=10)
        printf("%s",s[i]);
        else printf("%c%d%c",s[i][0],(l-2),s[i][l-1]);
    }
}


#include<stdio.h>
#include<strings.h>
main(){
    int n,i,j,l;
    scanf("%d",&n);
    char s[n][1000];
    for(i=0;i<n;i++)
    {
        scanf("%s\n",s);
        getchar();
    }
    for(i=0;i<n;i++)
    {
        l=strlen(s[i]);
        if(l<=10)
        printf("%s",s[i]);
        else printf("%c%d%c\n",s[i][0],(l-2),s[i][l-1]);
    }
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
    int i,s,n ;
    char a[200];
    for (i=0;i<n;i++){
        scanf("%s",&a);
        s=strlen(a);

        printf("%c%d%c ",a[0],s-2,a[s-1]);
    }
    return 0 ;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
    int i,s,n ;
    char a[200];
    for (i=0;i<n;i++){
        scanf("%s",&a);
        s=strlen(a);

        printf("%d%d%d",a[0],s-2,a[s-1]);
    }
    return 0 ;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
    int i,s,n ;
    char a[200];
    scanf("%d",n);
    for (i=0;i<n;i++){
        scanf("%s",&a);
        s=strlen(a);

        printf("%d%d%d\n ",a[0],s-2,a[s-1]);
    }
    return 0 ;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
    int i,s,n ;
    char a[200];
    scanf("%d",&n);
    if(n>10){
    for (i=0;i<n;i++){
        scanf("%s",&a);
        s=strlen(a);

        printf("%c%d%c ",a[0],s-2,a[s-1]);
    }
    }
    else {
        printf("%s",a);}
    return 0 ;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
    int i,s,n ;
    char a[200];
    scanf("%d",&n);

    for (i=0;i<n;i++){
        scanf("%s",&a);
        s=strlen(a);
        if(s>10){
        printf("%c%d%c \n ",a[0],s-2,a[s-1]);}
        else{
        printf("%s",a);}
    }

    return 0 ;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
    int i,s,n ;
    char a[100];
    for (i=0;i<n;i++){
        scanf("%s",&a);
        s=strlen(a);

        printf("%d %d %d ",a[0],s-2,a[n-1]);
    }
    return 0 ;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
    int i,s,n ;
    char a[100];
    for (i=0;i<n;i++){
        scanf("%s",&a);
        s=strlen(a);

        {printf("%d %d %d ",a[0],s-2,a[n-1]);}
    }
    return 0 ;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
    int i,s,n ;
    char a[200];
    for (i=0;i<n;i++){
        scanf("%s",&a);
        s=strlen(a);

        printf("%d %d %d ",a[0],s-2,a[s-1]);
    }
    return 0 ;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
    int i,s,n ;
    char a[200];
    scanf("%d",&n);

    for (i=0;i<n;i++){
        scanf("%s",&a);
        s=strlen(a);
        if(s>10){
        printf("%c%d%c ",a[0],s-2,a[s-1]);}
        else{
        printf("%s",a);}
    }

    return 0 ;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
    int i,s,n ;
    scanf("%d",&n);
    char a[200];
    for (i=0;i<n;i++){
        scanf("%s",&a);
        s=strlen(a);

        printf("%d %d %d ",a[0],s-2,a[s-1]);
    }
    return 0 ;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
    int i,s,n ;
    char a[200];
    scanf("%d \n",&n);

    for (i=0;i<n;i++){
        scanf("%s",&a);
        s=strlen(a);
        if(s>10){
        printf("%c%d%c \n",a[0],s-2,a[s-1]);}
        else{
        printf("%s",a);}
    }

    return 0 ;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
    int i,s,n ;
    char a[200];
    scanf("%d",&n);
    for (i=0;i<n;i++){
        scanf("%s",&a);
        s=strlen(a);

        printf("%c%d%c ",a[0],s-2,a[s-1]);
    }
    return 0 ;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
    int i,s,n ;
    char a[200];
    scanf("%d \n",&n);

    for (i=0;i<n;i++){
        scanf("%s",&a);
        s=strlen(a);
        if(s>10){
        printf("%c%d%c \n",a[0],s-2,a[s-1]);}
        else{
        printf("%s \n",a);}
    }

    return 0 ;
}


#include <stdio.h>
#include <string.h>
int main(){
char str[101];
int i,j,n;
scanf("%d", &n);
for(i=0;i<n;i++)
 { scanf("%s",str);
   j=strlen(str[i]);
   if(j<11)
      printf("%s\n", str);
   else
      printf("%c%d%c\n", str[0], j-2, str[j-1]);

 }
return 0;
}


#include <stdio.h>
#include <string.h>
int main(){
char str[101];
int i,j,n;
scanf("%d", &n);
for(i=0;i<n;i++)
 { scanf("%s", str);
   j=strlen(str);
   if(j<11)
      printf("%s\n", str);
   else
      printf("%c%d%c\n", str[0], j-2, str[j-1]);

 }
return 0;
}


#include <stdio.h>
#include <string.h>
int main(){
char str[101];
int i,j,n;
scanf("%d", &n);
for(i=0;i<n;i++)
 { scanf("%s",str[i])
   j=strlen(str[i]);
   if(j<11)
      printf("%s\n", str);
   else
      printf("%c%d%c\n", str[0], j-2, str[j-1]);

 }
return 0;
}


#include <stdio.h>
#include <string.h>
int main(){
char str[101][101];
int i,j,n;
scanf("%d", &n);
for(i=0;i<n;i++)
 scanf("%s",str[i]);
for(i=0;i<n;i++)
 { j=strlen(str[i]);
   if(j<11)
      printf("%s\n", str[i]);
   else
      printf("%c%d%c\n", str[i][0], j-2, str[i][j-1]);

 }
return 0;
}


#include <stdio.h>
#include <string.h>
int main(){
char str[101];
int i,j,n;
scanf("%d", &n);
for(i=0;i<n;i++)
 { scanf("%s",str[i])
   j=strlen(str[i]);
   if(j<11)
      printf("%s\n", str[i]);
   else
      printf("%c%d%c\n", str[i][0], j-2, str[i][j-1]);

 }
return 0;
}


#include <stdio.h>
#include <string.h>
int main(){
char str[101];
int i,j,n;
scanf("%d", &n);
for(i=0;i<n;i++)
 { scanf("%s",str)
   j=strlen(str[i]);
   if(j<11)
      printf("%s\n", str);
   else
      printf("%c%d%c\n", str[0], j-2, str[j-1]);

 }
return 0;
}


#include<stdio.h>
#include<string.h>

int main(){

char wordarray[100][100];
int n=0,i=0,len=0,d=0;
char c1='\0',c2='\0';
scanf("%d%*c",&n);

for(i=0;i<n;i++){

    gets(wordarray[i]);
}

for(i=0;i<n;i++){

len=strlen(wordarray[i]);
if( len>10){

    d=len-2;

if(d==9){

    wordarray[i][1]='9';
    wordarray[i][2]=wordarray[i][len-1];
    wordarray[i][3]='\0';

}

else{

        c1=((d/10)%10) + '0';
        c2=d%10+'0';

         wordarray[i][1]=c1;
         wordarray[i][2]=c2;
         wordarray[i][3]=wordarray[i][len-1];
         wordarray[i][4]='\0';

}

}

}
for(i=0;i<n;i++){

    printf("%s\n",wordarray[i]);
}
return 0;
}


#include<stdio.h>
#include<ctype.h>
#include<string.h>

int main(){

char wordarray[100][100];
int n=0,i=0,len=0,d=0;
char c1='\0',c2='\0';
scanf("%d",&n);

for(i=0;i<=n;i++){
    gets(wordarray[i]);
}

for(i=0;i<=n;i++){

len=strlen(wordarray[i]);
if( len>10){

    d=len-2;

if(d==9){

    wordarray[i][1]='9';
    wordarray[i][2]=wordarray[i][len-1];
    wordarray[i][3]='\0';

}
else{

        c1=((d/10)%10) + '0';
        c2=d%10+'0';

         wordarray[i][1]=c1;
         wordarray[i][2]=c2;
         wordarray[i][3]=wordarray[i][len-1];

         if(len<100)
         wordarray[i][4]='\0';

}

}

}
for(i=0;i<=n;i++){
    puts(wordarray[i]);
}
return 0;
}


#include<stdio.h>
#include<stdlib.h>
int n,I;
int a[200];
int main()
{
    int i,j,len;
    scanf("%d\n",&n);
    for(I=1;I<=n;I++)
    {
        for(i=1;;i++)
        {
            scanf("%c",&a[i]);
            if(a[i]>='a'&&a[i]<='z')
            continue;
            break;
        }
        len=i-1;
        if(len<=10)
        {
            for(j=1;j<=len;j++)
            {
                printf("%c",a[j]);
            }
            printf("\n");
            continue;
        }
        printf("%c%d%c\n",a[1],len-2,a[len]);
    }
    return 0;
}


#include<stdio.h>
#include<ctype.h>
#include<string.h>

int main(){

char wordarray[100][100];
int n=0,i=0,len=0,d=0;
char c1='\0',c2='\0';
scanf("%d",&n);

for(i=0;i<n;i++){
    scanf("%s",wordarray[i]);
}

for(i=0;i<n;i++){

len=strlen(wordarray[i]);
if( len>10){

    d=len-2;

if(d==9){

    wordarray[i][1]='9';
    wordarray[i][2]=wordarray[i][len-1];
    wordarray[i][3]='\0';

}
else{

        c1=((d/10)%10) + '0';
        c2=d%10+'0';

         wordarray[i][1]=c1;
         wordarray[i][2]=c2;
         wordarray[i][3]=wordarray[i][len-1];
         wordarray[i][4]='\0';

}

}

}
for(i=0;i<=n;i++){

    printf("%s\n",wordarray[i]);
}
return 0;
}


#include<stdio.h>
#include<string.h>

int main(){

char wordarray[100][100];
int n=0,i=0,len=0,d=0;
char c1='\0',c2='\0';
scanf("%d%*c",&n);

for(i=0;i<n;i++){

    gets(wordarray[i]);
}

for(i=0;i<n;i++){

len=strlen(wordarray[i]);
if( len>=10){

    d=len-2;

if(d==9){

    wordarray[i][1]='9';
    wordarray[i][2]=wordarray[i][len-1];
    wordarray[i][3]='\0';

}
else if (d==8){
        wordarray[i][1]='8';
        wordarray[i][2]=wordarray[i][len-1];
         wordarray[i][3]='\0';

}
else{

        c1=((d/10)%10) + '0';
        c2=d%10+'0';

         wordarray[i][1]=c1;
         wordarray[i][2]=c2;
         wordarray[i][3]=wordarray[i][len-1];
         wordarray[i][4]='\0';

}

}

}
for(i=0;i<n;i++){

    printf("%s\n",wordarray[i]);
}
return 0;
}


#include<stdio.h>
#include<string.h>

int main(){

char wordarray[100][200];
int n=0,i=0,len=0,d=0;
char c1='\0',c2='\0';
scanf("%d%*c",&n);

for(i=0;i<n;i++){

    gets(wordarray[i]);
}

for(i=0;i<n;i++){

len=strlen(wordarray[i]);
if( len>10){

    d=len-2;

if(d==9){

    wordarray[i][1]='9';
    wordarray[i][2]=wordarray[i][len-1];
    wordarray[i][3]='\0';

}

else{

        c1=((d/10)%10) + '0';
        c2=d%10+'0';

         wordarray[i][1]=c1;
         wordarray[i][2]=c2;
         wordarray[i][3]=wordarray[i][len-1];
         wordarray[i][4]='\0';

}

}

}
for(i=0;i<n;i++){

    printf("%s\n",wordarray[i]);
}
return 0;
}


#include<stdio.h>
#include<ctype.h>
#include<string.h>

int main(){

char wordarray[100][100];
int n=0,i=0,len=0,d=0;
char c1,c2;
scanf("%d",&n);

for(i=0;i<=n;i++){
    gets(wordarray[i]);
}

for(i=0;i<=n;i++){

len=strlen(wordarray[i]);
if( len>10){
    d=len-2;
if(d==9){
    wordarray[i][1]='9';
    wordarray[i][2]=wordarray[i][len-1];
    wordarray[i][3]='\0';
}
else{

        c1=((d/10)%10) + '0';
        c2=d%10+'0';

         wordarray[i][1]=c1;
         wordarray[i][2]=c2;
         wordarray[i][3]=wordarray[i][len-1];
         wordarray[i][4]='\0';
}

}

}
for(i=0;i<=n;i++){
    puts(wordarray[i]);
}
return 0;
}


#include<stdio.h>
#include<string.h>

int main(){

char wordarray[100][100];
int n=0,i=0,len=0,d=0;
char c1='\0',c2='\0';
scanf("%d",&n);
getchar();
for(i=0;i<n;i++){

    gets(wordarray[i]);
}

for(i=0;i<n;i++){

len=strlen(wordarray[i]);
if( len>10){

    d=len-2;

if(d==9){

    wordarray[i][1]='9';
    wordarray[i][2]=wordarray[i][len-1];
    wordarray[i][3]='\0';

}
else{

        c1=((d/10)%10) + '0';
        c2=d%10+'0';

         wordarray[i][1]=c1;
         wordarray[i][2]=c2;
         wordarray[i][3]=wordarray[i][len-1];
         wordarray[i][4]='\0';

}

}

}
for(i=0;i<n;i++){

    printf("%s\n",wordarray[i]);
}
return 0;
}


#include<stdio.h>
#include<ctype.h>
#include<string.h>

int main(){

char wordarray[100][100];
int n=0,i=0,len=0,d=0;
char c1='\0',c2='\0';
scanf("%d",&n);

for(i=0;i<=n;i++){
    gets(wordarray[i]);
}

for(i=0;i<=n;i++){

len=strlen(wordarray[i]);
if( len>10){

    d=len-2;

if(d==9){

    wordarray[i][1]='9';
    wordarray[i][2]=wordarray[i][len-1];
    wordarray[i][3]='\0';

}
else{

        c1=((d/10)%10) + '0';
        c2=d%10+'0';

         wordarray[i][1]=c1;
         wordarray[i][2]=c2;
         wordarray[i][3]=wordarray[i][len-1];

         wordarray[i][4]='\0';

}

}

}
for(i=0;i<=n;i++){
    puts(wordarray[i]);
}
return 0;
}


#include<stdio.h>
#include<ctype.h>
#include<string.h>

int main(){

char wordarray[100][100];
int n=0,i=0,len=0,d=0;
char c1='\0',c2='\0';
scanf("%d",&n);

for(i=0;i<n;i++){
    scanf("%s",wordarray[i]);
}

for(i=0;i<n;i++){

len=strlen(wordarray[i]);
if( len>10){

    d=len-2;

if(d==9){

    wordarray[i][1]='9';
    wordarray[i][2]=wordarray[i][len-1];
    wordarray[i][3]='\0';

}
else{

        c1=((d/10)%10) + '0';
        c2=d%10+'0';

         wordarray[i][1]=c1;
         wordarray[i][2]=c2;
         wordarray[i][3]=wordarray[i][len-1];
         wordarray[i][4]='\0';

}

}

}
for(i=0;i<n;i++){

    printf("%s\n",wordarray[i]);
}
return 0;
}


#include<stdio.h>
#include<ctype.h>
#include<string.h>

int main(){

char wordarray[100][100];
int n=0,i=0,len=0,d=0;
char c1='\0',c2='\0';
scanf("%d",&n);

for(i=0;i<=n;i++){
    gets(wordarray[i]);
}

for(i=0;i<=n;i++){

len=strlen(wordarray[i]);
if( len>10){
    d=len-2;
if(d==9){
    wordarray[i][1]='9';
    wordarray[i][2]=wordarray[i][len-1];
    wordarray[i][3]='\0';
}
else{

        c1=((d/10)%10) + '0';
        c2=d%10+'0';

         wordarray[i][1]=c1;
         wordarray[i][2]=c2;
         wordarray[i][3]=wordarray[i][len-1];
         wordarray[i][4]='\0';
}

}

}
for(i=0;i<=n;i++){
    puts(wordarray[i]);
}
return 0;
}


#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	for(int i=0; i<n; i++)
	{
		char str[100];
		scanf("%s", str);
		int x;
		while(str[i]!='\0')
		{
			x++;
			i++;
		}
		if(x>9)
		printf("%c%d%c", str[0], (x-2), str[x-1]);
	    else
	    printf("%s", str);
	}
	return 0;
}


#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	for(int i=0; i<n; i++)
	{
		char str[100];
		scanf("%s", str);
		int x;
		while(str[k]!='\0')
		{
			x++;
			k++;
		}
		if(x>9)
		printf("%c%d%c", str[0], (x-2), str[x-1]);
	    else
	    printf("%s", str);
	}
	return 0;
}


#include<stdio.h>
int main()
{
	int n;
	char a[100];
	scanf("%d", &n);
	for(int i=0; i<n; i++)
	{
		scanf("%s", a);
		int x;
		x=0;
		int k=0;
		while(a[k]!='\0')
		{
			x++;
			k++;
		}
		if(x>10)
		printf("%c%d%c\n", a[0], (x-2), a[x-1]);
	    else
	    printf("%s\n", a);
	}
	return 0;
}


#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	for(int i=0; i<n; i++)
	{
		char str[100];
		scanf("%s", str);
		int x;
		x=0;
		while(str[k]!='\0')
		{
			x++;
			k++;
		}
		if(x>9)
		printf("%c%d%c\n", str[0], (x-2), str[x-1]);
	    else
	    printf("%s\n", str);
	}
	return 0;
}


#include<stdio.h>
int main()
{
	int n;
	char a[100];
	scanf("%d", &n);
	for(int i=0; i<n; i++)
	{
		scanf("%s", a);
		int x;
		x=0;
		int k=0;
		while(a[k]!='\0')
		{
			x++;
			k++;
		}
		if(x>9)
		printf("%c%d%c\n", a[0], (x-2), a[x-1]);
	    else
	    printf("%s\n", a);
	}
	return 0;
}


#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	for(int i=0; i<n; i++)
	{
		char str[100];
		scanf("%s", str);
		int x;
		x=0;
		while(str[k]!='\0')
		{
			x++;
			k++;
		}
		if(x>9)
		printf("%c%d%c", str[0], (x-2), str[x-1]);
	    else
	    printf("%s", str);
	}
	return 0;
}


#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	for(int i=0; i<n; i++)
	{
		char str[100];
		scanf("%s", &str);
		int x;
		while(str[i]!=\0)
		{
			x++;
		}
		printf("%c%d%c", str[o], (x-2), str[x-1]);
	}
	return 0;
}


#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	for(int i=0; i<n; i++)
	{
		char str[100];
		scanf("%s", &str);
		int x;
		while(str[i]!=\0)
		{
			x++;
		}
		if(x>9)
		printf("%c%d%c", str[o], (x-2), str[x-1]);
	    else
	    printf("%s", str);
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    char ch[100];
    int i,j,k,count;i=0;gets(ch);
    j=strlen(ch);k=j;
    if(j<=4){
        printf("%s",ch);
        return 0;
    }
    j--;k=k-2;
    printf("%c%d%c",ch[i],k,ch[j]);
}


#include<stdio.h>
#include<string.h>
int main()
{
    char ch[100];
    int i,j,k,l,m,flag;scanf("%d",&m);getch();flag=0;
    for(l=0;l<m;l++)
    {
        scanf("%s",ch);
    j=strlen(ch);k=j;//printf("%d",j);
    if(j<=10){
            flag=1;
    }
    else{
      i=0;      k=j;
    j--;k=k-2;

}
    if(flag==1)
        printf("%s",ch);
    else
        printf("%c%d%c",ch[i],k,ch[j]);
}
}


/*input
5
2 1
3
2 3
2 1
3
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("O2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define endl '\n'
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

void solve(){
	int n;cin>>n;int c=1;
	cout<<fixed<<setprecision(10);
	std::vector<int> v;
	v.push_back(0);
	double lazyinc[n+1]={0};
	long double sum=0;
	while(n--){
		long double t;cin>>t;
		if(t==1){
			int a,x;
			cin>>a>>x;
			sum+=a*x;
			lazyinc[a-1]+=x;
		}
		else if(t==2){
			int k;cin>>k;
			sum+=k;
			v.push_back(k);
			++c;
		}
		else{
			sum-=lazyinc[c-1];
			sum-=v.back();
			lazyinc[c-2]+=lazyinc[c-1];
			lazyinc[c-1]=0;
			c--;
			v.pop_back();
		}
		cout<<(sum/c)<<endl;
	}

}

signed main(){
	IOS
	int t=1;
	//cin>>t;
	while(t--)
		solve();
	return 0;
}


/*input
5
2 1
3
2 3
2 1
3
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("O2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define endl '\n'
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

void solve(){
	int n;cin>>n;int c=1;
	cout<<fixed<<setprecision(10);
	std::vector<int> v;
	v.push_back(0);
	double lazyinc[n+1]={0};
	long double sum=0;
	while(n--){
		long double t;cin>>t;
		if(t==1){
			int a,x;
			cin>>a>>x;
			sum+=a*x;
			lazyinc[a-1]+=x;
		}
		else if(t==2){
			int k;cin>>k;
			sum+=k;
			v.push_back(k);
			++c;
		}
		else{
			sum-=lazyinc[c-1];
			sum-=v.back();
			lazyinc[c-2]+=lazyinc[c-1];
			lazyinc[c-1]=0;
			c--;
			v.pop_back();
		}
		cout<<(sum/c)<<endl;
	}

}

signed main(){
	// IOS
	int t=1;
	//cin>>t;
	while(t--)
		solve();
	return 0;
}


/*input
5
2 1
3
2 3
2 1
3
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("O2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define endl '\n'
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

void solve(){
	int n;cin>>n;int c=1;
	cout<<fixed<<setprecision(10);
	std::vector<int> v;
	v.push_back(0);
	map<int,long double> lazyinc;
	long double sum=0;
	while(n--){
		long double t;cin>>t;
		if(t==1){
			long double a,x;
			cin>>a>>x;
			sum+=a*x;
			lazyinc[a-1]+=x;
		}
		else if(t==2){
			long double k;cin>>k;
			sum+=k;
			v.push_back(k);
			++c;
		}
		else{
			sum-=lazyinc[c-1];
			sum-=v.back();
			lazyinc[c-2]+=lazyinc[c-1];
			lazyinc[c-1]=0;
			c--;
			v.pop_back();

		}
		cout<<(sum/c)<<endl;
	}

}

signed main(){
	IOS
	int t=1;
	//cin>>t;
	while(t--)
		solve();
	return 0;
}


/*input
5
2 1
3
2 3
2 1
3
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define endl '\n'
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
void solve(){
	double n;cin>>n;double c=1;
	cout<<fixed<<setprecision(20);
	std::vector<double> v;
	v.push_back(0);
	map<double,double> lazyinc;
	double sum=0;
	while(n--){
		double t;cin>>t;
		if(t==1){
			double a,x;
			cin>>a>>x;
			sum+=a*x;
			lazyinc[a-1]+=x;
		}
		else if(t==2){
			double k;cin>>k;
			sum+=k;
			v.push_back(k);
			++c;
		}
		else{
			sum-=lazyinc[c-1];
			sum-=v.back();
			lazyinc[c-2]+=lazyinc[c-1];
			lazyinc[c-1]=0;
			c--;
			v.pop_back();

		}
		cout<<(sum/c)<<endl;
	}

}

signed main(){
	IOS
	double t=1;
	//cin>>t;
	while(t--)
		solve();
	return 0;
}


/*input
5
2 1
3
2 3
2 1
3
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define endl '\n'
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

void solve(){
	double n;cin>>n;double c=1;
	cout<<fixed<<setprecision(10);
	std::vector<double> v;
	v.push_back(0);
	map<double,double> lazyinc;
	double sum=0;
	while(n--){
		double t;cin>>t;
		if(t==1){
			double a,x;
			cin>>a>>x;
			sum+=a*x;
			lazyinc[a-1]+=x;
		}
		else if(t==2){
			double k;cin>>k;
			sum+=k;
			v.push_back(k);
			++c;
		}
		else{
			sum-=lazyinc[c-1];
			sum-=v.back();
			lazyinc[c-2]+=lazyinc[c-1];
			lazyinc[c-1]=0;
			c--;
			v.pop_back();

		}
		cout<<(sum/c)<<endl;
	}

}

signed main(){
	IOS
	double t=1;
	//cin>>t;
	while(t--)
		solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long ll;
#define fio                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
int main()
{
    fio;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll t;
    //cin >> t;
    t = 1;
    while (t--)
    {
        ll n;
        cin >> n;
        ll sm = 0;
        vector<ll> vc, mi(1, 0);
        vc.push_back(0);

        cout << fixed << setprecision(6);
        while (n--)
        {
            ll tp;
            cin >> tp;
            if (tp == 1)
            {
                ll ele, pos;
                cin >> pos >> ele;
                vc[pos - 1] += ele;
                mi[pos - 1] = ele;
                sm += (ele * pos);
                cout << (double)sm / (double)vc.size() << "\n";
            }
            else if (tp == 2)
            {
                ll ele;
                cin >> ele;
                vc.push_back(ele);
                mi.push_back(0);
                sm += ele;
                cout << (double)sm / (double)vc.size() << "\n";
            }
            else
            {
                ll i = vc.size() - 1;
                if (i - 1 > 0)
                {
                    vc[i - 1] += mi[i];
                    //mi[i] = 0;
                    mi[i - 1] = mi[i];
                }
                mi[i] = 0;
                sm -= vc.back();
                vc.pop_back();
                cout << (double)sm / (double)vc.size() << "\n";
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long ll;
#define fio                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
int main()
{
    fio;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll t;
    //cin >> t;
    t =1;
    while (t--)
    {
        ll n;
        cin >> n;
        ll sm = 0;
        vector<ll> vc;
        vc.push_back(0);
        cout<<fixed<<setprecision(6);
        while (n--)
        {
            ll tp;
            cin >> tp;
            if (tp == 1)
            {
                ll ele,pos;
                cin >> pos>>ele;
                for(ll i=0;i<pos;i++){
                    vc[i] += ele;
                    sm += ele;
                }
                cout << (double)sm / (double)vc.size()<<"\n";
            }
            else if (tp == 2)
            {
                ll ele;
                cin>>ele;
                vc.push_back(ele);
                sm+=ele;
                cout<<(double)sm/(double)vc.size()<<"\n";
            }
            else
            {
                sm-=vc.back();
                vc.pop_back();
                cout<<(double)sm/(double)vc.size()<<"\n";
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long ll;
#define fio                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
int main()
{
    fio;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll t;
    //cin >> t;
    t = 1;
    while (t--)
    {
        ll n;
        cin >> n;
        ll sm = 0;
        vector<ll> vc, mi(1, 0);
        vc.push_back(0);

        cout << fixed << setprecision(20);
        while (n--)
        {
            ll tp;
            cin >> tp;
            if (tp == 1)
            {
                ll ele, pos;
                cin >> pos >> ele;
                vc[pos - 1] += ele;
                mi[pos - 1] = ele;
                sm += (ele * pos);
                cout << (double)sm / (double)vc.size() << "\n";
            }
            else if (tp == 2)
            {
                ll ele;
                cin >> ele;
                vc.push_back(ele);
                mi.push_back(0);
                sm += ele;
                cout << (double)sm / (double)vc.size() << "\n";
            }
            else
            {
                ll i = vc.size() - 1;
                if (i - 1 > 0)
                {
                    vc[i - 1] +=  mi[i];
                    //mi[i] = 0;
                    mi[i - 1] += mi[i];
                }
                mi[i] = 0;
                sm -= vc.back();
                vc.pop_back();
                cout << (double)sm / (double)vc.size() << "\n";
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long ll;
#define fio                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
int main()
{
    fio;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll t;
    //cin >> t;
    t = 1;
    while (t--)
    {
        ll n;
        cin >> n;
        ll sm = 0;
        vector<ll> vc, mi(1, 0);
        vc.push_back(0);

        cout << fixed << setprecision(20);
        while (n--)
        {
            ll tp;
            cin >> tp;
            if (tp == 1)
            {
                ll ele, pos;
                cin >> pos >> ele;
                vc[pos - 1] += ele;
                mi[pos - 1] = ele;
                sm += (ele * pos);
                cout << (double)sm / (double)vc.size() << "\n";
            }
            else if (tp == 2)
            {
                ll ele;
                cin >> ele;
                vc.push_back(ele);
                mi.push_back(0);
                sm += ele;
                cout << (double)sm / (double)vc.size() << "\n";
            }
            else
            {
                ll i = vc.size() - 1;
                if (i - 1 > 0)
                {
                    vc[i - 1] += mi[i];
                    //mi[i] = 0;
                    mi[i - 1] = mi[i];
                }
                mi[i] = 0;
                sm -= vc.back();
                vc.pop_back();
                cout << (double)sm / (double)vc.size() << "\n";
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long ll;
#define fio                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
int main()
{
    fio;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll t;
    //cin >> t;
    t = 1;
    while (t--)
    {
        ll n;
        cin >> n;
        ll sm = 0;
        vector<ll> vc, mi(1, 0);
        vc.push_back(0);

        cout << fixed << setprecision(10);
        while (n--)
        {
            ll tp;
            cin >> tp;
            if (tp == 1)
            {
                ll ele, pos;
                cin >> pos >> ele;
                vc[pos - 1] += ele;
                mi[pos - 1] = ele;
                sm += (ele * pos);
                cout << (double)sm / (double)vc.size() << "\n";
            }
            else if (tp == 2)
            {
                ll ele;
                cin >> ele;
                vc.push_back(ele);
                mi.push_back(0);
                sm += ele;
                cout << (double)sm / (double)vc.size() << "\n";
            }
            else
            {
                ll i = vc.size() - 1;
                if (i - 1 > 0)
                {
                    vc[i - 1] += mi[i];
                    //mi[i] = 0;
                    mi[i - 1] = mi[i];
                }
                mi[i] = 0;
                sm -= vc.back();
                vc.pop_back();
                cout << (double)sm / (double)vc.size() << "\n";
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long ll;
#define fio                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
int main()
{
    fio;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll t;
    //cin >> t;
    t =1;
    while (t--)
    {
        ll n;
        cin >> n;
        ll sm = 0;
        vector<ll> vc;
        vc.push_back(0);
        while (n--)
        {
            ll tp;
            cin >> tp;
            if (tp == 1)
            {
                ll ele,pos;
                cin >> pos>>ele;
                for(ll i=0;i<pos;i++){
                    vc[i] += ele;
                    sm += ele;
                }
                cout << (double)sm / (double)vc.size()<<"\n";
            }
            else if (tp == 2)
            {
                ll ele;
                cin>>ele;
                vc.push_back(ele);
                sm+=ele;
                cout<<(double)sm/(double)vc.size()<<"\n";
            }
            else
            {
                sm-=vc.back();
                vc.pop_back();
                cout<<(double)sm/(double)vc.size()<<"\n";
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long ll;
#define fio                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
int main()
{
    fio;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll t;
    //cin >> t;
    t = 1;
    while (t--)
    {
        ll n;
        cin >> n;
        ll sm = 0;
        vector<ll> vc, mi(1, 0);
        vc.push_back(0);

        cout << fixed << setprecision(20);
        while (n--)
        {
            ll tp;
            cin >> tp;
            if (tp == 1)
            {
                ll ele, pos;
                cin >> pos >> ele;
                vc[pos - 1] += ele;
                mi[pos - 1] += ele;
                sm += (ele * pos);
                cout << (double)sm / (double)vc.size() << "\n";
            }
            else if (tp == 2)
            {
                ll ele;
                cin >> ele;
                vc.push_back(ele);
                mi.push_back(0);
                sm += ele;
                cout << (double)sm / (double)vc.size() << "\n";
            }
            else
            {
                ll i = vc.size() - 1;
                if (i - 1 > 0)
                {
                    vc[i - 1] +=  mi[i];
                    //mi[i] = 0;
                    mi[i - 1] += mi[i];
                }
                mi[i] = 0;
                sm -= vc.back();
                vc.pop_back();
                cout << (double)sm / (double)vc.size() << "\n";
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#define FIXED_FLOAT(x) std::fixed <<std::setprecision(6)<<(x)
#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define inf std::numeric_limits<int>::max();
#define highest_2_pow(n)  __builtin_clzll((long long)0)- __builtin_clzll((long long)n) - 1
//-----------------------------------------------------------------------------------------------------
#define lli long long int
#define int long long
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define vi vector<int>
#define vlli vector<long long int>
#define si set<int>
#define slli set<long long int>
#define mt make_tuple
#define mp make_pair
#define eb emplace_back
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll
//---------------------------------------------------
using namespace std;
// GCD and LCM are available
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}

void faster(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}
void solve(){
    int n;
    cin>>n;
    int tp;
    vi pref(n+1,0);
    vi arr(n+1,0);
    vi del(n+1,0);
    int ind = 0;
    int x,k,a;
    int sm=0;
    rep(i,0,n){
        cin>>tp;
        if(tp==1){
            cin>>a>>x;
            sm+=a*x;
            del[a-1] += x;
        }
        else if (tp==2){
            cin>>k;
            sm+=k;
            arr[++ind] = k;
        }
        else{
            int val = arr[ind] + del[ind];
            ind--;
            sm-=val;
            del[ind] += del[ind+1];
        }
        //error(sm,ind,del[1],arr[1]);
        cout<<FIXED_FLOAT((1.0*sm)/(ind+1))<<endl;
    }
}
signed main()
{
    faster();
    int t=1;
    //cin>>t;
    while(t--) solve();
}


#include <bits/stdc++.h>
#define FIXED_FLOAT(x) std::fixed <<std::setprecision(6)<<(x)
#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define inf std::numeric_limits<int>::max();
#define highest_2_pow(n)  __builtin_clzll((long long)0)- __builtin_clzll((long long)n) - 1
//-----------------------------------------------------------------------------------------------------
#define lli long long int
#define int long long
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define vi vector<int>
#define vlli vector<long long int>
#define si set<int>
#define slli set<long long int>
#define mt make_tuple
#define mp make_pair
#define eb emplace_back
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll
//---------------------------------------------------
using namespace std;
// GCD and LCM are available
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}

void faster(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}
void solve(){
    int n;
    cin>>n;
    int tp;
    vi pref(n+1,0);
    vi arr(n+1,0);
    vi del(n+1,0);
    int ind = 0;
    int x,k,a;
    int sm=0;
    rep(i,0,n){
        cin>>tp;
        if(tp==1){
            cin>>a>>x;
            sm+=a*x;
            del[a-1] += x;
        }
        else if (tp==2){
            cin>>k;
            sm+=k;
            arr[++ind] = k;
        }
        else{
            int val = arr[ind] + del[ind];
            arr[ind] = 0;
            del[ind] = 0;
            ind--;
            sm-=val;
            del[ind] += del[ind+1];
        }
        //error(sm,ind,del[1],arr[1]);
        cout<<FIXED_FLOAT(((double)sm)/(ind+1))<<endl;
    }
}
signed main()
{
    faster();
    int t=1;
    //cin>>t;
    while(t--) solve();
}


#include <bits/stdc++.h>
#define FIXED_FLOAT(x) std::fixed <<std::setprecision(8)<<(x)
#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define inf std::numeric_limits<int>::max();
#define highest_2_pow(n)  __builtin_clzll((long long)0)- __builtin_clzll((long long)n) - 1
//-----------------------------------------------------------------------------------------------------
#define lli long long int
#define int long long
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define vi vector<int>
#define vlli vector<long long int>
#define si set<int>
#define slli set<long long int>
#define mt make_tuple
#define mp make_pair
#define eb emplace_back
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll
//---------------------------------------------------
using namespace std;
// GCD and LCM are available
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}

void faster(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}
void solve(){
    int n;
    cin>>n;
    int tp;
    vi pref(n+1,0);
    vi arr(n+1,0);
    vi del(n+1,0);
    int ind = 0;
    int x,k,a;
    int sm=0;
    rep(i,0,n){
        cin>>tp;
        if(tp==1){
            cin>>a>>x;
            sm+=a*x;
            del[a-1] += x;
        }
        else if (tp==2){
            cin>>k;
            sm+=k;
            arr[++ind] = k;
        }
        else{
            int val = arr[ind] + del[ind];
            ind--;
            sm-=val;
            del[ind] += del[ind+1];
        }
        //error(sm,ind,del[1],arr[1]);
        cout<<FIXED_FLOAT(((double)sm)/(ind+1))<<endl;
    }
}
signed main()
{
    faster();
    int t=1;
    //cin>>t;
    while(t--) solve();
}