#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=11000;
int n=10000,m,cp=1,E=0,g=0;
int hd[N],ot[N+N],nt[N+N],f[N],d[N],u[N+N];
int a[N];
int bcj(const int x){return f[x]==x?x:f[x]=bcj(f[x]);}
void add(const int x,const int y)
{
    ++d[x],++d[y];
    f[bcj(x)]=bcj(y);
    ot[++cp]=y,nt[cp]=hd[x],hd[x]=cp;
    ot[++cp]=x,nt[cp]=hd[y],hd[y]=cp;
}
void init()
{
    for(int i=1;i<=n;++i) f[i]=i;
    scanf("%d",&m);
    for(int i=1,x,y;i<=m;++i)
        scanf("%d%d",&x,&y),add(x,y);
}
bool _no()
{
    if ( m==1 ) return 1;
    for(int i=1;i<=n;++i)
    {
        if ( f[i]==i && d[i]>0 ) ++E;
        if ( d[i]&1 ) a[++g]=i;
    }
    if ( E>2 || g>4 ) return 1;
    if ( g==4 && E==2 )
        return bcj(a[1])==bcj(a[2]) && bcj(a[2])==bcj(a[3]) && bcj(a[3])==bcj(a[4]);
    return 0;
}
int c[N],e[N];
bool dfs(const int x,const bool y,int *c)
{
    if ( d[x]==0 ) return 1;
    for(int i=hd[x];i!=0;i=nt[i] )
        if ( !u[i] )
        {
            --d[x],--d[ot[i]],--m;
            u[i]=u[i^1]=1;
            bool k=dfs(ot[i],y,c);
            c[++c[0]]=(i>>1);
            if ( k&y ) return k;
        }
    return 0;
}
void Gans()
{
    c[0]=0;
    if ( E==1 && g==0 )
    {
        for(int i=1;i<=n;++i)
            if ( d[i]>0 ) { dfs(i,0,c);break;}
        e[1]=c[c[0]--];
        e[0]=1;
    }else if ( E==1 && g==2 )
    {
        dfs(a[1],0,c);
        e[1]=c[c[0]--];e[0]=1;
    }else if ( E==1 && g==4 )
    {
        dfs(a[1],1,c);
        if ( d[a[1]]>0 ) dfs(a[1],1,c);
        for(int i=2;i<=4;++i)
            if ( d[a[i]]>0 ) dfs(a[i],0,e);
    }else {
        if ( g>0 ) dfs(a[1],0,e);
        for(int i=2;i<=g;++i)
            if ( d[a[i]]>0 ) dfs(a[i],0,c);
        for(int i=1;i<=n;++i)
            if ( d[i]>0 ) { dfs(i,0,c);break;}
        for(int i=1;i<=n;++i)
            if ( d[i]>0 ) dfs(i,0,e);
    }
    if ( E!=1 || g!=4 )
    {
        printf("%d\n",c[0]);
        for(int i=1;i<c[0];++i) printf("%d ",c[i]);
        printf("%d\n",c[c[0]]);
    }else {
        int now=a[1];m+=c[0];
        printf("%d\n",m);
        for(int i=c[0];i>=0;--i )
        {
            c[0]=i;
            if ( d[now]>0 ) dfs(now,0,c);
            for(int k=i+1;k<=c[0];++k)
            {
                printf("%d",c[k]);
                if ( k<c[0] || m>0 ) printf(" ");
            }
            if ( i==0 ) break;
            printf("%d",c[i]);--m;
                if ( m>0 ) printf(" ");
            if ( ot[c[i]*2]!=now ) now=ot[c[i]*2];else now=ot[c[i]*2+1];
        }puts("");
    }
    printf("%d\n",e[0]);
    for(int i=1;i<e[0];++i) printf("%d ",e[i]);
    printf("%d\n",e[e[0]]);
}
int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    init();
    if ( _no() ) puts("-1");
    else Gans();
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=11000;
int n=10000,m,cp=1,E=0,g=0;
int hd[N],ot[N+N],nt[N+N],f[N],d[N],u[N+N];
int a[N];
int bcj(const int x){return f[x]==x?x:f[x]=bcj(f[x]);}
void add(const int x,const int y)
{
    ++d[x],++d[y];
    f[bcj(x)]=bcj(y);
    ot[++cp]=y,nt[cp]=hd[x],hd[x]=cp;
    ot[++cp]=x,nt[cp]=hd[y],hd[y]=cp;
}
void init()
{
    for(int i=1;i<=n;++i) f[i]=i;
    scanf("%d",&m);
    for(int i=1,x,y;i<=m;++i)
        scanf("%d%d",&x,&y),add(x,y);
}
bool _no()
{
    if ( m==1 ) return 1;
    for(int i=1;i<=n;++i)
    {
        if ( f[i]==i && d[i]>0 ) ++E;
        if ( d[i]&1 ) a[++g]=i;
    }
    if ( E>2 || g>4 ) return 1;
    if ( g==4 && E==2 )
        return bcj(a[1])==bcj(a[2]) && bcj(a[2])==bcj(a[3]) && bcj(a[3])==bcj(a[4]);
    return 0;
}
int c[N],e[N];
bool dfs(const int x,const bool y,int *c)
{
    if ( d[x]==0 ) return 1;
    for(int i=hd[x];i!=0;i=nt[i] )
        if ( !u[i] )
        {
            --d[x],--d[ot[i]];
            u[i]=u[i^1]=1;
            bool k=dfs(ot[i],y,c);
            c[++c[0]]=(i>>1);
            if ( k&y ) return k;
        }
    return 0;
}
void Gans()
{
    c[0]=0;
    if ( E==1 && g==0 )
    {
        for(int i=1;i<=n;++i)
            if ( d[i]>0 ) { dfs(i,0,c);break;}
        e[1]=c[c[0]--];
        e[0]=1;
    }else if ( E==1 && g==2 )
    {
        dfs(a[1],0,c);
        e[1]=c[c[0]--];e[0]=1;
    }else if ( E==1 && g==4 )
    {
        dfs(a[1],1,c);
        if ( d[a[1]]>0 ) dfs(a[1],1,c);
        for(int i=2;i<=4;++i)
            if ( d[a[i]]>0 ) dfs(a[i],0,e);
    }else {
        if ( g>0 ) dfs(a[1],0,e);
        for(int i=2;i<=g;++i)
            if ( d[a[i]]>0 ) dfs(a[i],0,c);
        for(int i=1;i<=n;++i)
            if ( d[i]>0 ) dfs(i,0,c);
    }
    printf("%d\n",c[0]);
    for(int i=1;i<c[0];++i) printf("%d ",c[i]);
    printf("%d\n",c[c[0]]);
    printf("%d\n",e[0]);
    for(int i=1;i<e[0];++i) printf("%d ",e[i]);
    printf("%d\n",e[e[0]]);
}
int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    init();
    if ( _no() ) puts("-1");
    else Gans();
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=11000;
int n=10000,m,cp=1,E=0,g=0;
int hd[N],ot[N+N],nt[N+N],f[N],d[N],u[N+N];
int a[N];
int bcj(const int x){return f[x]==x?x:f[x]=bcj(f[x]);}
void add(const int x,const int y)
{
    ++d[x],++d[y];
    f[bcj(x)]=bcj(y);
    ot[++cp]=y,nt[cp]=hd[x],hd[x]=cp;
    ot[++cp]=x,nt[cp]=hd[y],hd[y]=cp;
}
void init()
{
    for(int i=1;i<=n;++i) f[i]=i;
    scanf("%d",&m);
    for(int i=1,x,y;i<=m;++i)
        scanf("%d%d",&x,&y),add(x,y);
}
bool _no()
{
    if ( m==1 ) return 1;
    for(int i=1;i<=n;++i)
    {
        if ( f[i]==i && d[i]>0 ) ++E;
        if ( d[i]&1 ) a[++g]=i;
    }
    if ( E>2 || g>4 ) return 1;
    if ( g==4 && E==2 )
        return bcj(a[1])==bcj(a[2]) && bcj(a[2])==bcj(a[3]) && bcj(a[3])==bcj(a[4]);
    return 0;
}
int c[N],e[N];
bool dfs(const int x,const bool y,int *c)
{
    if ( d[x]==0 ) return 1;
    for(int i=hd[x];i!=0;i=nt[i] )
        if ( !u[i] )
        {
            --d[x],--d[ot[i]],--m;
            u[i]=u[i^1]=1;
            bool k=dfs(ot[i],y,c);
            c[++c[0]]=(i>>1);
            if ( k&y ) return k;
        }
    return 0;
}
void Gans()
{
    c[0]=0;
    if ( E==1 && g==0 )
    {
        for(int i=1;i<=n;++i)
            if ( d[i]>0 ) { dfs(i,0,c);break;}
        e[1]=c[c[0]--];
        e[0]=1;
    }else if ( E==1 && g==2 )
    {
        dfs(a[1],0,c);
        e[1]=c[c[0]--];e[0]=1;
    }else if ( E==1 && g==4 )
    {
        dfs(a[1],1,c);
        if ( d[a[1]]>0 ) dfs(a[1],1,c);
        for(int i=2;i<=4;++i)
            if ( d[a[i]]>0 ) dfs(a[i],0,e);
    }else {
        if ( g>0 ) dfs(a[1],0,e);
        for(int i=2;i<=g;++i)
            if ( d[a[i]]>0 ) dfs(a[i],0,c);
        for(int i=1;i<=n;++i)
            if ( d[i]>0 ) { dfs(i,0,c);break;}
        for(int i=1;i<=n;++i)
            if ( d[i]>0 ) dfs(i,0,e);
    }
    if ( E!=1 || g!=4 )
    {
        printf("%d\n",c[0]);
        for(int i=1;i<c[0];++i) printf("%d ",c[i]);
        printf("%d\n",c[c[0]]);
    }else {
        int now=a[1];
        printf("%d\n",c[0]+m);
        for(int i=c[0];i>=0;--i )
        {
            c[0]=i;
            if ( d[now]>0 ) dfs(d[now],0,c);
            for(int k=i+1;k<=c[0];++k) printf("%d ",c[k]);
            if ( i==0 ) break;
            printf("%d ",c[i]);
            if ( ot[c[i]*2]!=now ) now=ot[c[i]*2];else now=ot[c[i]*2+1];
        }puts("");
    }
    printf("%d\n",e[0]);
    for(int i=1;i<e[0];++i) printf("%d ",e[i]);
    printf("%d\n",e[e[0]]);
}
int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    init();
    if ( _no() ) puts("-1");
    else Gans();
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=11000;
int n=10000,m,cp=1,E=0,g=0;
int hd[N],ot[N+N],nt[N+N],f[N],d[N],u[N+N];
int a[N];
int bcj(const int x){return f[x]==x?x:f[x]=bcj(f[x]);}
void add(const int x,const int y)
{
    ++d[x],++d[y];
    f[bcj(x)]=bcj(y);
    ot[++cp]=y,nt[cp]=hd[x],hd[x]=cp;
    ot[++cp]=x,nt[cp]=hd[y],hd[y]=cp;
}
void init()
{
    for(int i=1;i<=n;++i) f[i]=i;
    scanf("%d",&m);
    for(int i=1,x,y;i<=m;++i)
        scanf("%d%d",&x,&y),add(x,y);
}
bool _no()
{
    if ( m==1 ) return 1;
    for(int i=1;i<=n;++i)
    {
        if ( f[i]==i && d[i]>0 ) ++E;
        if ( d[i]&1 ) a[++g]=i;
    }
    if ( E>2 || g>4 ) return 1;
    if ( g==4 && E==2 )
        return bcj(a[1])==bcj(a[2]) && bcj(a[2])==bcj(a[3]) && bcj(a[3])==bcj(a[4]);
    return 0;
}
int c[N],e[N];
bool dfs(const int x,const bool y,int *c)
{
    if ( d[x]==0 ) return 1;
    for(int i=hd[x];i!=0;i=nt[i] )
        if ( !u[i] )
        {
            --d[x],--d[ot[i]];
            u[i]=u[i^1]=1;
            bool k=dfs(ot[i],y,c);
            c[++c[0]]=(i>>1);
            if ( k&y ) return k;
        }
    return 0;
}
void Gans()
{
    c[0]=0;
    if ( E==1 && g==0 )
    {
        for(int i=1;i<=n;++i)
            if ( d[i]>0 ) { dfs(i,0,c);break;}
        e[1]=c[c[0]--];
        e[0]=1;
    }else if ( E==1 && g==2 )
    {
        dfs(a[1],0,c);
        e[1]=c[c[0]--];e[0]=1;
    }else if ( E==1 && g==4 )
    {
        dfs(a[1],1,c);
        if ( d[a[1]]>0 ) dfs(a[1],1,c);
        for(int i=2;i<=4;++i)
            if ( d[a[i]]>0 ) dfs(a[i],0,e);
    }else {
        if ( g>0 ) dfs(a[1],0,e);
        for(int i=2;i<=g;++i)
            if ( d[a[i]]>0 ) dfs(a[i],0,c);
        for(int i=1;i<=n;++i)
            if ( d[i]>0 ) dfs(i,0,c);
    }
    printf("%d\n",c[0]);
    for(int i=1;i<c[0];++i) printf("%d ",c[i]);
    printf("%d\n",c[c[0]]);
    printf("%d\n",e[0]);
    for(int i=1;i<e[0];++i) printf("%d ",e[i]);
    printf("%d\n",e[e[0]]);
}
int main()
{
    init();
    if ( _no() ) puts("-1");
    else Gans();
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=11000;
int n=10000,m,cp=1,E=0,g=0;
int hd[N],ot[N+N],nt[N+N],f[N],d[N],u[N+N];
int a[N];
int bcj(const int x){return f[x]==x?x:f[x]=bcj(f[x]);}
void add(const int x,const int y)
{
    ++d[x],++d[y];
    f[bcj(x)]=bcj(y);
    ot[++cp]=y,nt[cp]=hd[x],hd[x]=cp;
    ot[++cp]=x,nt[cp]=hd[y],hd[y]=cp;
}
void init()
{
    for(int i=1;i<=n;++i) f[i]=i;
    scanf("%d",&m);
    for(int i=1,x,y;i<=m;++i)
        scanf("%d%d",&x,&y),add(x,y);
}
bool _no()
{
    if ( m==1 ) return 1;
    for(int i=1;i<=n;++i)
    {
        if ( f[i]==i && d[i]>0 ) ++E;
        if ( d[i]&1 ) a[++g]=i;
    }
    if ( E>2 || g>4 ) return 1;
    if ( g==4 && E==2 )
        return bcj(a[1])==bcj(a[2]) && bcj(a[2])==bcj(a[3]) && bcj(a[3])==bcj(a[4]);
    return 0;
}
int c[N],e[N];
bool dfs(const int x,const bool y,int *c)
{
    if ( d[x]==0 ) return 1;
    for(int i=hd[x];i!=0;i=nt[i] )
        if ( !u[i] )
        {
            --d[x],--d[ot[i]];
            u[i]=u[i^1]=1;
            bool k=dfs(ot[i],y,c);
            c[++c[0]]=(i>>1);
            if ( k&y ) return k;
        }
    return 0;
}
void Gans()
{
    c[0]=0;
    if ( E==1 && g==0 )
    {
        for(int i=1;i<=n;++i)
            if ( d[i]>0 ) { dfs(i,0,c);break;}
        e[1]=c[c[0]--];
        e[0]=1;
    }else if ( E==1 && g==2 )
    {
        dfs(a[1],0,c);
        e[1]=c[c[0]--];e[0]=1;
    }else if ( E==1 && g==4 )
    {
        dfs(a[1],1,c);
        if ( d[a[1]]>0 ) dfs(a[1],1,c);
        for(int i=2;i<=4;++i)
            if ( d[a[i]]>0 ) dfs(a[i],0,e);
    }else {
        if ( g>0 ) dfs(a[1],0,e);
        for(int i=2;i<=g;++i)
            if ( d[a[i]]>0 ) dfs(a[i],0,c);
        for(int i=1;i<=n;++i)
            if ( d[i]>0 ) { dfs(i,0,c);break;}
        for(int i=1;i<=n;++i)
            if ( d[i]>0 ) dfs(i,0,e);
    }
    printf("%d\n",c[0]);
    for(int i=1;i<c[0];++i) printf("%d ",c[i]);
    printf("%d\n",c[c[0]]);
    printf("%d\n",e[0]);
    for(int i=1;i<e[0];++i) printf("%d ",e[i]);
    printf("%d\n",e[e[0]]);
}
int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    init();
    if ( _no() ) puts("-1");
    else Gans();
    return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

const int N = 10005;

struct Edge
{
	Edge(){}
	Edge(int i, int id) : v(i), index(id)
	{
	}
	int v;
	int index;
};

vector<Edge> graph[N];
vector<int> odds[3];
vector<int> path;
int com[N];
bool used[N];
bool hasIndex[N];
int next[N];

void dfs(int u, int c)
{
	com[u] = c;
	int i, v;
	for (i = 0; i < graph[u].size(); i++)
	{
		v = graph[u][i].v;
		if (!com[v])
		{
			dfs(v, c);
		}
	}
}

void eular(int u)
{
	int index, v;
	while (next[u] < graph[u].size())
	{
		if (used[graph[u][next[u]].index])
		{
			next[u]++;
			continue;
		}
		v = graph[u][next[u]].v;
		index = graph[u][next[u]].index;
		next[u]++;
		used[index] = true;
		eular(v);

		path.push_back(index);
	}
}

int main()
{
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);

	int m, i, j, k, u, v, n;
	bool ok = true;
	vector<int> ans[3];
	scanf("%d", &m);
	n = 0;

	for (i = 1; i <= m; i++)
	{
		scanf("%d%d", &u, &v);
		n = max(n, max(u, v));
		hasIndex[u] = hasIndex[v] = true;

		graph[u].push_back(Edge(v, i));
		graph[v].push_back(Edge(u, i));
	}

	int c = 0;
	for (i = 1; i <= n; i++)
	{
		if (!hasIndex[i])
		{
			continue;
		}
		if (!com[i])
		{
			++c;
			dfs(i, c);
		}
	}

	for (i = 1; i <= n; i++)
	{
		if (!hasIndex[i])
		{
			continue;
		}
		if (graph[i].size() & 1)
		{
			if (com[i] == 1)
			{
				odds[1].push_back(i);
			}
			else if (com[i] == 2)
			{
				odds[2].push_back(i);
			}
		}
	}

	if (c > 2)
	{
		ok = false;
	}
	else if (c == 2)
	{
		for (k = 1; k <= 2; k++)
		{
			if (odds[k].size() == 0)
			{
				for (i = 1; i <= n && com[i] != k; i++);
				eular(i);
				ans[k] = path;
				path.clear();
			}
			else if (odds[k].size() == 2)
			{
				eular(odds[k][0]);
				ans[k] = path;
				path.clear();
			}
			else
			{
				ok = false;
				break;
			}
		}
	}
	else
	{
		if (odds[1].size() == 0 || odds[1].size() == 2)
		{
			int start;
			for (start = 1; start <= n && com[start] != 1; start++);

			if (odds[1].size() == 2)
			{
				start = odds[1][0];
			}
			eular(start);
			if (path.size() < 2)
			{
				ok = false;
			}
			else
			{
				ans[1] = path;
				ans[1].pop_back();
				ans[2].push_back(path[path.size() - 1]);
			}
		}
		else if (odds[1].size() == 4)
		{
			u = odds[1][0];
			v = odds[1][1];
			graph[u].push_back(Edge(v, 0));
			graph[v].push_back(Edge(u, 0));
			eular(odds[1][2]);
			for (i = 0; path[i] != 0; i++)
			{
				ans[1].push_back(path[i]);
			}

			for (i++; i < path.size(); i++)
			{
				ans[2].push_back(path[i]);
			}
		}
		else
		{
			ok = false;
		}
	}

	if (!ok)
	{
		printf("-1\n");
	}
	else
	{
		for (k = 1; k <= 2; k++)
		{
			printf("%d\n", ans[k].size());
			for (i = 0; i < ans[k].size(); i++)
			{
				printf("%d ", ans[k][i]);
			}
			printf("\n");
		}
	}
}


#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

const int N = 10005;

struct Edge
{
	Edge(){}
	Edge(int i, int id) : v(i), index(id)
	{
	}
	int v;
	int index;
};

vector<Edge> graph[N];
vector<int> odds[3];
vector<int> path;
int com[N];
bool used[N];
bool hasIndex[N];
int next[N];

void dfs(int u, int c)
{
	com[u] = c;
	int i, v;
	for (i = 0; i < graph[u].size(); i++)
	{
		v = graph[u][i].v;
		if (!com[v])
		{
			dfs(v, c);
		}
	}
}

void eular(int u)
{
	int index, v;
	while (next[u] < graph[u].size())
	{
		if (used[graph[u][next[u]].index])
		{
			next[u]++;
			continue;
		}
		v = graph[u][next[u]].v;
		index = graph[u][next[u]].index;
		next[u]++;
		used[index] = true;
		eular(v);

		path.push_back(index);
	}
}

int main()
{
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);

	int m, i, j, k, u, v, n;
	bool ok = true;
	vector<int> ans[3];
	scanf("%d", &m);
	n = 0;

	for (i = 1; i <= m; i++)
	{
		scanf("%d%d", &u, &v);
		n = max(n, max(u, v));
		hasIndex[u] = hasIndex[v] = true;

		graph[u].push_back(Edge(v, i));
		graph[v].push_back(Edge(u, i));
	}

	int c = 0;
	for (i = 1; i <= n; i++)
	{
		if (!hasIndex[i])
		{
			continue;
		}
		if (!com[i])
		{
			++c;
			dfs(i, c);
		}
	}

	for (i = 1; i <= n; i++)
	{
		if (!hasIndex[i])
		{
			continue;
		}
		if (graph[i].size() & 1)
		{
			if (com[i] == 1)
			{
				odds[1].push_back(i);
			}
			else if (com[i] == 2)
			{
				odds[2].push_back(i);
			}
		}
	}

	if (c > 2)
	{
		ok = false;
	}
	else if (c == 2)
	{
		for (k = 1; k <= 2; k++)
		{
			if (odds[k].size() == 0)
			{
				for (i = 1; i <= n && com[i] != k; i++);
				eular(i);
				ans[k] = path;
				path.clear();
			}
			else if (odds[k].size() == 2)
			{
				eular(odds[k][0]);
				ans[k] = path;
				path.clear();
			}
			else
			{
				ok = false;
				break;
			}
		}
	}
	else
	{
		if (odds[1].size() == 0 || odds[1].size() == 2)
		{
			int start;
			for (start = 1; start <= n && com[start] != 1; start++);

			if (odds[1].size() == 2)
			{
				start = odds[1][0];
			}
			eular(start);
			if (path.size() < 2)
			{
				ok = false;
			}
			else
			{
				ans[1] = path;
				ans[1].pop_back();
				ans[2].push_back(path[path.size() - 1]);
			}
		}
		else if (odds[1].size() == 4)
		{
			u = odds[1][0];
			v = odds[1][1];
			graph[u].push_back(Edge(v, 0));
			graph[v].push_back(Edge(u, 0));
			Edge(odds[1][2]);
			for (i = 0; path[i] != 0; i++)
			{
				ans[1].push_back(path[i]);
			}

			for (i++; i < path.size(); i++)
			{
				ans[2].push_back(path[i]);
			}
		}
		else
		{
			ok = false;
		}
	}

	if (!ok)
	{
		printf("-1\n");
	}
	else
	{
		for (k = 1; k <= 2; k++)
		{
			printf("%d\n", ans[k].size());
			for (i = 0; i < ans[k].size(); i++)
			{
				printf("%d ", ans[k][i]);
			}
			printf("\n");
		}
	}
}


#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

const int N = 10005;

struct Edge
{
	Edge(){}
	Edge(int i, int id) : v(i), index(id)
	{
	}
	int v;
	int index;
};

vector<Edge> graph[N];
vector<int> odds[3];
vector<int> path;
int com[N];
bool used[N];
bool hasIndex[N];
int next[N];

void dfs(int u, int c)
{
	com[u] = c;
	int i, v;
	for (i = 0; i < graph[u].size(); i++)
	{
		v = graph[u][i].v;
		if (!com[v])
		{
			dfs(v, c);
		}
	}
}

void eular(int u)
{
	int index, v;
	while (next[u] < graph[u].size())
	{
		if (used[graph[u][next[u]].index])
		{
			next[u]++;
			continue;
		}
		v = graph[u][next[u]].v;
		index = graph[u][next[u]].index;
		next[u]++;
		used[index] = true;
		eular(v);

		path.push_back(index);
	}
}

int main()
{
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);

	int m, i, j, k, u, v, n;
	bool ok = true;
	vector<int> ans[3];
	scanf("%d", &m);
	n = 0;

	for (i = 1; i <= m; i++)
	{
		scanf("%d%d", &u, &v);
		n = max(n, max(u, v));
		hasIndex[u] = hasIndex[v] = true;

		graph[u].push_back(Edge(v, i));
		graph[v].push_back(Edge(u, i));
	}

	int c = 0;
	for (i = 1; i <= n; i++)
	{
		if (!hasIndex[i])
		{
			continue;
		}
		if (!com[i])
		{
			++c;
			dfs(i, c);
		}
	}

	for (i = 1; i <= n; i++)
	{
		if (!hasIndex[i])
		{
			continue;
		}
		if (graph[i].size() & 1)
		{
			if (com[i] == 1)
			{
				odds[1].push_back(i);
			}
			else if (com[i] == 2)
			{
				odds[2].push_back(i);
			}
		}
	}

	if (c > 2)
	{
		ok = false;
	}
	else if (c == 2)
	{
		for (k = 1; k <= 2; k++)
		{
			if (odds[k].size() == 0)
			{
				for (i = 1; i <= n && com[i] != k; i++);
				eular(i);
				ans[k] = path;
				path.clear();
			}
			else if (odds[k].size() == 2)
			{
				eular(odds[k][0]);
				ans[k] = path;
				path.clear();
			}
			else
			{
				ok = false;
				break;
			}
		}
	}
	else
	{
		if (odds[1].size() == 0 || odds[1].size() == 2)
		{
			int start = 1;
			if (odds[1].size() == 2)
			{
				start = odds[1][0];
			}
			eular(start);
			if (path.size() < 2)
			{
				ok = false;
			}
			else
			{
				ans[1] = path;
				ans[1].pop_back();
				ans[2].push_back(path[path.size() - 1]);
			}
		}
		else if (odds[1].size() == 4)
		{
			u = odds[1][0];
			v = odds[1][1];
			graph[u].push_back(Edge(v, 0));
			graph[v].push_back(Edge(u, 0));
			Edge(odds[1][2]);
			for (i = 0; path[i] != 0; i++)
			{
				ans[1].push_back(path[i]);
			}

			for (i++; i < path.size(); i++)
			{
				ans[2].push_back(path[i]);
			}
		}
		else
		{
			ok = false;
		}
	}

	if (!ok)
	{
		printf("-1\n");
	}
	else
	{
		for (k = 1; k <= 2; k++)
		{
			printf("%d\n", ans[k].size());
			for (i = 0; i < ans[k].size(); i++)
			{
				printf("%d ", ans[k][i]);
			}
			printf("\n");
		}
	}
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define M 10100
using namespace std;
struct abcd{
    int to,num,next;
    bool flag;
}table[M<<1];
int head[M],tot=1;
int n=10000,m,a[2],degree[M];
int stack[M],top;
void Add(int x,int y,int z)
{
    degree[y]++;
    table[++tot].to=y;
    table[tot].num=z;
    table[tot].next=head[x];
    head[x]=tot;
}
namespace Union_Find_Set{
    int fa[M],rank[M];
    int Find(int x)
    {
        if(!fa[x]||fa[x]==x)
            return fa[x]=x;
        return fa[x]=Find(fa[x]);
    }
    void Union(int x,int y)
    {
        x=Find(x);y=Find(y);
        if(x==y) return ;
        if(rank[x]>rank[y])
            swap(x,y);
        if(rank[x]==rank[y])
            rank[y]++;
        fa[x]=y;
    }
}
void DFS(int x)
{
    int i;
    for(i=head[x];i;i=head[x])
    {
        head[x]=table[head[x]].next;
        if(table[i].flag)
            continue;
        table[i^1].flag=true;
        DFS(table[i].to);
        stack[++top]=table[i].num;
    }
}
int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    using namespace Union_Find_Set;
    int i,x,y;
    cin>>m;
    if(m==1)
    {
        cout<<-1<<endl;
        return 0;
    }
    for(i=1;i<=m;i++)
    {
        scanf("%d%d",&x,&y);
        Add(x,y,i);Add(y,x,i);
        Union(x,y);
    }
    for(i=1;i<=n;i++)
        if(head[i])
        {
            if(!a[0])
                a[0]=i;
            else if(Find(i)!=Find(a[0]))
            {
                if(!a[1])
                    a[1]=i;
                else if(Find(i)!=Find(a[1]))
                    return cout<<-1<<endl,0;
            }
        }
    if(a[1])
    {
        int cnt[2]={0,0};
        int st[2]={a[0],a[1]};
        for(i=1;i<=n;i++)
            if(degree[i]&1)
            {
                cnt[Find(i)==Find(a[1])]++;
                st[Find(i)==Find(a[1])]=i;
            }
        if(cnt[0]>2||cnt[1]>2)
            return cout<<-1<<endl,0;
        DFS(st[0]);
        cout<<top<<endl;
        while(top)
            printf("%d%c",stack[top],top==1?'\n':' '),top--;
        DFS(st[1]);
        cout<<top<<endl;
        while(top)
            printf("%d%c",stack[top],top==1?'\n':' '),top--;
    }
    else
    {
        int st[4]={0,0,0,0};
        for(i=1;i<=n;i++)
            if(degree[i]&1)
            {
                if(!st[0])
                    st[0]=i;
                else if(!st[1])
                    st[1]=i;
                else if(!st[2])
                    st[2]=i;
                else if(!st[3])
                    st[3]=i;
                else
                    return cout<<-1<<endl,0;
            }
        if(!st[0])
        {
            DFS(a[0]);
            cout<<1<<'\n'<<stack[top--]<<endl;
            cout<<top<<endl;
            while(top)
                printf("%d%c",stack[top],top==1?'\n':' '),top--;
        }
        else if(!st[2])
        {
            DFS(st[0]);
            cout<<1<<'\n'<<stack[top--]<<endl;
            cout<<top<<endl;
            while(top)
                printf("%d%c",stack[top],top==1?'\n':' '),top--;
        }
        else
        {
            Add(st[0],st[1],m+1);
            DFS(st[2]);
            for(i=1;i<=top;i++)
                if(stack[i]==m+1)
                    break;
            cout<<top-i<<endl;
            while(top>i)
                printf("%d%c",stack[top],top==1?'\n':' '),top--;
            top--;
            cout<<top<<endl;
            while(top)
                printf("%d%c",stack[top],top==1?'\n':' '),top--;
        }
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define M 10100
using namespace std;
struct abcd{
	int to,num,next;
	bool flag;
}table[M<<1];
int head[M],tot=1;
int n=10000,m,a[2],degree[M];
int stack[M],top;
void Add(int x,int y,int z)
{
	degree[y]++;
	table[++tot].to=y;
	table[tot].num=z;
	table[tot].next=head[x];
	head[x]=tot;
}
namespace Union_Find_Set{
	int fa[M],rank[M];
	int Find(int x)
	{
		if(!fa[x]||fa[x]==x)
			return fa[x]=x;
		return fa[x]=Find(fa[x]);
	}
	void Union(int x,int y)
	{
		x=Find(x);y=Find(y);
		if(x==y) return ;
		if(rank[x]>rank[y])
			swap(x,y);
		if(rank[x]==rank[y])
			rank[y]++;
		fa[x]=y;
	}
}
void DFS(int x)
{
	int i;
	for(i=head[x];i;i=head[x])
	{
		head[x]=table[head[x]].next;
		if(table[i].flag)
			continue;
		table[i^1].flag=true;
		DFS(table[i].to);
		stack[++top]=table[i].num;
	}
}
int main()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	using namespace Union_Find_Set;
	int i,x,y;
	cin>>m;
	if(m==1)
	{
		cout<<-1<<endl;
		return 0;
	}
	for(i=1;i<=m;i++)
	{
		scanf("%d%d",&x,&y);
		Add(x,y,i);Add(y,x,i);
		Union(x,y);
	}
	for(i=1;i<=n;i++)
		if(head[i])
		{
			if(!a[0])
				a[0]=i;
			else if(Find(i)!=Find(a[0]))
			{
				if(!a[1])
					a[1]=i;
				else if(Find(i)!=Find(a[1]))
					return cout<<-1<<endl,0;
			}
		}
	if(a[1])
	{
		int cnt[2]={0,0};
		int st[2]={a[0],a[1]};
		for(i=1;i<=n;i++)
			if(degree[i]&1)
			{
				cnt[Find(i)==Find(a[1])]++;
				st[Find(i)==Find(a[1])]=i;
			}
		if(cnt[0]>2||cnt[1]>2)
			return cout<<-1<<endl,0;
		DFS(st[0]);
		cout<<top<<endl;
		while(top)
			printf("%d%c",stack[top],top==1?'\n':' '),top--;
		DFS(st[1]);
		cout<<top<<endl;
		while(top)
			printf("%d%c",stack[top],top==1?'\n':' '),top--;
	}
	else
	{
		int st[4]={0,0,0,0};
		for(i=1;i<=n;i++)
			if(degree[i]&1)
			{
				if(!st[0])
					st[0]=i;
				else if(!st[1])
					st[1]=i;
				else if(!st[2])
					st[2]=i;
				else if(!st[3])
					st[3]=i;
				else
					return cout<<-1<<endl,0;
			}
		if(!st[0])
		{
			DFS(a[0]);
			cout<<1<<'\n'<<stack[top--]<<endl;
			cout<<top<<endl;
			while(top)
				printf("%d%c",stack[top],top==1?'\n':' '),top--;
		}
		else if(!st[2])
		{
			DFS(st[0]);
			cout<<1<<'\n'<<stack[top--]<<endl;
			cout<<top<<endl;
			while(top)
				printf("%d%c",stack[top],top==1?'\n':' '),top--;
		}
		else
		{
			Add(st[0],st[1],m+1);
			Add(st[1],st[0],m+1);
			DFS(st[2]);
			for(i=1;i<=top;i++)
				if(stack[i]==m+1)
					break;
			cout<<top-i<<endl;
			while(top>i)
				printf("%d%c",stack[top],top==i+1?'\n':' '),top--;
			top--;
			cout<<top<<endl;
			while(top)
				printf("%d%c",stack[top],top==1?'\n':' '),top--;
		}
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define M 10100
using namespace std;
struct abcd{
    int to,num,next;
    bool flag;
}table[M<<1];
int head[M],tot=1;
int n=10000,m,a[2],degree[M];
int stack[M],top;
void Add(int x,int y,int z)
{
    degree[y]++;
    table[++tot].to=y;
    table[tot].num=z;
    table[tot].next=head[x];
    head[x]=tot;
}
namespace Union_Find_Set{
    int fa[M],rank[M];
    int Find(int x)
    {
        if(!fa[x]||fa[x]==x)
            return fa[x]=x;
        return fa[x]=Find(fa[x]);
    }
    void Union(int x,int y)
    {
        x=Find(x);y=Find(y);
        if(x==y) return ;
        if(rank[x]>rank[y])
            swap(x,y);
        if(rank[x]==rank[y])
            rank[y]++;
        fa[x]=y;
    }
}
void DFS(int x)
{
    int i;
    for(i=head[x];i;i=head[x])
    {
        head[x]=table[head[x]].next;
        if(table[i].flag)
            continue;
        table[i^1].flag=true;
        DFS(table[i].to);
        stack[++top]=table[i].num;
    }
}
int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    using namespace Union_Find_Set;
    int i,x,y;
    cin>>m;
    if(m==1)
    {
        cout<<-1<<endl;
        return 0;
    }
    for(i=1;i<=m;i++)
    {
        scanf("%d%d",&x,&y);
        Add(x,y,i);Add(y,x,i);
        Union(x,y);
    }
    for(i=1;i<=n;i++)
        if(head[i])
        {
            if(!a[0])
                a[0]=i;
            else if(Find(i)!=Find(a[0]))
            {
                if(!a[1])
                    a[1]=i;
                else if(Find(i)!=Find(a[1]))
                    return cout<<-1<<endl,0;
            }
        }
    if(a[1])
    {
        int cnt[2]={0,0};
        int st[2]={a[0],a[1]};
        for(i=1;i<=n;i++)
            if(degree[i]&1)
            {
                cnt[Find(i)==Find(a[1])]++;
                st[Find(i)==Find(a[1])]=i;
            }
        if(cnt[0]>2||cnt[1]>2)
            return cout<<-1<<endl,0;
        DFS(st[0]);
        cout<<top<<endl;
        while(top)
            printf("%d%c",stack[top],top==1?'\n':' '),top--;
        DFS(st[1]);
        cout<<top<<endl;
        while(top)
            printf("%d%c",stack[top],top==1?'\n':' '),top--;
    }
    else
    {
        int st[4]={0,0,0,0};
        for(i=1;i<=n;i++)
            if(degree[i]&1)
            {
                if(!st[0])
                    st[0]=i;
                else if(!st[1])
                    st[1]=i;
                else if(!st[2])
                    st[2]=i;
                else if(!st[3])
                    st[3]=i;
                else
                    return cout<<-1<<endl,0;
            }
        if(!st[0])
        {
            DFS(a[0]);
            cout<<1<<'\n'<<stack[top--]<<endl;
            cout<<top<<endl;
            while(top)
                printf("%d%c",stack[top],top==1?'\n':' '),top--;
        }
        else if(!st[2])
        {
            DFS(st[0]);
            cout<<1<<'\n'<<stack[top--]<<endl;
            cout<<top<<endl;
            while(top)
                printf("%d%c",stack[top],top==1?'\n':' '),top--;
        }
        else
        {
            Add(st[0],st[1],m+1);
            DFS(st[2]);
            for(i=1;i<=top;i++)
                if(stack[i]==m+1)
                    break;
            cout<<top-i<<endl;
            while(top>i)
                printf("%d%c",stack[top],top==i+1?'\n':' '),top--;
            top--;
            cout<<top<<endl;
            while(top)
                printf("%d%c",stack[top],top==1?'\n':' '),top--;
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

const int N = 10001, M = 10001;
int x[M], y[M];
int d[N], p[N], bg;
int n, m, l;

vector<int> adj[N];

void print_path(){
	for (int i=1;i<l;i++)
		cout << p[i] << " ";
	cout << p[l] << endl;
}

void dfs(int u){
	d[u]--;

	//cout << u << endl;

	int v, j;
	for (int i=0;i<adj[u].size();i++){
		j = adj[u][i], v = x[j]!=u ? x[j] : y[j];
		if (d[v]!=0) {
			p[++l] = j; d[v]--;
		//	cout << j << " ";
			dfs(v);
		}
	}
}

void init(){
	cin >> m;
	for (int i=1;i<=m;i++){
		cin >> x[i] >> y[i]; n = max(n, x[i]), n = max(n, y[i]);
		adj[x[i]].push_back(i);
		adj[y[i]].push_back(i);
		d[x[i]]++, d[y[i]]++;
	}
}

void solve(){
	int stat = 0;
	for (int i=1;i<=n;i++){
		if ((d[i]&1)==1) {
			stat++;
			bg = i;
		}
	}

	if (stat==2 && m==1 || stat!=2 && stat!=4){
		cout << -1 << endl;
		return;
	}

	if (stat==2){
		dfs(bg); cout << endl;

		cout << m - 1 << endl;
		for (int i=1;i<m-1;i++)
			cout << p[i] << " ";
		cout << p[m-1] << endl;

		cout << 1 << endl;
		cout << p[m] << endl;
	}

	if (stat==4){
		dfs(bg);
		print_path();

		l = 0;
		for (int i=1;i<=n;i++)
			if ((d[i]&1)==1) bg = i;
		dfs(bg);
		print_path();
	}
}

int main(){
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	init(); solve();
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

const int N = 10001, M = 10001;
int x[M], y[M];
int d[N], p[N], pp[N], bg;
int n, m, l, ll;

vector<int> adj[N];

void print_path(){
	cout << l << endl;
	for (int i=1;i<l;i++)
		cout << p[i] << " ";
	cout << p[l] << endl;
}

void dfs(int u, int uu){
	d[u]--;

	int v, j;
	for (int i=0;i<adj[u].size();i++){
		j = adj[u][i], v = x[j]!=u ? x[j] : y[j];
		if (d[v]!=0 && v!=uu) {
			d[v]--, dfs(v, u);
			p[++l] = j;
		}
	}
}

void init(){
	cin >> m;
	for (int i=1;i<=m;i++){
		cin >> x[i] >> y[i]; n = max(n, x[i]), n = max(n, y[i]);
		adj[x[i]].push_back(i);
		adj[y[i]].push_back(i);
		d[x[i]]++, d[y[i]]++;
	}
}

void solve(){
	int stat = 0;
	for (int i=1;i<=n;i++){
		if ((d[i]&1)==1) {
			stat++;
			bg = i;
		}
	}

	if (stat==2 && m==1 || stat!=2 && stat!=4){
		cout << -1 << endl;
		return;
	}

	if (stat==2){
		dfs(bg, 0);

		cout << m - 1 << endl;
		for (int i=1;i<m-1;i++)
			cout << p[i] << " ";
		cout << p[m-1] << endl;

		cout << 1 << endl;
		cout << p[m] << endl;
	}

	if (stat==4){
		dfs(bg, 0);
		memcpy(pp, p, sizeof(p)); ll = l;

		l = 0;
		for (int i=1;i<=n;i++)
			if ((d[i]&1)==1) bg = i;
		dfs(bg, 0);

		if (l + ll != m){
			cout << -1 << endl;
			return;
		}

		print_path();
		memcpy(pp, p, sizeof(p)); l = ll;
		print_path();

	}
}

int main(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	init(); solve();
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

const int N = 10001, M = 10001;
vector<int> adj[N];
int x[M], y[M]; bool used[M];
int degree[N];
int p[N], pp[N], l, ll;
int n, m;

void dfs(int u){

	//cout << u << endl;

	int v, j;
	for (int i=0;i<adj[u].size();i++){
		j = adj[u][i]; if (used[j]) continue;
		v = x[j]!=u ? x[j] : y[j];

		//cout << "-" << v << endl;
		if (degree[v]!=0){
			degree[u]--, degree[v]--, used[j] = true, dfs(v),
			p[++l] = j;
		}
	}
}

void init(){
	cin >> m;
	for (int i=1;i<=m;i++){
		cin >> x[i] >> y[i]; n = max(n, x[i]), n = max(n, y[i]);
		adj[x[i]].push_back(i), adj[y[i]].push_back(i);
		degree[x[i]]++, degree[y[i]]++;
	}
}

void solve(){
	int ss = 0, s = 1;
	for (int i=1;i<=n;i++)
		if ((degree[i]&1)==1) ss++, s = i;

	if (ss!=0 && ss!=2 && ss!=4 || m==1){
		cout << -1 << endl;
		return;
	}

	l = 0, dfs(s);
	if (l==m) {
		cout << m-1 << endl;
		for (int i=1;i<=m-2;i++)
			cout << p[i] << " ";
		cout << p[m-1] << endl;
		cout << 1 << endl;
		cout << p[m] << endl;
	}
	else {
		memcpy(pp, p, sizeof(p)); ll = l;

		s = 0;
		for (int i=1;i<=n;i++)
			if ((degree[i]&1)==1 || s == 0 && degree[i]!=0) s = i;
		l = 0, dfs(s);

		if (l+ll!=m) {
			cout << -1 << endl;
			return;
		}

		cout << l << endl;
		for (int i=1;i<=l-1;i++)
			cout << p[i] << " ";
		cout << p[l] << endl;
		cout << ll << endl;
		for (int i=1;i<=ll-1;i++)
			cout << pp[i] << " ";
		cout << pp[ll] << endl;
		return;
	}
}

int main(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	init(); solve();
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

const int N = 10001, M = 10001;
vector<int> adj[N];
int x[M], y[M]; bool used[M];
int degree[N];
int p[N], pp[N], l, ll;
int n, m;

void dfs(int u){

	//cout << u << endl;

	int v, j;
	for (int i=0;i<adj[u].size();i++){
		j = adj[u][i]; if (used[j]) continue;
		v = x[j]!=u ? x[j] : y[j];

		//cout << "-" << v << endl;
		if (degree[v]!=0){
			degree[u]--, degree[v]--, used[j] = true, dfs(v),
			p[++l] = j;
		}
	}
}

void init(){
	cin >> m;
	for (int i=1;i<=m;i++){
		cin >> x[i] >> y[i]; n = max(n, x[i]), n = max(n, y[i]);
		adj[x[i]].push_back(i), adj[y[i]].push_back(i);
		degree[x[i]]++, degree[y[i]]++;
	}
}

void solve(){
	int ss = 0, s = 1;
	for (int i=1;i<=n;i++)
		if ((degree[i]&1)==1) ss++, s = i;

	if (ss!=0 && ss!=2 && ss!=4 || m==1){
		cout << -1 << endl;
		return;
	}

	l = 0, dfs(s);
	if (l==m) {
		cout << m-1 << endl;
		for (int i=1;i<=m-2;i++)
			cout << p[i] << " ";
		cout << p[m-1] << " " << endl;
		cout << 1 << endl;
		cout << p[m] << " " << endl;
	}
	else {
		memcpy(pp, p, sizeof(p)); ll = l;

		s = 0;
		for (int i=1;i<=n;i++)
			if ((degree[i]&1)==1 || s == 0 && degree[i]!=0) s = i;
		l = 0, dfs(s);

		if (l+ll!=m) {
			cout << -1 << endl;
			return;
		}

		cout << l << endl;
		for (int i=1;i<=l-1;i++)
			cout << p[i] << " ";
		cout << p[l] <<  " " << endl;
		cout << ll << endl;
		for (int i=1;i<=ll-1;i++)
			cout << pp[i] << " ";
		cout << pp[ll] << " " << endl;
		return;
	}
}

int main(){
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	init(); solve();
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

const int N = 10001, M = 10001;
int x[M], y[M];
int d[N], p[N], pp[N], bg;
int n, m, l, ll;

vector<int> adj[N];

void print_path(){
	cout << l << endl;
	for (int i=1;i<l;i++)
		cout << p[i] << " ";
	cout << p[l] << endl;
}

void dfs(int u, int uu){
	d[u]--;

	int v, j;
	for (int i=0;i<adj[u].size();i++){
		j = adj[u][i], v = x[j]!=u ? x[j] : y[j];
		if (d[v]!=0 && v!=uu) {
			d[v]--, dfs(v, u);
			p[++l] = j;
		}
	}
}

void init(){
	cin >> m;
	for (int i=1;i<=m;i++){
		cin >> x[i] >> y[i]; n = max(n, x[i]), n = max(n, y[i]);
		adj[x[i]].push_back(i);
		adj[y[i]].push_back(i);
		d[x[i]]++, d[y[i]]++;
	}
}

void solve(){
	int stat = 0;
	for (int i=1;i<=n;i++){
		if ((d[i]&1)==1) {
			stat++;
			bg = i;
		}
	}

	if (stat==2 && m==1 || stat!=2 && stat!=4){
		cout << -1 << endl;
		return;
	}

	if (stat==2){
		dfs(bg, 0);

		if (l != m) return;

		cout << m - 1 << endl;
		for (int i=1;i<m-1;i++)
			cout << p[i] << " ";
		cout << p[m-1] << endl;

		cout << 1 << endl;
		cout << p[m] << endl;
	}

	if (stat==4){
		dfs(bg, 0);
		memcpy(pp, p, sizeof(p)); ll = l;

		l = 0, bg = 0;
		for (int i=1;i<=n;i++)
			if ((d[i]&1)==1 || bg==0) bg = i;
		dfs(bg, 0);

		if (l + ll != m){
			cout << -1 << endl;
			return;
		}

		print_path();
		memcpy(pp, p, sizeof(p)); l = ll;
		print_path();

	}
}

int main(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	init(); solve();
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

const int N = 10001, M = 10001;
vector<int> adj[N];
int x[M], y[M]; bool used[M];
int degree[N];
int p[N], pp[N], l, ll;
int n, m;

void dfs(int u){

	//cout << u << endl;

	int v, j;
	for (int i=0;i<adj[u].size();i++){
		j = adj[u][i]; if (used[j]) continue;
		v = x[j]!=u ? x[j] : y[j];

		//cout << "-" << v << endl;
		if (degree[v]!=0){
			degree[u]--, degree[v]--, used[j] = true, dfs(v),
			p[++l] = j;
		}
	}
}

void init(){
	cin >> m;
	for (int i=1;i<=m;i++){
		cin >> x[i] >> y[i]; n = max(n, x[i]), n = max(n, y[i]);
		adj[x[i]].push_back(i), adj[y[i]].push_back(i);
		degree[x[i]]++, degree[y[i]]++;
	}
}

void solve(){
	int ss = 0, s = 1;
	for (int i=1;i<=n;i++)
		if ((degree[i]&1)==1) ss++, s = i;

	l = 0, dfs(s);
	if (ss==0 || ss==2 && l==m && m!=1) {
		cout << m-1 << endl;
		for (int i=1;i<=m-2;i++)
			cout << p[i] << " ";
		cout << p[m-1] << endl;
		cout << 1 << endl;
		cout << p[m] << endl;
	}
	else if (ss==4) {
		memcpy(pp, p, sizeof(p)); ll = l;

		s = 0;
		for (int i=1;i<=n;i++)
			if ((degree[i]&1)==1 || s == 0 && degree[i]!=0) s = i;
		l = 0, dfs(s);

		if (l+ll!=m) {
			cout << -1 << endl;
			return;
		}

		cout << l << endl;
		for (int i=1;i<=l-1;i++)
			cout << p[i] << " ";
		cout << p[l] << endl;
		cout << ll << endl;
		for (int i=1;i<=ll-1;i++)
			cout << pp[i] << " ";
		cout << pp[ll] << endl;
	}
	else
		cout << -1 << endl;
}

int main(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	init(); solve();
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

const int N = 10001, M = 10001;
vector<int> adj[N];
int x[M], y[M]; bool used[M];
int d[N], dd[N];
int p1[N], p2[N], l1, l2;
int n, m;

void insert(int a, int b, int c){
	adj[a].push_back(c), adj[b].push_back(c), n = max(n, max(a, b));
	d[a]++, d[b]++;
}

void print_path(){
	cout << l1 << endl;
	for (int i=1;i<l1;i++)
		cout << p1[i] << " ";
	cout << p1[l1] << endl;

	cout << l2 << endl;
	for (int i=1;i<l2;i++)
		cout << p2[i] << " ";
	cout << p2[l2] << endl;
}

void dfs(int u){
	//cout << u << endl;
	int v, j;
	for (int i=adj[u].size()-1;i>=0;i--){
		j = adj[u][i]; if (used[j]) continue;
		v = x[j]!=u ? x[j] : y[j];
		if (d[v]!=0){
			d[u]--, d[v]--, used[j] = true, dfs(v),
			p1[++l1] = j;
		}
	}
}

void init(){
	cin >> m;
	for (int i=1;i<=m;i++){
		cin >> x[i] >> y[i];
		insert(x[i], y[i], i);
	}
}

void solve(){

	if (m < 2){
		cout << -1 << endl;
		return;
	}

	vector<int> s; int i;
	for (i=1;i<=n;i++)
		if ((d[i]&1)==1) s.push_back(i);

	if (s.size()==0){
		for (i=1;i<=n;i++)
			if (d[i]!=0) break;
		dfs(i);

		if (l1!=m){
			l2 = l1, memcpy(p2, p1, sizeof(p1));
			for (i=1;i<=n;i++)
				if (d[i]!=0) break;

			l1 = 0, dfs(i);
			if (l1+l2!=m){
				cout << -1 << endl;
				return;
			}
		}
		else
			p2[l2 = 1] = p1[l1--];

		print_path();
	}
	else if (s.size()==2){
		dfs(s[0]);
		if (l1!=m){
			l2 = l1, memcpy(p2, p1, sizeof(p1));
			for (i=1;i<=n;i++)
				if (d[i]!=0) break;
			dfs(i);

			if (l1+l2!=m){
				cout << -1 << endl;
				return;
			}
		}
		else
			p2[l2 = 1] = p1[l1--];
		print_path();
	}
	else if (s.size()==4){
		memcpy(dd, d, sizeof(d));
		dfs(s[0]);
		if (l1!=m){
			l2 = l1, memcpy(p2, p1, sizeof(p1));

			i = d[s[1]]!=0 ? s[1] : s[2];
			dfs(i);

			if (l1+l2!=m){
				cout << -1 << endl;
				return;
			}
		}
		else {
			memset(used, false, sizeof(used));
			memcpy(d, dd, sizeof(d));
			x[0] = s[0], y[0] = s[1], m++;
			insert(s[0], s[1], 0);
			l1 = 0, dfs(s[2]);

			//print_path();
			if (l1!=m){
				cout << -1 << endl;
				return;
			}

			while (l1>0 && p1[l1]!=0)
				p2[++l2] = p1[l1--];
			l1--;
		}
		print_path();
	}
	else
		cout << -1 << endl;

}

int main(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	init(); solve();
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

const int N = 10001, M = 10001;
int x[M], y[M];
int d[N], p[N], bg;
int n, m, l;

vector<int> adj[N];

void print_path(){
	cout << l << endl;
	for (int i=1;i<l;i++)
		cout << p[i] << " ";
	cout << p[l] << endl;
}

void dfs(int u){
	d[u]--;

	//cout << u << endl;

	int v, j;
	for (int i=0;i<adj[u].size();i++){
		j = adj[u][i], v = x[j]!=u ? x[j] : y[j];
		if (d[v]!=0) {
			p[++l] = j; d[v]--;
		//	cout << j << " ";
			dfs(v);
		}
	}
}

void init(){
	cin >> m;
	for (int i=1;i<=m;i++){
		cin >> x[i] >> y[i]; n = max(n, x[i]), n = max(n, y[i]);
		adj[x[i]].push_back(i);
		adj[y[i]].push_back(i);
		d[x[i]]++, d[y[i]]++;
	}
}

void solve(){
	int stat = 0;
	for (int i=1;i<=n;i++){
		if ((d[i]&1)==1) {
			stat++;
			bg = i;
		}
	}

	if (stat==2 && m==1 || stat!=2 && stat!=4){
		cout << -1 << endl;
		return;
	}

	if (stat==2){
		dfs(bg);

		cout << m - 1 << endl;
		for (int i=1;i<m-1;i++)
			cout << p[i] << " ";
		cout << p[m-1] << endl;

		cout << 1 << endl;
		cout << p[m] << endl;
	}

	if (stat==4){
		dfs(bg); 		print_path();

		l = 0;
		for (int i=1;i<=n;i++)
			if ((d[i]&1)==1) bg = i;
		dfs(bg);
		print_path();
	}
}

int main(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	init(); solve();
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

const int N = 10001, M = 10001;
vector<int> adj[N];
int x[M], y[M]; bool used[M];
int degree[N];
int p[N], pp[N], l, ll;
int n, m;

void dfs(int u){

	//cout << u << endl;

	int v, j;
	for (int i=0;i<adj[u].size();i++){
		j = adj[u][i]; if (used[j]) continue;
		v = x[j]!=u ? x[j] : y[j];

		//cout << "-" << v << endl;
		if (degree[v]!=0){
			degree[u]--, degree[v]--, used[j] = true, dfs(v),
			p[++l] = j;
		}
	}
}

void init(){
	cin >> m;
	for (int i=1;i<=m;i++){
		cin >> x[i] >> y[i]; n = max(n, x[i]), n = max(n, y[i]);
		adj[x[i]].push_back(i), adj[y[i]].push_back(i);
		degree[x[i]]++, degree[y[i]]++;
	}
}

void solve(){
	int ss = 0, s = 1;
	for (int i=1;i<=n;i++)
		if ((degree[i]&1)==1) ss++, s = i;

	l = 0, dfs(s);
	if ((ss==0 || ss==2) && l==m && m!=1) {
		cout << m-1 << endl;
		for (int i=1;i<=m-2;i++)
			cout << p[i] << " ";
		cout << p[m-1] << endl;
		cout << 1 << endl;
		cout << p[m] << endl;
	}
	else if (ss==4) {
		memcpy(pp, p, sizeof(p)); ll = l;

		s = 0;
		for (int i=1;i<=n;i++)
			if ((degree[i]&1)==1 || s == 0 && degree[i]!=0) s = i;
		l = 0, dfs(s);

		if (l+ll!=m) {
			cout << -1 << endl;
			return;
		}

		cout << l << endl;
		for (int i=1;i<=l-1;i++)
			cout << p[i] << " ";
		cout << p[l] << endl;
		cout << ll << endl;
		for (int i=1;i<=ll-1;i++)
			cout << pp[i] << " ";
		cout << pp[ll] << endl;
	}
	else

		cout << -1 << endl;
}

int main(){
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	init(); solve();
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

const int N = 10001, M = 10001;
int x[M], y[M];
int d[N], p[N], bg;
int n, m, l;

vector<int> adj[N];

void print_path(){
	cout << l << endl;
	for (int i=1;i<l;i++)
		cout << p[i] << " ";
	cout << p[l] << endl;
}

void dfs(int u, int uu){
	d[u]--;

	//cout << u << endl;

	int v, j;
	for (int i=0;i<adj[u].size();i++){
		j = adj[u][i], v = x[j]!=u ? x[j] : y[j];
		if (d[v]!=0 && v!=uu) {
			p[++l] = j; d[v]--;
		//	cout << j << " ";
			dfs(v, u);
		}
	}
}

void init(){
	cin >> m;
	for (int i=1;i<=m;i++){
		cin >> x[i] >> y[i]; n = max(n, x[i]), n = max(n, y[i]);
		adj[x[i]].push_back(i);
		adj[y[i]].push_back(i);
		d[x[i]]++, d[y[i]]++;
	}
}

void solve(){
	int stat = 0;
	for (int i=1;i<=n;i++){
		if ((d[i]&1)==1) {
			stat++;
			bg = i;
		}
	}

	if (stat==2 && m==1 || stat!=2 && stat!=4){
		cout << -1 << endl;
		return;
	}

	if (stat==2){
		dfs(bg, 0);

		cout << m - 1 << endl;
		for (int i=1;i<m-1;i++)
			cout << p[i] << " ";
		cout << p[m-1] << endl;

		cout << 1 << endl;
		cout << p[m] << endl;
	}

	if (stat==4){
		dfs(bg, 0);
 		print_path();

		l = 0;
		for (int i=1;i<=n;i++)
			if ((d[i]&1)==1) bg = i;
		dfs(bg, 0);
		print_path();
	}
}

int main(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	init(); solve();
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

const int N = 10001, M = 10001;
int x[M], y[M];
int d[N], p[N], pp[N], bg;
int n, m, l, ll;

vector<int> adj[N];

void print_path(){
	cout << l << endl;
	for (int i=1;i<l;i++)
		cout << p[i] << " ";
	cout << p[l] << endl;
}

void dfs(int u, int uu){
	int v, j;
	for (int i=0;i<adj[u].size();i++){
		j = adj[u][i], v = x[j]!=u ? x[j] : y[j];
		if (d[v]!=0 && v!=uu) {
			d[u]--, d[v]--, dfs(v, u);
			p[++l] = j;
		}
	}
}

void init(){
	cin >> m;
	for (int i=1;i<=m;i++){
		cin >> x[i] >> y[i]; n = max(n, x[i]), n = max(n, y[i]);
		adj[x[i]].push_back(i);
		adj[y[i]].push_back(i);
		d[x[i]]++, d[y[i]]++;
	}
}

void solve(){
	int stat = 0;
	for (int i=1;i<=n;i++){
		if ((d[i]&1)==1) {
			stat++;
			bg = i;
		}
	}

	if (stat==2 && m==1 || stat!=2 && stat!=4){
		cout << -1 << endl;
		return;
	}

	if (stat==2){
		dfs(bg, 0);

		if (l != m) return;

		cout << m - 1 << endl;
		for (int i=1;i<m-1;i++)
			cout << p[i] << " ";
		cout << p[m-1] << endl;

		cout << 1 << endl;
		cout << p[m] << endl;
	}

	if (stat==4){
		dfs(bg, 0);
		memcpy(pp, p, sizeof(p)); ll = l;

		l = 0, bg = 0;
		for (int i=1;i<=n;i++){
			if ((d[i]&1)==1 || bg==0) bg = i;

		}
		dfs(bg, 0);
		if (l + ll != m){
			cout << -1 << endl;
			return;
		}

		print_path();
		memcpy(p, pp, sizeof(p)); l = ll;
		print_path();

	}
}

int main(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	init(); solve();
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

const int N = 10001, M = 10001;
vector<int> adj[N];
int x[M], y[M]; bool used[M];
int degree[N];
int p[N], pp[N], l, ll;
int n, m;

void dfs(int u){

	//cout << u << endl;

	int v, j;
	for (int i=0;i<adj[u].size();i++){
		j = adj[u][i]; if (used[j]) continue;
		v = x[j]!=u ? x[j] : y[j];

		//cout << "-" << v << endl;
		if (degree[v]!=0){
			degree[u]--, degree[v]--, used[j] = true, dfs(v),
			p[++l] = j;
		}
	}
}

void init(){
	cin >> m;
	for (int i=1;i<=m;i++){
		cin >> x[i] >> y[i]; n = max(n, x[i]), n = max(n, y[i]);
		adj[x[i]].push_back(i), adj[y[i]].push_back(i);
		degree[x[i]]++, degree[y[i]]++;
	}
}

void solve(){
	int ss = 0, s = 1;
	for (int i=1;i<=n;i++)
		if ((degree[i]&1)==1) ss++, s = i;

	l = 0, dfs(s);
	if ((ss==0 || ss==2) && l==m && m!=1) {
		cout << m-1 << endl;
		for (int i=1;i<=m-2;i++)
			cout << p[i] << " ";
		cout << p[m-1] << endl;
		cout << 1 << endl;
		cout << p[m] << endl;
	}
	else if (ss==4) {
		memcpy(pp, p, sizeof(p)); ll = l;

		s = 0;
		for (int i=1;i<=n;i++)
			if ((degree[i]&1)==1 || s == 0 && degree[i]!=0) s = i;
		l = 0, dfs(s);

		if (l+ll!=m) {
			cout << -1 << endl;
			return;
		}

		cout << l << endl;
		for (int i=1;i<=l-1;i++)
			cout << p[i] << " ";
		cout << p[l] << endl;
		cout << ll << endl;
		for (int i=1;i<=ll-1;i++)
			cout << pp[i] << " ";
		cout << pp[ll] << endl;
	}
	else
		cout << -1 << endl;
}

int main(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	init(); solve();
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

const int N = 10001, M = 10001;
vector<int> adj[N];
int x[M], y[M]; bool used[M];
int d[N], dd[N];
int p1[N], p2[N], l1, l2;
int n, m;

void insert(int a, int b, int c){
	adj[a].push_back(c), adj[b].push_back(c), n = max(n, max(a, b));
	d[a]++, d[b]++;
}

void print_path(){
	cout << l1 << endl;
	for (int i=1;i<l1;i++)
		cout << p1[i] << " ";
	cout << p1[l1] << endl;

	cout << l2 << endl;
	for (int i=1;i<l2;i++)
		cout << p2[i] << " ";
	cout << p2[l2] << endl;
}

void dfs(int u){
	//cout << u << endl;
	int v, j;
	for (int i=adj[u].size()-1;i>=0;i--){
		j = adj[u][i]; if (used[j]) continue;
		v = x[j]!=u ? x[j] : y[j];
		if (d[v]!=0){
			d[u]--, d[v]--, used[j] = true, dfs(v),
			p1[++l1] = j;
		}
	}
}

void init(){
	cin >> m;
	for (int i=1;i<=m;i++){
		cin >> x[i] >> y[i];
		insert(x[i], y[i], i);
	}
}

void solve(){

	if (m < 2){
		cout << -1 << endl;
		return;
	}

	vector<int> s; int i;
	for (i=1;i<=n;i++)
		if ((d[i]&1)==1) s.push_back(i);

	if (s.size()==0){
		for (i=1;i<=n;i++)
			if (d[i]!=0) break;
		dfs(i);

		if (l1!=m){
			l2 = l1, memcpy(p2, p1, sizeof(p1)), l1 = 0;
			for (i=1;i<=n;i++)
				if (d[i]!=0) break;

			dfs(i);
			if (l1+l2!=m){
				cout << -1 << endl;
				return;
			}
		}
		else
			p2[l2 = 1] = p1[l1--];

		print_path();
	}
	else if (s.size()==2){
		dfs(s[0]);
		if (l1!=m){
			l2 = l1, memcpy(p2, p1, sizeof(p1)), l1 = 0;
			for (i=1;i<=n;i++)
				if (d[i]!=0) break;
			dfs(i);

			if (l1+l2!=m){
				cout << -1 << endl;
				return;
			}
		}
		else
			p2[l2 = 1] = p1[l1--];
		print_path();
	}
	else if (s.size()==4){
		memcpy(dd, d, sizeof(d));
		dfs(s[0]);
		if (l1!=m){
			l2 = l1, memcpy(p2, p1, sizeof(p1)), l1 = 0;

			i = d[s[1]]!=0 ? s[1] : s[2];
			dfs(i);

			if (l1+l2!=m){
				cout << -1 << endl;
				return;
			}
		}

		else {

			memset(used, false, sizeof(used));
			memcpy(d, dd, sizeof(d));
			x[0] = s[0], y[0] = s[1], m++;
			insert(s[0], s[1], 0);
			l1 = 0, dfs(s[2]);

			if (l1!=m){
				cout << -1 << endl;
				return;
			}

			while (l1>0 && p1[l1]!=0)
				p2[++l2] = p1[l1--];
			l1--;
		}
		print_path();
	}
	else
		cout << -1 << endl;

}

int main(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	init(); solve();
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

const int N = 10001, M = 10001;
int x[M], y[M];
int d[N], p[N], pp[N], bg;
int n, m, l, ll;

vector<int> adj[N];

void print_path(){
	cout << l << endl;
	for (int i=1;i<l;i++)
		cout << p[i] << " ";
	cout << p[l] << endl;
}

void dfs(int u, int uu){
	d[u]--;

	//cout << u << endl;

	int v, j;
	for (int i=0;i<adj[u].size();i++){
		j = adj[u][i], v = x[j]!=u ? x[j] : y[j];
		if (d[v]!=0 && v!=uu) {
			p[++l] = j; d[v]--;
		//	cout << j << " ";
			dfs(v, u);
		}
	}
}

void init(){
	cin >> m;
	for (int i=1;i<=m;i++){
		cin >> x[i] >> y[i]; n = max(n, x[i]), n = max(n, y[i]);
		adj[x[i]].push_back(i);
		adj[y[i]].push_back(i);
		d[x[i]]++, d[y[i]]++;
	}
}

void solve(){
	int stat = 0;
	for (int i=1;i<=n;i++){
		if ((d[i]&1)==1) {
			stat++;
			bg = i;
		}
	}

	if (stat==2 && m==1 || stat!=2 && stat!=4){
		cout << -1 << endl;
		return;
	}

	if (stat==2){
		dfs(bg, 0);

		cout << m - 1 << endl;
		for (int i=1;i<m-1;i++)
			cout << p[i] << " ";
		cout << p[m-1] << endl;

		cout << 1 << endl;
		cout << p[m] << endl;
	}

	if (stat==4){
		dfs(bg, 0);
		memcpy(pp, p, sizeof(p)); ll = l;

		l = 0;
		for (int i=1;i<=n;i++)
			if ((d[i]&1)==1) bg = i;
		dfs(bg, 0);

		if (l + ll != m){
			cout << -1 << endl;
			return;
		}

		print_path();
		memcpy(pp, p, sizeof(p)); l = ll;
		print_path();

	}
}

int main(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	init(); solve();
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

const int N = 10001, M = 10001;
vector<int> adj[N];
int x[M], y[M]; bool used[M];
int d[N], dd[N];
int p1[N], p2[N], l1, l2;
int n, m;

void insert(int a, int b, int c){
	adj[a].push_back(c), adj[b].push_back(c), n = max(n, max(a, b));
	d[a]++, d[b]++;
}

void print_path(){
	cout << l1 << endl;
	for (int i=1;i<l1;i++)
		cout << p1[i] << " ";
	cout << p1[l1] << endl;

	cout << l2 << endl;
	for (int i=1;i<l2;i++)
		cout << p2[i] << " ";
	cout << p2[l2] << endl;
}

void dfs(int u){
	//cout << u << endl;
	int v, j;
	for (int i=adj[u].size()-1;i>=0;i--){
		j = adj[u][i]; if (used[j]) continue;
		v = x[j]!=u ? x[j] : y[j];
		if (d[v]!=0){
			d[u]--, d[v]--, used[j] = true, dfs(v),
			p1[++l1] = j;
		}
	}
}

void init(){
	cin >> m;
	for (int i=1;i<=m;i++){
		cin >> x[i] >> y[i];
		insert(x[i], y[i], i);
	}
}

void solve(){

	if (m < 2){
		cout << -1 << endl;
		return;
	}

	vector<int> s; int i;
	for (i=1;i<=n;i++)
		if ((d[i]&1)==1) s.push_back(i);

	if (s.size()==0){
		for (i=1;i<=n;i++)
			if (d[i]!=0) break;
		dfs(i);

		if (l1!=m){
			l2 = l1, memcpy(p2, p1, sizeof(p1));
			for (i=1;i<=n;i++)
				if (d[i]!=0) break;
			dfs(i);

			if (l1+l2!=m){
				cout << -1 << endl;
				return;
			}
		}
		else
			p2[l2 = 1] = p1[l1--];

		print_path();
	}
	else if (s.size()==2){
		dfs(s[0]);
		if (l1!=m){
			l2 = l1, memcpy(p2, p1, sizeof(p1));
			for (i=1;i<=n;i++)
				if (d[i]!=0) break;
			dfs(i);

			if (l1+l2!=m){
				cout << -1 << endl;
				return;
			}
		}
		else
			p2[l2 = 1] = p1[l1--];
		print_path();
	}
	else if (s.size()==4){
		memcpy(dd, d, sizeof(d));
		dfs(s[0]);
		if (l1!=m){
			l2 = l1, memcpy(p2, p1, sizeof(p1));
			i = d[s[1]]!=0 ? s[1] : s[2];
			dfs(i);

			if (l1+l2!=m){
				cout << -1 << endl;
				return;
			}
		}
		else {
			memset(used, false, sizeof(used));
			memcpy(d, dd, sizeof(d));
			x[0] = s[0], y[0] = s[1], m++;
			insert(s[0], s[1], 0);
			l1 = 0, dfs(s[2]);

			//print_path();
			if (l1!=m){
				cout << -1 << endl;
				return;
			}

			while (l1>0 && p1[l1]!=0)
				p2[++l2] = p1[l1--];
			l1--;
		}
		print_path();
	}
	else
		cout << -1 << endl;

}

int main(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	init(); solve();
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

const int N = 10001, M = 10001;
vector<int> adj[N];
int x[M], y[M]; bool used[M];
int degree[N];
int p1[N], p2[N], l1, l2;
int n, m;

void insert(int a, int b, int c){
	adj[a].push_back(c), adj[b].push_back(c), n = max(n, max(a, b));
	degree[a]++, degree[b]++;
}

void print_path(){
	cout << l1 << endl;
	for (int i=1;i<l1;i++)
		cout << p1[i] << " ";
	cout << p1[l1] << endl;

	cout << l2 << endl;
	for (int i=1;i<l2;i++)
		cout << p2[i] << " ";
	cout << p2[l2] << endl;
}

void dfs(int u){
	//cout << u << endl;
	int v, j;
	for (int i=adj[u].size()-1;i>=0;i--){
		j = adj[u][i]; if (used[j]) continue;
		v = x[j]!=u ? x[j] : y[j];
		if (degree[v]!=0){
			degree[u]--, degree[v]--, used[j] = true, dfs(v),
			p1[++l1] = j;
		}
	}
}

void init(){
	cin >> m;
	for (int i=1;i<=m;i++){
		cin >> x[i] >> y[i];
		insert(x[i], y[i], i);
	}
}

void solve(){

	if (m < 2){
		cout << -1 << endl;
		return;
	}

	vector<int> s; int i;
	for (i=1;i<=n;i++)
		if ((degree[i]&1)==1) s.push_back(i);

	if (s.size()==0){
		for (i=1;i<=n;i++)
			if (degree[i]!=0) break;
		dfs(i);

		if (l1!=m){
			l2 = l1, memcpy(p2, p1, sizeof(p1));
			for (i=1;i<=n;i++)
				if (degree[i]!=0) break;
			dfs(i);

			if (l1+l2!=m){
				cout << -1 << endl;
				return;
			}
		}
		else
			p2[l2 = 1] = p1[l1--];

		print_path();
	}
	else if (s.size()==2){
		dfs(s[0]);
		if (l1!=m){
			l2 = l1, memcpy(p2, p1, sizeof(p1));
			for (i=1;i<=n;i++)
				if (degree[i]!=0) break;
			dfs(i);

			if (l1+l2!=m){
				cout << -1 << endl;
				return;
			}
		}
		else
			p2[l2 = 1] = p1[l1--];
		print_path();
	}
	else if (s.size()==4){
		x[0] = s[0], y[0] = s[1], m++;
		insert(s[0], s[1], 0);
		dfs(s[2]);

		//print_path();

		if (l1!=m){
			cout << -1 << endl;
			return;
		}

		while (l1>0 && p1[l1]!=0)
			p2[++l2] = p1[l1--];
		l1--;

		print_path();
	}
	else
		cout << -1 << endl;

}

int main(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	init(); solve();
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

const int N = 10001, M = 10001;
vector<int> adj[N];
int x[M], y[M]; bool used[M];
int degree[N];
int p[N], pp[N], l, ll;
int n, m;

void dfs(int u){

	//cout << u << endl;

	int v, j;
	for (int i=0;i<adj[u].size();i++){
		j = adj[u][i]; if (used[j]) continue;
		v = x[j]!=u ? x[j] : y[j];

		//cout << "-" << v << endl;
		if (degree[v]!=0){
			degree[u]--, degree[v]--, used[j] = true, dfs(v),
			p[++l] = j;
		}
	}
}

void init(){
	cin >> m;
	for (int i=1;i<=m;i++){
		cin >> x[i] >> y[i]; n = max(n, x[i]), n = max(n, y[i]);
		adj[x[i]].push_back(i), adj[y[i]].push_back(i);
		degree[x[i]]++, degree[y[i]]++;
	}
}

void solve(){
	int ss = 0, s = 1;
	for (int i=1;i<=n;i++)
		if ((degree[i]&1)==1) ss++, s = i;

	if (ss!=0 && ss!=2 && ss!=4 || m==1){
		cout << -1 << endl;
		return;
	}

	l = 0, dfs(s);
	if (l==m) {
		cout << m-1 << endl;
		for (int i=1;i<=m-2;i++)
			cout << p[i] << " ";
		cout << p[m-1] << " " << endl;
		cout << 1 << endl;
		cout << p[m] << " " << endl;
	}
	else {
		memcpy(pp, p, sizeof(p)); ll = l;

		s = 0;
		for (int i=1;i<=n;i++)
			if ((degree[i]&1)==1 || s == 0 && degree[i]!=0) s = i;
		l = 0, dfs(s);

		if (l+ll!=m) {
			cout << -1 << endl;
			return;
		}

		cout << l << endl;
		for (int i=1;i<=l-1;i++)
			cout << p[i] << " ";
		cout << p[l] <<  " " << endl;
		cout << ll << endl;
		for (int i=1;i<=ll-1;i++)
			cout << pp[i] << " ";
		cout << pp[ll] << " " << endl;
		return;
	}
}

int main(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	init(); solve();
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

const int N = 10001, M = 10001;
vector<int> adj[N];
int x[M], y[M];
int degree[N];
int p[N], pp[N], l, ll;
int n, m;

void dfs(int u){

	//cout << u << endl;

	int v, j;
	for (int i=0;i<adj[u].size();i++){
		j = adj[u][i], v = x[j]!=u ? x[j] : y[j];

		//cout << "-" << v << endl;
		if (degree[v]!=0){
			degree[u]--, degree[v]--, dfs(v),
			p[++l] = j;
		}
	}
}

void init(){
	cin >> m;
	for (int i=1;i<=m;i++){
		cin >> x[i] >> y[i]; n = max(n, x[i]), n = max(n, y[i]);
		adj[x[i]].push_back(i), adj[y[i]].push_back(i);
		degree[x[i]]++, degree[y[i]]++;
	}
}

void solve(){
	int ss = 0, s = 1;
	for (int i=1;i<=n;i++)
		if ((degree[i]&1)==1) ss++, s = i;

	if (ss==0 || ss==2){
		l = 0, dfs(s);
		if (l!=m) {
			cout << -1 << endl;
			return;
		}
		cout << m-1 << endl;
		for (int i=1;i<=m-2;i++)
			cout << p[i] << " ";
		cout << p[m-1] << endl;
		cout << 1 << endl;
		cout << p[m] << endl;
		return;
	}
	else if (ss == 4){
		l = 0, dfs(s); memcpy(pp, p, sizeof(p)); ll = l;

		s = 0;
		for (int i=1;i<=n;i++)
			if ((degree[i]&1)==1 || s == 0 && degree[i]!=0) s = i;
		l = 0, dfs(s);

		if (l+ll!=m) {
			cout << -1 << endl;
			return;
		}

		cout << l << endl;
		for (int i=1;i<=l-1;i++)
			cout << p[i] << " ";
		cout << p[l] << endl;
		cout << l << endl;
		for (int i=1;i<=ll-1;i++)
			cout << pp[i] << " ";
		cout << pp[ll] << endl;
		return;
	}

	cout << -1 << endl;
}

int main(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	init(); solve();
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

const int N = 10001, M = 10001;
vector<int> adj[N];
int x[M], y[M]; bool used[M];
int d[N], dd[N];
int p1[N], p2[N], l1, l2;
int n, m;

void insert(int a, int b, int c){
	adj[a].push_back(c), adj[b].push_back(c), n = max(n, max(a, b));
	d[a]++, d[b]++;
}

void print_path(){
	cout << l1 << endl;
	for (int i=1;i<l1;i++)
		cout << p1[i] << " ";
	cout << p1[l1] << endl;

	cout << l2 << endl;
	for (int i=1;i<l2;i++)
		cout << p2[i] << " ";
	cout << p2[l2] << endl;
}

void dfs(int u){
	//cout << u << endl;
	int v, j;
	for (int i=adj[u].size()-1;i>=0;i--){
		j = adj[u][i]; if (used[j]) continue;
		v = x[j]!=u ? x[j] : y[j];
		if (d[v]!=0){
			d[u]--, d[v]--, used[j] = true, dfs(v),
			p1[++l1] = j;
		}
	}
}

void init(){
	cin >> m;
	for (int i=1;i<=m;i++){
		cin >> x[i] >> y[i];
		insert(x[i], y[i], i);
	}
}

void solve(){

	if (m < 2){
		cout << -1 << endl;
		return;
	}

	vector<int> s; int i;
	for (i=1;i<=n;i++)
		if ((d[i]&1)==1) s.push_back(i);

	if (s.size()==0){
		for (i=1;i<=n;i++)
			if (d[i]!=0) break;
		dfs(i);

		if (l1!=m){
			l2 = l1, memcpy(p2, p1, sizeof(p1));
			for (i=1;i<=n;i++)
				if (d[i]!=0) break;
			dfs(i);

			if (l1+l2!=m){
				cout << -1 << endl;
				return;
			}
		}
		else
			p2[l2 = 1] = p1[l1--];

		print_path();
	}
	else if (s.size()==2){
		dfs(s[0]);
		if (l1!=m){
			l2 = l1, memcpy(p2, p1, sizeof(p1));
			for (i=1;i<=n;i++)
				if (d[i]!=0) break;
			dfs(i);

			if (l1+l2!=m){
				cout << -1 << endl;
				return;
			}
		}
		else
			p2[l2 = 1] = p1[l1--];
		print_path();
	}
	else if (s.size()==4){
		memcpy(dd, d, sizeof(d));
		dfs(s[0]);
		if (l1!=m){
			l2 = l1, memcpy(p2, p1, sizeof(p1));
			i = d[s[1]]!=0 ? s[1] : s[2];
			dfs(i);

			if (l1+l2!=m){
				cout << -1 << endl;
				return;
			}
		}
		else {
			memset(used, false, sizeof(used));
			memcpy(d, dd, sizeof(d));
			x[0] = s[0], y[0] = s[1], m++;
			insert(s[0], s[1], 0);
			l1 = 0, dfs(s[2]);

			//print_path();
			if (l1!=m){
				cout << -1 << endl;
				return;
			}

			while (l1>0 && p1[l1]!=0)
				p2[++l2] = p1[l1--];
			l1--;
		}
		print_path();
	}
	else
		cout << -1 << endl;

}

int main(){
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	init(); solve();
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#define deg(x) cout<< #x"=" << x << endl
#define degg(x,y) cout<< #x"="<< x <<","<< #y"="<< y <<endl;
#define deggg(x,y,z) cout<<#x"="<<x<<","<<#y"="<<y<<","<<#z"="<<z<<endl;
#define sca(x) scanf("%d",&x)
#define scaa(x,y) scanf("%d%d",&x,&y)
#define scaaa(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define ptf(x) printf("%d\n",x)
#define ptff(x,y) printf("%d %d\n",x,y)
#define ptfff(x,y,z) printf("%d %d %d\n",x,y,z)
#define inc(i,a,b) for(int i=a;i<=b;++i)
#define dec(i,a,b) for(int i=a;i>=b;--i)
#define mes(a,x) memset(a,x,sizeof(a))
#define PI acos(-1)
#define lowbit(x) x&-x
#define ALL(X) (X).begin(), (X).end()
#define PB push_back
#define MP make_pair
#define X first
#define Y second
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef priority_queue<int,vector<int>,greater<int> > xqueue;
typedef priority_queue<int> dqueue;

const int mod=1e9+7;
const ll INF=0x3f3f3f3f3f3f3f3fLL;
const int inf=0x3f3f3f3f;
const int N=1e5+5;

int n;
int b[10];

void work()
{
    sca(n);
    while(n--)
    {
        int q;
        sca(q);
        mes(b,0);
        inc(i,1,q)
        {
            int x;
            sca(x);
            b[x%3]++;
        }//deggg(b[1],b[2],b[3]);
        int ans=min(b[1],b[2])+b[0];
        if(b[1]>b[2])
        {
            b[1]-=b[2];
            ans+=(b[1]/3);
        }
        else
        {
            b[2]-=b[1];
            ans+=(b[2]/3);
        }
        ptf(ans);
    }
}

int main()
{
#ifdef mm
    //freopen("1.txt","r",stdin);
#endif // mm
    //ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    work();
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#define deg(x) cout<< #x"=" << x << endl
#define degg(x,y) cout<< #x"="<< x <<","<< #y"="<< y <<endl;
#define deggg(x,y,z) cout<<#x"="<<x<<","<<#y"="<<y<<","<<#z"="<<z<<endl;
#define sca(x) scanf("%d",&x)
#define scaa(x,y) scanf("%d%d",&x,&y)
#define scaaa(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define ptf(x) printf("%d\n",x)
#define ptff(x,y) printf("%d %d\n",x,y)
#define ptfff(x,y,z) printf("%d %d %d\n",x,y,z)
#define inc(i,a,b) for(int i=a;i<=b;++i)
#define dec(i,a,b) for(int i=a;i>=b;--i)
#define mes(a,x) memset(a,x,sizeof(a))
#define PI acos(-1)
#define lowbit(x) x&-x
#define ALL(X) (X).begin(), (X).end()
#define PB push_back
#define MP make_pair
#define X first
#define Y second
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef priority_queue<int,vector<int>,greater<int> > xqueue;
typedef priority_queue<int> dqueue;

const int mod=1e9+7;
const ll INF=0x3f3f3f3f3f3f3f3fLL;
const int inf=0x3f3f3f3f;
const int N=1e5+5;

int n;
int b[10];

void work()
{
    sca(n);
    while(n--)
    {
        int q;
        sca(q);
        mes(b,0);
        inc(i,1,q)
        {
            ll x;
            cin>>x;
            b[x%3]++;
        }//deggg(b[1],b[2],b[3]);
        int ans=min(b[1],b[2])+b[0];
        if(b[1]>b[2])
        {
            b[1]-=b[2];
            ans+=(b[1]/3);
        }
        ptf(ans);
    }
}

int main()
{
#ifdef mm
    //freopen("1.txt","r",stdin);
#endif // mm
    //ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    work();
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#define deg(x) cout<< #x"=" << x << endl
#define degg(x,y) cout<< #x"="<< x <<","<< #y"="<< y <<endl;
#define deggg(x,y,z) cout<<#x"="<<x<<","<<#y"="<<y<<","<<#z"="<<z<<endl;
#define sca(x) scanf("%d",&x)
#define scaa(x,y) scanf("%d%d",&x,&y)
#define scaaa(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define ptf(x) printf("%d\n",x)
#define ptff(x,y) printf("%d %d\n",x,y)
#define ptfff(x,y,z) printf("%d %d %d\n",x,y,z)
#define inc(i,a,b) for(int i=a;i<=b;++i)
#define dec(i,a,b) for(int i=a;i>=b;--i)
#define mes(a,x) memset(a,x,sizeof(a))
#define PI acos(-1)
#define lowbit(x) x&-x
#define ALL(X) (X).begin(), (X).end()
#define PB push_back
#define MP make_pair
#define X first
#define Y second
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef priority_queue<int,vector<int>,greater<int> > xqueue;
typedef priority_queue<int> dqueue;

const int mod=1e9+7;
const ll INF=0x3f3f3f3f3f3f3f3fLL;
const int inf=0x3f3f3f3f;
const int N=1e5+5;

int n;
int a[105],b[10];

void work()
{
    sca(n);
    while(n--)
    {
        int q;
        sca(q);
        mes(b,0);
        inc(i,1,q)
        {
            sca(a[i]);
            if(a[i]!=3)
                a[i]%=3;
            b[a[i]]++;
        }
        int ans=min(b[1],b[2])+b[3];
        if(b[1]>b[2])
        {
            b[1]-=b[2];
            ans+=b[1]/3;
        }
        else
        {
            b[2]-=b[1];
            ans+=b[2]/3;
        }
        ptf(ans);
    }
}

int main()
{
#ifdef mm
    //freopen("1.txt","r",stdin);
#endif // mm
    //ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    work();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
typedef  long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
#define F first
#define S second

int main()
{

	ll t;
	cin>>t;
	while(t--){
        ll n;
        cin>>n;
        ll a[n];
        map<int,int> m;
        vector<int> v;
        ll f=0;
        for(int x=0;x<n;x++){
            cin>>a[x];
            if(m[a[x]]==0){
            v.push_back(a[x]);
            }
            m[a[x]]++;
        }

        sort(a,a+n);
        for(int x=n-1;x>=0;x--){
            if(a[x]%3==0){
                f++;
            }
            else{
             if(a[x]>3){
                ll k=a[x]%3;
                if(k==1){
                    if(m[2]>0){
                        m[2]--;
                        m[a[x]]--;
                        f++;
                    }
                }
                 if(k==2){
                    if(m[1]>0){
                        m[1]--;
                        m[a[x]]--;
                        f++;
                    }
                }
            }
            if(a[x]==2){
                if(m[1]>0 && m[2]>0){
                    m[1]--;
                    m[a[x]]--;
                    f++;
                }
            }
        }
    }
        f+=m[1]/3;
        m[1]=m[1]%3;
    cout<<f<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
typedef  long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
#define F first
#define S second

int main()
{
    ll t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        ll a[n];
        for(int x=0;x<n;x++){
            cin>>a[x];
        }
        ll m[3]={0};
        for(int x=0;x<n;x++){
            ll k=a[x]%3;
            m[k]++;
        }
        ll sum=0;
        ll f=min(m[1],m[2]);
        sum=m[0]+f;
        m[1]-=f;
        m[2]-=f;
        if(m[1]>0){
            sum+=m[1]/3
        }
        if(m[2]>0){
            sum+=m[2]/3;

        }
        cout<<sum<<endl;

    }
}


#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
typedef  long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
#define F first
#define S second

int main()
{

	ll t;
	cin>>t;
	while(t--){
        ll n;
        cin>>n;
        ll a[n];
        map<int,int> m;
        ll f=0;
        for(int x=0;x<n;x++){
            cin>>a[x];
            m[a[x]]++;
        }
        f=m[1]/3;
        m[1]=m[1]%3;
        sort(a,a+n);
        for(int x=n-1;x>=0;x--){
            if(a[x]%3==0){
                f++;
            }
            else{
             if(a[x]>3){
                ll k=a[x]%3;
                if(m[k-1]!=0 && k!=0){
                    m[k-1]--;
                    m[a[x]]--;
                    f++;
                }
            }
            if(a[x]==2){
                if(m[1]!=0){
                    m[1]--;
                    m[2]--;
                    f++;
                }
            }
        }
    }
    cout<<f<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
typedef  long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
#define F first
#define S second

int main()
{

	ll t;
	cin>>t;
	while(t--){
        ll n;
        cin>>n;
        ll a[n];
        map<int,int> m;
        ll f=0;
        for(int x=0;x<n;x++){
            cin>>a[x];
            m[a[x]]++;
        }

        sort(a,a+n);
        for(int x=n-1;x>=0;x--){
            if(a[x]%3==0){
                f++;
            }
            else{
             if(a[x]>3){
                ll k=a[x]%3;
                if(k==1){
                    if(m[2]>0){
                        m[2]--;
                        m[a[x]]--;
                        f++;
                    }
                }
                 if(k==2){
                    if(m[1]>0){
                        m[1]--;
                        m[a[x]]--;
                        f++;
                    }
                }
            }
            if(a[x]==2){
                if(m[1]>0 && m[2]>0){
                    m[1]--;
                    m[a[x]]--;
                    f++;
                }
            }
        }
    }
        f+=m[1]/3;
        f+=m[2]/3;
        m[1]=m[1]%3;
    cout<<f<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
typedef  long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
#define F first
#define S second

int main()
{

	ll t;
	cin>>t;
	while(t--){
        ll n;
        cin>>n;
        ll a[n];
        map<int,int> m;
        ll f=0;
        for(int x=0;x<n;x++){
            cin>>a[x];
            m[a[x]]++;
        }

        sort(a,a+n);
        for(int x=n-1;x>=0;x--){
            if(a[x]%3==0){
                f++;
            }
            else{
             if(a[x]>3){
                ll k=a[x]%3;
                if(k==1){
                    if(m[2]>0){
                        m[2]--;
                        m[a[x]]--;
                        f++;
                    }
                }
                else if(k==2){
                    if(m[1]>0){
                        m[1]--;
                        m[a[x]]--;
                        f++;
                    }
                }
            }
            if(a[x]==2){
                if(m[1]>0){
                    m[1]--;
                    m[2]--;
                    f++;
                }
            }
        }
    }
        f+=m[1]/3;
        m[1]=m[1]%3;
    cout<<f<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
typedef  long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
#define F first
#define S second

int main()
{
    ll t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        ll a[n];
        for(int x=0;x<n;x++){
            cin>>a[x];
        }
        ll m[3]={0};
        for(int x=0;x<n;x++){
            ll k=a[x]%3;
            m[k]++;
        }
        ll sum=0;
        ll f=min(m[1],m[2]);
        sum=m[0]+f;
        m[1]-=f;
        m[2]-=f;
        if(m[1]>0){
            sum+=m[1]/3;
        }
        if(m[2]>0){
            sum+=m[2]/3;

        }
        cout<<sum<<endl;

    }
}


#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
typedef  long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
#define F first
#define S second

int main()
{

	ll t;
	cin>>t;
	while(t--){
        ll n;
        cin>>n;
        ll a[n];
        map<int,int> m;
        ll f=0;
        for(int x=0;x<n;x++){
            cin>>a[x];
            m[a[x]]++;
        }
        f=m[1]/3;
        m[1]=m[1]%3;
        sort(a,a+n);
        for(int x=n-1;x>=0;x--){
            if(a[x]%3==0){
                f++;
            }
            else{
             if(a[x]>3){
                ll k=a[x]%3;
                if(k==1){
                    if(m[2]!=0){
                        m[2]--;
                        m[a[x]]--;
                        f++;
                    }
                }
                else if(k==2){
                    if(m[1]!=0){
                        m[1]--;
                        m[a[x]]--;
                        f++;
                    }
                }
            }
            if(a[x]==2){
                if(m[1]!=0){
                    m[1]--;
                    m[2]--;
                    f++;
                }
            }
        }
    }
    cout<<f<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
typedef  long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
#define F first
#define S second

int main()
{

	ll t;
	cin>>t;
	while(t--){
        ll n;
        cin>>n;
        ll a[n];
        map<int,int> m;
        ll f=0;
        for(int x=0;x<n;x++){
            cin>>a[x];
            m[a[x]]++;
        }
        for(int x=0;x<n;x++){
            f+=m[a[x]]/3;
            m[a[x]]%=3;
        }

        sort(a,a+n);
        for(int x=n-1;x>=0;x--){
            if(a[x]%3==0){
                f++;
            }
            else{
             if(a[x]>3){
                ll k=a[x]%3;
                if(k==1){
                    if(m[2]>0){
                        m[2]--;
                        m[a[x]]--;
                        f++;
                    }
                }
                 if(k==2){
                    if(m[1]>0){
                        m[1]--;
                        m[a[x]]--;
                        f++;
                    }
                }
            }
            if(a[x]==2){
                if(m[1]>0 && m[2]>0){
                    m[1]--;
                    m[a[x]]--;
                    f++;
                }
            }
        }
    }
    cout<<f<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
typedef  long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
#define F first
#define S second

int main()
{

	ll t;
	cin>>t;
	while(t--){
        ll n;
        cin>>n;
        ll a[n];
        map<int,int> m;
        ll f=0;
        for(int x=0;x<n;x++){
            cin>>a[x];
            m[a[x]]++;
        }

        sort(a,a+n);
        for(int x=n-1;x>=0;x--){
            if(a[x]%3==0){
                f++;
            }
            else{
             if(a[x]>3){
                ll k=a[x]%3;
                if(k==1){
                    if(m[2]!=0){
                        m[2]--;
                        m[a[x]]--;
                        f++;
                    }
                }
                else if(k==2){
                    if(m[1]!=0){
                        m[1]--;
                        m[a[x]]--;
                        f++;
                    }
                }
            }
            if(a[x]==2){
                if(m[1]!=0){
                    m[1]--;
                    m[2]--;
                    f++;
                }
            }
        }
    }
        f+=m[1]/3;
        m[1]=m[1]%3;
    cout<<f<<endl;
	}
}


#include<iostream>
#include<algorithm>
using namespace std;
long long t, n,cnt;
long long one, two;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> t;
	while (t--)
	{
		cin >> n;
		for (int i = 0; i < n; i++)
		{
			int a;
			cin >> a;
			if (a == 3)
				cnt++;
			else if(a==1)
				one++;
			else if (a == 2)
				two++;
		}
		if (two > one)
		{
			cnt += one;
		}
		else if (two == one)
		{
			cnt += two;
		}
		else
		{
			cnt = cnt + two;
			one = one-two;
			cnt = cnt + one / 3;
		}
		cout << cnt << '\n';
		cnt = 0; one = 0; two = 0;
	}
}


#include<iostream>
#include<algorithm>
using namespace std;
long long t, n, cnt;
long long one, two, zz, hh;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> t;
	while (t--)
	{
		cin >> n;
		for (int i = 0; i < n; i++)
		{
			int a;
			cin >> a;
			if (a % 3 == 0)
				cnt++;
			else if (a < 3)
			{
				if (a %3== 1)
					one++;
				else if (a %3== 2)
					two++;
			}
		}
		if (two > one)
		{
			cnt += one;
			two -= one;
			cnt += two / 3;
		}
		else if (two == one)
		{
			cnt += two;
		}
		else
		{
			cnt = cnt + two;
			one = one - two;
			cnt = cnt + one / 3;
		}
		cout << cnt << '\n';
		cnt = 0; one = 0; two = 0; zz = 0; hh = 0;
	}
}


#include<iostream>
#include<algorithm>
using namespace std;
long long t, n, cnt,k;
long long one, two;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> t;
	while (t--)
	{
		cin >> n;
		int ar[101];
		for (int i = 0; i < n; i++)
		{
			int a;
			cin >> a;
			if (a % 3==0)
				cnt++;
			else if (a < 3)
			{
				 if (a == 1)
					one++;
				else if (a == 2)
					two++;
			}
			else if (a > 3)
			{
				ar[k++] = a;
			}
		}
		if (two > one)
		{
			cnt += one;
		}
		else if (two == one)
		{
			cnt += two;
		}
		else
		{
			cnt = cnt + two;
			one = one - two;
			cnt = cnt + one / 3;
		}
		for (int i = 0; i < k; i++)
		{
			if (ar[i] == 0) continue;
			for (int j = 0; j < k; j++)
			{
				if (ar[j] == 0) continue;
				if(i!=j )
					if (ar[i] + ar[j] % 3 == 0)
					{
						cnt++;
						ar[i] = 0; ar[j] = 0;
					}
			}
		}
		cout << cnt << '\n';
		cnt = 0; one = 0; two = 0; k=0;
	}
}


#include<iostream>
#include<algorithm>
using namespace std;
long long t, n, cnt,k;
long long one, two;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> t;
	while (t--)
	{
		cin >> n;
		int ar[101];
		for (int i = 0; i < n; i++)
		{
			int a;
			cin >> a;
			if (a % 3==0)
				cnt++;
			else if (a < 3)
			{
				 if (a == 1)
					one++;
				else if (a == 2)
					two++;
			}
			else if (a > 3)
			{
				ar[k++] = a;
			}
		}
		if (two > one)
		{
			cnt += one;
		}
		else if (two == one)
		{
			cnt += two;
		}
		else
		{
			cnt = cnt + two;
			one = one - two;
			cnt = cnt + one / 3;
		}
		for (int i = 0; i < k; i++)
		{
			if (ar[i] == 0) continue;
			for (int j = 0; j < k; j++)
			{
				if (ar[j] == 0) continue;
				if (i != j)
				{
					if ((ar[i] + ar[j]) % 3 == 0)
					{
						cnt++;
						ar[i] = 0; ar[j] = 0;
					}
					else
					{
						ar[i] = 0; ar[j] = ar[i] + ar[j];
					}
				}
			}
		}
		cout << cnt << '\n';
		cnt = 0; one = 0; two = 0; k=0;
	}
}


#include<iostream>
#include<algorithm>
using namespace std;
long long t, n, cnt;
long long one, two,zz,hh;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> t;
	while (t--)
	{
		cin >> n;
		for (int i = 0; i < n; i++)
		{
			int a;
			cin >> a;
			if (a % 3==0)
				cnt++;
			else if (a < 3)
			{
				 if (a == 1)
					one++;
				else if (a == 2)
					two++;
			}
			else if (a > 3)
			{
				if (a % 2 == 0)
					zz++;
				else
					hh++;
			}
		}
		if (two > one)
		{
			cnt += one;
		}
		else if (two == one)
		{
			cnt += two;
		}
		else
		{
			cnt = cnt + two;
			one = one - two;
			cnt = cnt + one / 3;
		}
		cnt += (zz / 2);
		cnt += (hh / 2);
		cout << cnt << '\n';
		cnt = 0; one = 0; two = 0; zz = 0; hh = 0;
	}
}


#include<iostream>
#include<algorithm>
using namespace std;
int t, n,cnt;
int one, two;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> t;
	while (t--)
	{
		cin >> n;
		for (int i = 0; i < n; i++)
		{
			int a;
			cin >> a;
			if (a == 3)
				cnt++;
			else if(a==1)
				one++;
			else if (a == 2)
				two++;
		}
		if (two > one)
		{
			cnt += one;
		}
		else if (two == one)
		{
			cnt += two;
		}
		else
		{
			cnt += two;
			one -= two;
			cnt += (one / 3);
		}
		cout << cnt << '\n';
		cnt = 0; one = 0; two = 0;
	}
}


#include<iostream>
#include<algorithm>
using namespace std;
long long t, n, cnt;
long long one, two, zz, hh;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> t;
	while (t--)
	{
		cin >> n;
		for (int i = 0; i < n; i++)
		{
			int a;
			cin >> a;
			if (a % 3 == 0)
				cnt++;
			else if (a %3== 1)
				one++;
			else if (a %3== 2)
				two++;

		}
		if (two > one)
		{
			cnt += one;
			two -= one;
			cnt += two / 3;
		}
		else if (two == one)
		{
			cnt += two;
		}
		else
		{
			cnt = cnt + two;
			one = one - two;
			cnt = cnt + one / 3;
		}
		cout << cnt << '\n';
		cnt = 0; one = 0; two = 0; zz = 0; hh = 0;
	}
}


#include<iostream>
#include<algorithm>
using namespace std;
long long t, n, cnt;
long long one, two, zz, hh;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> t;
	while (t--)
	{
		cin >> n;
		for (int i = 0; i < n; i++)
		{
			int a;
			cin >> a;
			if (a % 3 == 0)
				cnt++;
			else if (a < 3)
			{
				if (a %3== 1)
					one++;
				else if (a %3== 2)
					two++;
			}
		}
		if (two > one)
		{
			cnt += one;
		}
		else if (two == one)
		{
			cnt += two;
		}
		else
		{
			cnt = cnt + two;
			one = one - two;
			cnt = cnt + one / 3;
		}
		cout << cnt << '\n';
		cnt = 0; one = 0; two = 0; zz = 0; hh = 0;
	}
}


#include<bits/stdc++.h>
using namespace std;

int main(){
    int t,n;
    cin>>t;
    while(t--){
        cin>>n;
        long long sum = 0,in,temp=0,r;
        for(int i=0;i<n;i++ ){
            cin>>in;
            if(in<3 ){
              temp += in;
                if(temp>=3){
                    r = temp/3;
                    sum+=1;
                    temp = temp-(3*r);
                }
            }else{
                in += temp;
                r = in/3;
                sum+=1;
                temp = in-(3*r);
            }
        }
        cout<<sum<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main(){
    int t,n;
    cin>>t;
    while(t--){
        cin>>n;
        long long sum = 0,in,temp=0;
        int one =0,two =0,ans=0;
        for(int i=0;i<n;i++ ){
            cin>>in;

            if(in<3){
                sum+=in;
            }else if(in%3==0){
                ans+=1;
            }else{
                temp = in/3;
                temp = in-(temp*3);
                if(temp==2)two=2;
                else one = 1;
            }
        }

            if((sum%3)==0){
                 ans+=sum/3;
            }else{
                ans+=sum/3;
                if((sum+one)%3==0)ans+=2;
                if((sum+two)%3==0)ans+=2;

            }

        cout<<ans<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main(){
    int t,n;
    cin>>t;
    while(t--){
        cin>>n;
        long long sum = 0,in,temp=0;
        int one =0,two =0,ans=0;
        for(int i=0;i<n;i++ ){
            cin>>in;
            if(in==1)one++;
           else if(in==2)two++;
           else if(in%3==0)ans++;
           else if(in%3==1)one++;
           else if(in%3==2)two++;
        }
        if(one>two){
            ans+=two;
            ans+=(one-two)/3;
        }else{
            ans+=one;
            ans+=((two-one)*2)/3;
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main(){
    int t,n;
    cin>>t;
    while(t--){
        cin>>n;
        long long sum = 0,in;
        for(int i=0;i<n;i++ ){
            cin>>in;
            sum+=in;
        }
        cout<<sum/3<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main(){
    int t,n;
    cin>>t;
    while(t--){
        cin>>n;
        long long sum = 0,in,temp=0;
        int one =0,two =0,ans=0;
        for(int i=0;i<n;i++ ){
            cin>>in;

            if(in<3){
                sum+=in;
            }else if(in%3==0){
                ans+=1;
            }else{
                temp = in/3;
                temp = in-(temp*3);
                if(temp==2)two=2;
                else one = 1;
            }
        }

            if((sum%3)==0){
                 ans+=sum/3;
            }else{
                ans+=sum/3;
                if((sum+one)%3==0)ans+=1;
                if((sum+two)%3==0)ans+=1;

            }

        cout<<ans<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main(){
    int t,n;
    cin>>t;
    while(t--){
        cin>>n;
        long long sum = 0,in,temp=0;
        int one =0,two =0,ans=0;
        for(int i=0;i<n;i++ ){
            cin>>in;
            in+=temp;
            if((in/3)>0) ans++;
            temp = in-((in/3)*3);

        }

        cout<<ans<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main(){
    int t,n;
    cin>>t;
    while(t--){
        cin>>n;
        long long int in;
        int one =0,two =0,ans=0;
        for(int i=0;i<n;i++ ){
            cin>>in;
            if(in%3==0)ans++;
           else if(in%3==1)one++;
           else if(in%3==2)two++;
        }
        int mn = min(one,two);
        ans+=mn;
        one-=mn;two-=mn;
        ans+=(one+two)/3;
        cout<<ans<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define nn cout<<endl;
#define pb push_back
#define w(c) int c;cin>>c;while(c--)
int main()
{

w(t)
{
 ll n,i,m,j,c=0,one=0,two=0;
 cin>>n;
 ll a[n];
 vector<ll>v;
 vector<ll>b(n);
 for(i=0;i<n;i++)
    {cin>>a[i];
    if(a[i]%3==0) c++;
     if(a[i]%3!=0)
        v.pb(a[i]%3);}
       if(v.size()==0) {cout<<c<<endl;continue;}

for(i=0;i<v.size();i++)
{
    if(v[i]==2)two++;
    else one++;}
    if(one>two) cout<<c+two+(v.size()-2*two)/3<<endl;
    else if(one<=two) cout<<c+one<<endl;}}


#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define nn cout<<endl;
#define pb push_back
#define w(c) int c;cin>>c;while(c--)
int main()
{

w(t)
{
 ll n,i,m,j,c=0,one=0,two=0;
 cin>>n;
 ll a[n];
 vector<ll>v;
 vector<ll>b(n);
 for(i=0;i<n;i++)
    {cin>>a[i];
    if(a[i]%3==0) c++;
     if(a[i]%3!=0)
        v.pb(a[i]%3);}
       if(v.size()==0) {cout<<c<<endl;continue;}

for(i=0;i<v.size();i++)
{
    if(v[i]==2)two++;
    else one++;}
    if(one>two) cout<<c+two+(v.size()-2*two)/3<<endl;
    else if(one<=two) cout<<c+one+(v.size()-2*one)/3<<endl;}}


#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define nn cout<<endl;
#define pb push_back
#define w(c) int c;cin>>c;while(c--)
int main()
{

w(t)
{
 ll n,i,m,j,c=0,one=0,two=0;
 cin>>n;
 ll a[n];
 vector<ll>v;
 vector<ll>b(n);
 for(i=0;i<n;i++)
    {cin>>a[i];
    if(a[i]%3==0) c++;
     if(a[i]%3!=0)
        v.pb(a[i]%3);}

for(i=0;i<v.size();i++)
{
    if(v[i]==2)two++;
    else one++;}
    if(one>two) cout<<c+two+(v.size()-two)/3<<endl;
    else if(one<two) cout<<c+one<<endl;}}


#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define nn cout<<endl;
#define pb push_back
#define w(c) int c;cin>>c;while(c--)
int main()
{

w(t)
{
 ll n,i,m,j,c=0,one=0,two=0;
 cin>>n;
 ll a[n];
 vector<ll>v;
 vector<ll>b(n);
 for(i=0;i<n;i++)
    {cin>>a[i];
    if(a[i]%3==0) c++;
     if(a[i]%3!=0)
        v.pb(a[i]%3);}
       if(v.size()==0) {cout<<c<<endl;continue;}

for(i=0;i<v.size();i++)
{
    if(v[i]==2)two++;
    else one++;}
    if(one>two) cout<<c+two+(v.size()-two)/3<<endl;
    else if(one<two) cout<<c+one<<endl;}}


#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define nn cout<<endl;
#define pb push_back
#define w(c) int c;cin>>c;while(c--)
int main()
{

w(t)
{
 ll n,i,m,j,c=0;
 cin>>n;
 ll a[n];
 vector<ll>v;
 vector<ll>b(n);
 for(i=0;i<n;i++)
    {cin>>a[i];
    if(a[i]%3==0) c++;
     if(a[i]%3!=0)
        v.pb(a[i]%3);}

 for(i=0;i<v.size()-1;i++)
    { for(j=i+1;j<v.size();j++)
       if(v[j]+v[i]==3){v[i]=-1;v[j]=-1;
        c++;}}

  sort(v.rbegin(),v.rend());
   if(v[0]==-1){cout<<c<<endl;continue;}
   b[0]=v[0];
   for(i=1;i<v.size();i++)
   { if(v[i]!=-1)
      {b[i]=b[i-1]+v[i];
      if(b[i]%3==0)
        {c++;b[i-1]=0;}}

   }
   cout<<c<<endl;}}


#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define nn cout<<endl;
#define pb push_back
#define w(c) int c;cin>>c;while(c--)
int main()
{

w(t)
{
 ll n,i,m,j,c=0,one=0,two=0;
 cin>>n;
 ll a[n];
 vector<ll>v;
 vector<ll>b(n);
 for(i=0;i<n;i++)
    {cin>>a[i];
    if(a[i]%3==0) c++;
     if(a[i]%3!=0)
        v.pb(a[i]%3);}
       if(v.size()==0) {cout<<c<<endl;continue;}

for(i=0;i<v.size();i++)
{
    if(v[i]==2)two++;
    else one++;}
    if(one>two) cout<<c+two+(v.size()-two)/3<<endl;
    else if(one<=two) cout<<c+one<<endl;}}


	#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define mod2 998244353
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define sz(v) ((ll)(v).size())
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define pb push_back
	#define f first
	#define s second
	#define dbg(a) cout<<#a<<" --> "<<(a)<<"\n";
	#define forn(i,n) for (ll i=0; i<(n); ++i)
	#define fornd(i,n) for (ll i=(n)-1; i>=0; --i)
	#define forab(i,a,b) for (ll i=(a); i<=(b); ++i)
	#define read(a) ll a; cin >> a;
	#define reads(s) string s; cin >> s;
	#define readb(a, b) ll a, b; cin >> a >> b;
	#define readc(a, b, c) ll a, b, c; cin >> a >> b >> c;
	#define readarr(a, n) int a[(n) + 1] = {}; forab(i, 0, (n-1)) {cin >> a[i];}
	#define readmat(a, n, m) int a[n + 1][m + 1] = {}; forab(i, 1, n) {forab(j, 1, m) cin >> a[i][j];}
	#define readv(A,n) vll A(n,0); forn(i,n) cin>>A[i];
	#define print(a) cout << a << endl;
	#define printarr(a, n) forab (i, 1, n) cout << a[i] << " "; cout << endl;
	#define printv(v) for (int i: v) cout << i << " "; cout << endl;
	#define printmat(a, n, m) forab(i, 1, n) {forab (j, 1, m) cout << a[i][j] << " "; cout << endl;}

	#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
	using namespace std;
	bool isPowerOfTwo(int x) {
    return x && (!(x & (x - 1)));
	}
	int takemod(int x) {
    return (x % mod + mod) % mod;
	}

	int fpow(int base, int power, int MOD) {
    int result = 1;
    base = base % MOD;
    while (power) {
        if (power & 1)
            result = (result * base) % MOD;
        base = (base * base) % MOD;
        power = power >> 1;
    }
    return result;
	}

	int modinv(int x) {return fpow(x, mod - 2, mod);}
	void solve()
	{
		int n;
		cin>>n;
		vi A(n);
		int ans=0,a=0,b=0,c=0;
		forn(i,n)
		{
			cin>>A[i];

			if(A[i]%3==0) a++;
			else if(A[i]%3==1) b++;
			else c++;

		}

		ans+=min(b,c);
		ans+=a;
		b-=min(b,c);c-=min(b,c);
		ans+=((b+c)/3);
		cout<<ans<<endl;

	}
	int main()
	{
		#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		#endif
		fast_io;
		int T=1;
		cin>>T;
		// cin.ignore(); must be there when using getline(cin, s)
		while(T--)
		{
			solve();
		}
		return 0;
	}


	#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define mod2 998244353
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define sz(v) ((ll)(v).size())
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define pb push_back
	#define f first
	#define s second
	#define dbg(a) cout<<#a<<" --> "<<(a)<<"\n";
	#define forn(i,n) for (ll i=0; i<(n); ++i)
	#define fornd(i,n) for (ll i=(n)-1; i>=0; --i)
	#define forab(i,a,b) for (ll i=(a); i<=(b); ++i)
	#define read(a) ll a; cin >> a;
	#define reads(s) string s; cin >> s;
	#define readb(a, b) ll a, b; cin >> a >> b;
	#define readc(a, b, c) ll a, b, c; cin >> a >> b >> c;
	#define readarr(a, n) int a[(n) + 1] = {}; forab(i, 0, (n-1)) {cin >> a[i];}
	#define readmat(a, n, m) int a[n + 1][m + 1] = {}; forab(i, 1, n) {forab(j, 1, m) cin >> a[i][j];}
	#define readv(A,n) vll A(n,0); forn(i,n) cin>>A[i];
	#define print(a) cout << a << endl;
	#define printarr(a, n) forab (i, 1, n) cout << a[i] << " "; cout << endl;
	#define printv(v) for (int i: v) cout << i << " "; cout << endl;
	#define printmat(a, n, m) forab(i, 1, n) {forab (j, 1, m) cout << a[i][j] << " "; cout << endl;}

	#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
	using namespace std;
	bool isPowerOfTwo(int x) {
    return x && (!(x & (x - 1)));
	}
	int takemod(int x) {
    return (x % mod + mod) % mod;
	}

	int fpow(int base, int power, int MOD) {
    int result = 1;
    base = base % MOD;
    while (power) {
        if (power & 1)
            result = (result * base) % MOD;
        base = (base * base) % MOD;
        power = power >> 1;
    }
    return result;
	}

	int modinv(int x) {return fpow(x, mod - 2, mod);}
	void solve()
	{
		ll n;
		cin>>n;
		vll A(n);
		forn(i,n)
		{
			cin>>A[i];
			A[i]=A[i]%3LL;
		}

		ll ans=0,a=0,b=0,c=0;
		forn(i,n)
		{
			if(A[i]==0)a++;
			else if(A[i]==1LL)b++;
			else c++;
		}
		ans+=min(b,c);
		ans+=a;
		b-=min(b,c);c-=min(b,c);
		ans+=((b+c)/3);
		cout<<ans<<endl;

	}
	int main()
	{
		#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		#endif
		fast_io;
		int T=1;
		cin>>T;
		// cin.ignore(); must be there when using getline(cin, s)
		while(T--)
		{
			solve();
		}
		return 0;
	}


	#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define mod2 998244353
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define sz(v) ((ll)(v).size())
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define pb push_back
	#define f first
	#define s second
	#define dbg(a) cout<<#a<<" --> "<<(a)<<"\n";
	#define forn(i,n) for (ll i=0; i<(n); ++i)
	#define fornd(i,n) for (ll i=(n)-1; i>=0; --i)
	#define forab(i,a,b) for (ll i=(a); i<=(b); ++i)
	#define read(a) ll a; cin >> a;
	#define reads(s) string s; cin >> s;
	#define readb(a, b) ll a, b; cin >> a >> b;
	#define readc(a, b, c) ll a, b, c; cin >> a >> b >> c;
	#define readarr(a, n) int a[(n) + 1] = {}; forab(i, 0, (n-1)) {cin >> a[i];}
	#define readmat(a, n, m) int a[n + 1][m + 1] = {}; forab(i, 1, n) {forab(j, 1, m) cin >> a[i][j];}
	#define readv(A,n) vll A(n,0); forn(i,n) cin>>A[i];
	#define print(a) cout << a << endl;
	#define printarr(a, n) forab (i, 1, n) cout << a[i] << " "; cout << endl;
	#define printv(v) for (int i: v) cout << i << " "; cout << endl;
	#define printmat(a, n, m) forab(i, 1, n) {forab (j, 1, m) cout << a[i][j] << " "; cout << endl;}

	#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
	using namespace std;
	bool isPowerOfTwo(int x) {
    return x && (!(x & (x - 1)));
	}
	int takemod(int x) {
    return (x % mod + mod) % mod;
	}

	int fpow(int base, int power, int MOD) {
    int result = 1;
    base = base % MOD;
    while (power) {
        if (power & 1)
            result = (result * base) % MOD;
        base = (base * base) % MOD;
        power = power >> 1;
    }
    return result;
	}

	int modinv(int x) {return fpow(x, mod - 2, mod);}
	void solve()
	{
		ll n;
		cin>>n;
		vll A(n);
		forn(i,n)
		{
			cin>>A[i];
			A[i]=A[i]%3LL;
		}

		ll ans=0,a=0,b=0,c=0;
		forn(i,n)
		{
			if(A[i]==0)a++;
			else if(A[i]==1LL)b++;
			else c++;
		}
		ans+=min(b,c);
		ans+=a;
		b-=min(b,c);c-=min(b,c);
		ans+=(b/3);ans+=(c/3);
		cout<<ans<<endl;

	}
	int main()
	{
		#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		#endif
		fast_io;
		int T=1;
		cin>>T;
		// cin.ignore(); must be there when using getline(cin, s)
		while(T--)
		{
			solve();
		}
		return 0;
	}