#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <climits>
#include <cfloat>

#define NN 11234

using namespace std;

int n, m, numComp;
vector<int> adj[NN];
int deg[NN], col[NN], start;
vector<int> imp;
map< pair<int, int>, vector<int> > pap;
map< pair<int, int>, int > avail;
vector<int> ans1, ans2;

stack<int> tour;
void find_tour(int u) {
	for(int i = 0; i < (int)adj[u].size(); i++) {
		if(avail[make_pair(u, adj[u][i])]) {
			avail[make_pair(u, adj[u][i])]--;
			avail[make_pair(adj[u][i], u)]--;
			find_tour(adj[u][i]);
		}
	}
	tour.push(u);
}

void dfs(int u) {
	col[u] = numComp;
	for(int i = 0; i < (int)adj[u].size(); i++)
		if(!col[adj[u][i]]) dfs(adj[u][i]);
}

int main(void) {
#ifdef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int i, j, k;

	scanf("%d", &m);
	n = 0;
	for(i = 0; i < m; i++) {
		scanf("%d %d", &j, &k), j--, k--;
		adj[j].push_back(k), deg[j]++;
		adj[k].push_back(j), deg[k]++;
		pap[make_pair(j, k)].push_back(i+1);
		pap[make_pair(k, j)].push_back(i+1);
		avail[make_pair(j, k)]++;
		avail[make_pair(k, j)]++;
		n = max(n, max(j, k));
	}
	n++;
	for(i = 0; i < n; i++) if(deg[i]&1) imp.push_back(i);

	if(m < 2 || (imp.size() != 0 && imp.size() != 2 && imp.size() != 4)) {
		printf("-1\n");
		return 0;
	}

	numComp = 0;
	for(i = 0; i < n; i++)
		if(!col[i] && deg[i])
			numComp++, dfs(i);

	if(numComp == 1) {
		for(i = 0; i < n; i++) if(col[i]) start = i;
		if(imp.size()) {
			start = imp[0];
			if(imp.size() == 4) {
				adj[imp[1]].push_back(imp[2]), deg[imp[1]]++;
				adj[imp[2]].push_back(imp[1]), deg[imp[2]]++;
				avail[make_pair(imp[1], imp[2])]++;
				avail[make_pair(imp[2], imp[1])]++;
			}
		}

		find_tour(start);
		i = tour.top(); tour.pop();
		while(!tour.empty()) {
			j = tour.top(); tour.pop();
			if(imp.size() == 4 && ((i == imp[1] && j == imp[2]) || (i == imp[2] && j == imp[1]))) {
				pap[make_pair(i,j)].erase(pap[make_pair(i,j)].end()-1);
				i = j;
				break;
			}
			ans1.push_back(pap[make_pair(i,j)].back());
			pap[make_pair(i,j)].erase(pap[make_pair(i,j)].end()-1);
			i = j;
			if(imp.size() == 2 || imp.size() == 0) break;
		}
		while(!tour.empty()) {
			j = tour.top(); tour.pop();
			ans2.push_back(pap[make_pair(i,j)].back());
			pap[make_pair(i,j)].erase(pap[make_pair(i,j)].end()-1);
			i = j;
		}
	} else if(numComp > 2) {
		printf("-1\n");
		return 0;
	} else {
		// numComp == 2
		int start1, start2;
		if(imp.size() == 4) {
			if(col[imp[0]] == col[imp[1]] && col[imp[1]] == col[imp[2]] && col[imp[2]] == col[imp[3]]) {
				// todos impares na mesma componente
				printf("-1\n");
				return 0;
			}
			for(i = 0; i < 4; i++) if(col[imp[i]] == 1) start1 = imp[i];
			for(i = 0; i < 4; i++) if(col[imp[i]] == 2) start2 = imp[i];
		} else if(imp.size() == 2) {
			if(col[imp[0]] == 1) {
				start1 = imp[0];
				start2 = 0;
				for(i = 0; i < n && !start2; i++) if(col[i] == 2) start2 = i;
			} else if(col[imp[0]] == 2) {
				start1 = 0;
				start2 = imp[0];
				for(i = 0; i < n && !start1; i++) if(col[i] == 1) start1 = i;
			}
		} else {
			start1 = 0;
			start2 = 0;
			for(i = 0; i < n && !start1; i++) if(col[i] == 1) start1 = i;
			for(i = 0; i < n && !start2; i++) if(col[i] == 2) start2 = i;
		}

		find_tour(start1);
		i = tour.top(); tour.pop();
		while(!tour.empty()) {
			j = tour.top(); tour.pop();
			ans1.push_back(pap[make_pair(i,j)].back());
			pap[make_pair(i,j)].erase(pap[make_pair(i,j)].end()-1);
			i = j;
		}

		find_tour(start2);
		i = tour.top(); tour.pop();
		while(!tour.empty()) {
			j = tour.top(); tour.pop();
			ans2.push_back(pap[make_pair(i,j)].back());
			pap[make_pair(i,j)].erase(pap[make_pair(i,j)].end()-1);
			i = j;
		}
	}

	printf("%d\n", ans1.size());
	for(i = 0; i < (int)ans1.size(); i++) printf("%d\n", ans1[i]);
	printf("%d\n", ans2.size());
	for(i = 0; i < (int)ans2.size(); i++) printf("%d\n", ans2[i]);

	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <climits>
#include <cfloat>

#define NN 11234

using namespace std;

int n, m;
vector<int> adj[NN];
int deg[NN], start;
vector<int> imp;
map< pair<int, int>, vector<int> > pap;
map< pair<int, int>, int > avail;
vector<int> ans1, ans2;

stack<int> tour;
void find_tour(int u) {
	for(int i = 0; i < (int)adj[u].size(); i++) {
		if(avail[make_pair(u, adj[u][i])]) {
			avail[make_pair(u, adj[u][i])]--;
			avail[make_pair(adj[u][i], u)]--;
			find_tour(adj[u][i]);
		}
	}
	tour.push(u);
}

int main(void) {
#ifdef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int i, j, k;

	scanf("%d", &m);
	n = 0;
	for(i = 0; i < m; i++) {
		scanf("%d %d", &j, &k), j--, k--;
		adj[j].push_back(k), deg[j]++;
		adj[k].push_back(j), deg[k]++;
		pap[make_pair(j, k)].push_back(i+1);
		pap[make_pair(k, j)].push_back(i+1);
		avail[make_pair(j, k)]++;
		avail[make_pair(k, j)]++;
		n = max(n, max(j, k));
	}
	n++;
	for(i = 0; i < n; i++) if(deg[i]&1) imp.push_back(i);

	if(m < 2 || (imp.size() != 0 && imp.size() != 2 && imp.size() != 4)) {
		printf("-1\n");
		return 0;
	}

	start = 0;
	if(imp.size()) {
		start = imp[0];
		if(imp.size() == 4) {
			adj[imp[1]].push_back(imp[2]), deg[imp[1]];
			adj[imp[2]].push_back(imp[1]), deg[imp[2]];
		}
	}

	vector<int> *ans = &ans1;
	find_tour(start);
	i = tour.top(); tour.pop();
	while(!tour.empty()) {
		j = tour.top(); tour.pop();
		if(ans == &ans1 && imp.size() == 4 && ((i == imp[1] && j == imp[2]) || (i == imp[2] && j == imp[1]))) ans = &ans2;
		ans->push_back(pap[make_pair(i,j)].back());
		pap[make_pair(i,j)].erase(pap[make_pair(i,j)].end()-1);
		if(ans == &ans1 && (imp.size() == 2 || imp.size() == 0)) ans = &ans2;
		i = j;
	}

	printf("%d\n", ans1.size());
	for(i = 0; i < (int)ans1.size(); i++) printf("%d\n", ans1[i]);
	printf("%d\n", ans2.size());
	for(i = 0; i < (int)ans2.size(); i++) printf("%d\n", ans2[i]);

	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <climits>
#include <cfloat>

#define NN 11234

using namespace std;

int n, m, numComp;
vector<int> adj[NN];
int deg[NN], col[NN], start;
vector<int> imp;
map< pair<int, int>, vector<int> > pap;
map< pair<int, int>, int > avail;
vector<int> ans1, ans2;

stack<int> tour;
void find_tour(int u) {
	for(int i = 0; i < (int)adj[u].size(); i++) {
		if(avail[make_pair(u, adj[u][i])]) {
			avail[make_pair(u, adj[u][i])]--;
			avail[make_pair(adj[u][i], u)]--;
			find_tour(adj[u][i]);
		}
	}
	tour.push(u);
}

void dfs(int u) {
	col[u] = numComp;
	for(int i = 0; i < (int)adj[u].size(); i++)
		if(!col[adj[u][i]]) dfs(adj[u][i]);
}

int main(void) {
#ifdef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int i, j, k;

	scanf("%d", &m);
	n = 0;
	for(i = 0; i < m; i++) {
		scanf("%d %d", &j, &k), j--, k--;
		adj[j].push_back(k), deg[j]++;
		adj[k].push_back(j), deg[k]++;
		pap[make_pair(j, k)].push_back(i+1);
		pap[make_pair(k, j)].push_back(i+1);
		avail[make_pair(j, k)]++;
		avail[make_pair(k, j)]++;
		n = max(n, max(j, k));
	}
	n++;
	for(i = 0; i < n; i++) if(deg[i]&1) imp.push_back(i);

	if(m < 2 || (imp.size() != 0 && imp.size() != 2 && imp.size() != 4)) {
		printf("-1\n");
		return 0;
	}

	numComp = 0;
	for(i = 0; i < n; i++)
		if(!col[i] && deg[i])
			numComp++, dfs(i);

	if(numComp == 1) {
		// só tem uma componente
		for(i = 0; i < n; i++) if(col[i]) start = i;
		if(imp.size()) {
			// tem nós ímpares, comece em um deles
			start = imp[0];
			if(imp.size() == 4) {
				// tem 4 nós ímpares, conecte 2 deles
				adj[imp[1]].push_back(imp[2]), deg[imp[1]]++;
				adj[imp[2]].push_back(imp[1]), deg[imp[2]]++;
				avail[make_pair(imp[1], imp[2])]++;
				avail[make_pair(imp[2], imp[1])]++;
			}
		}

		// encontra o caminho
		find_tour(start);

		// monta primeiro caminho
		i = tour.top(); tour.pop();
		while(!tour.empty()) {
			j = tour.top(); tour.pop();
			if(imp.size() == 4 && ((i == imp[1] && j == imp[2]) || (i == imp[2] && j == imp[1]))) {
				pap[make_pair(i,j)].erase(pap[make_pair(i,j)].end()-1);
				i = j;
				break;
			}
			ans1.push_back(pap[make_pair(i,j)].back());
			pap[make_pair(i,j)].erase(pap[make_pair(i,j)].end()-1);
			i = j;
			if(imp.size() == 2 || imp.size() == 0) break;
		}

		// monta segundo caminho
		while(!tour.empty()) {
			j = tour.top(); tour.pop();
			ans2.push_back(pap[make_pair(i,j)].back());
			pap[make_pair(i,j)].erase(pap[make_pair(i,j)].end()-1);
			i = j;
		}
	} else if(numComp > 2) {
		// tem mais que 2 componentes, não dá
		printf("-1\n");
		return 0;
	} else {
		// numComp == 2
		int start1, start2;
		if(imp.size() == 4) {
			if(col[imp[0]] == col[imp[1]] && col[imp[1]] == col[imp[2]] && col[imp[2]] == col[imp[3]]) {
				// todos 4 impares na mesma componente, no way
				printf("-1\n");
				return 0;
			}
			for(i = 0; i < 4; i++) if(col[imp[i]] == 1) start1 = imp[i];
			for(i = 0; i < 4; i++) if(col[imp[i]] == 2) start2 = imp[i];
		} else if(imp.size() == 2) {
			if(col[imp[0]] == 1) {
				// componente 1 tem os 2 nós ímpares
				start1 = imp[0];
				start2 = 0;
				for(i = 0; i < n && !start2; i++) if(col[i] == 2) start2 = i;
			} else if(col[imp[0]] == 2) {
				// componente 2 tem os 2 nós ímpares
				start1 = 0;
				start2 = imp[0];
				for(i = 0; i < n && !start1; i++) if(col[i] == 1) start1 = i;
			}
		} else {
			// as duas componentes só tem nós ímpares
			start1 = 0;
			start2 = 0;
			for(i = 0; i < n && !start1; i++) if(col[i] == 1) start1 = i;
			for(i = 0; i < n && !start2; i++) if(col[i] == 2) start2 = i;
		}

		// encontra o primeiro caminho
		find_tour(start1);
		i = tour.top(); tour.pop();
		while(!tour.empty()) {
			j = tour.top(); tour.pop();
			ans1.push_back(pap[make_pair(i,j)].back());
			pap[make_pair(i,j)].erase(pap[make_pair(i,j)].end()-1);
			i = j;
		}

		// encontra o segundo caminho
		find_tour(start2);
		i = tour.top(); tour.pop();
		while(!tour.empty()) {
			j = tour.top(); tour.pop();
			ans2.push_back(pap[make_pair(i,j)].back());
			pap[make_pair(i,j)].erase(pap[make_pair(i,j)].end()-1);
			i = j;
		}
	}

	printf("%d\n", ans1.size());
	for(i = 0; i < (int)ans1.size(); i++) {
		if(i) printf(" ");
		printf("%d", ans1[i]);
	}
	printf("\n");
	printf("%d\n", ans2.size());
	for(i = 0; i < (int)ans2.size(); i++) {
		if(i) printf(" ");
		printf("%d", ans2[i]);
	}
	printf("\n");

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
inline int get(){
	int n;char c;while((c=getchar())||1)if(c>='0'&&c<='9')break;
	n=c-'0';while((c=getchar())||1){
		if(c>='0'&&c<='9')n=n*10+c-'0';
		else return(n);
	}
}
typedef struct _b{
	int dest;int next;int num;
}bian;bian memchi[1000001];int gn=2;int heads[10001];
inline void add(int s,int t,int num){
	memchi[gn].dest=t;memchi[gn].next=heads[s];heads[s]=gn;memchi[gn].num=num;gn++;
}
unsigned char bv[100001];
int stk[10001];int sp=0;
void dfs(int pt){
	//printf("dfs(%d)\n",pt);
	for(register int i=heads[pt];i;i=memchi[i].next){
		//printf("(%d,%d)\n",pt,memchi[i].dest);
		if(bv[memchi[i].num])continue;bv[memchi[i].num]=1;dfs(memchi[i].dest);
		stk[sp]=memchi[i].num;sp++;
	}
}
int deg[10001];
int main(){
	 freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int n=0;int m=get();
	for(register int i=1;i<=m;i++){
		int s=get(),t=get();deg[s]++;deg[t]++;add(s,t,i);add(t,s,i);n=max(n,s);n=max(n,t);
	}
	int cnt=0;
	for(register int i=1;i<=n;i++){
		if(deg[i]&1)cnt++;
	}
	if(cnt!=0&&cnt!=2&&cnt!=4){
		printf("-1");return(0);
	}
	if(cnt==0){
		dfs(1);if(sp==1){
			printf("-1");return(0);
		}printf("1\n%d\n",stk[0]);
		printf("%d\n",sp-1);
		for(register int i=1;i<sp;i++)printf("%d\n",stk[i]);return(0);
	}
	if(cnt==2){
		for(register int i=1;i<=n;i++){
			if(deg[i]&1){
				dfs(i);if(sp==1){
					printf("-1");return(0);
				}printf("1\n%d\n",stk[0]);
				printf("%d\n",sp-1);
				for(register int i=1;i<sp;i++)printf("%d\n",stk[i]);return(0);
			}
		}
	}
	for(register int i=1;i<=n;i++){
		if(deg[i]&1){
			for(register int j=i+1;j<=n;j++){
				if(deg[j]&1){
					//printf("???%d %d\n",i,j);
					add(i,j,13145);add(j,i,13145);
					for(register int k=j+1;k<=n;k++){
						if(deg[k]&1){
							dfs(k);int cnt1=0;for(register int l=0;l<sp;l++){
								if(stk[l]==13145)break;cnt1++;
							}
							printf("%d\n",cnt1);for(register int l=0;l<cnt1;l++)printf("%d\n",stk[l]);
							printf("%d\n",sp-cnt1-1);for(register int l=cnt1+1;l<sp;l++)printf("%d\n",stk[l]);
							return(0);
						}
					}
				}
			}
		}
	}
	cout<<-1<<endl;
	return(0);
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
inline int get(){
	int n;char c;while((c=getchar())||1)if(c>='0'&&c<='9')break;
	n=c-'0';while((c=getchar())||1){
		if(c>='0'&&c<='9')n=n*10+c-'0';
		else return(n);
	}
}
typedef struct _b{
	int dest;int next;int num;
}bian;bian memchi[1000001];int gn=2;int heads[10001];
inline void add(int s,int t,int num){
	memchi[gn].dest=t;memchi[gn].next=heads[s];heads[s]=gn;memchi[gn].num=num;gn++;
}
unsigned char bv[100001];
int stk[10001];int sp=0;unsigned char bbv[10001];
void dfs(int pt){bbv[pt]=1;
	//printf("dfs(%d)\n",pt);
	for(register int i=heads[pt];i;i=memchi[i].next){
		//printf("(%d,%d)\n",pt,memchi[i].dest);
		if(bv[memchi[i].num])continue;bv[memchi[i].num]=1;dfs(memchi[i].dest);
		stk[sp]=memchi[i].num;sp++;
	}
}
int deg[10001];
vector<int> v;
int ints[10001];
int find(int n){
	if(ints[n]==n)return(n);return(ints[n]=find(ints[n]));
}int back[10001];
int main(){
	freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	for(register int i=1;i<=10000;i++)ints[i]=i;
	int n=0;int m=get();
	for(register int i=1;i<=m;i++){
		int s=get(),t=get();deg[s]++;deg[t]++;add(s,t,i);add(t,s,i);n=max(n,s);n=max(n,t);
		int aa=find(s),ab=find(t);if(aa!=ab)ints[aa]=ab;
	}
	int cnt=0;
	for(register int i=1;i<=n;i++){
		if(deg[i]&1)cnt++;
	}
	if(cnt!=0&&cnt!=2&&cnt!=4){
		printf("-1");return(0);
	}
	if(cnt==0){int me=0;for(register int i=1;i<=n;i++)if(deg[i])me=i;
		dfs(me);if(sp==0){
			printf("-1");return(0);
		}
		if(sp!=m){int tmp=sp;memcpy(back,stk,sizeof(stk));sp=0;
			//for(register int j=0;j<sp;j++)printf("%d\n",stk[j]);
			for(register int j=1;j<=n;j++){
				if(deg[j]&&!bbv[j]){
					sp=0;dfs(j);
					if(sp+tmp!=m){
						cout<<-1<<endl;return(0);
					}
					printf("%d\n",tmp);for(register int j=0;j<tmp;j++)printf("%d\n",back[j]);
					printf("%d\n",sp);for(register int j=0;j<sp;j++)printf("%d\n",stk[j]);
				}

			}return(0);
		}
		printf("1\n%d\n",stk[0]);
		printf("%d\n",sp-1);
		for(register int i=1;i<sp;i++)printf("%d\n",stk[i]);return(0);
	}int rn=0;for(register int i=1;i<=n;i++)if(deg[i]!=0)rn++;
	if(cnt==2){
		for(register int i=1;i<=n;i++){
			if(deg[i]&1){
				dfs(i);if(sp==1&&rn==2){
					printf("-1");return(0);
				}
				if(sp!=m){int tmp=sp;memcpy(back,stk,sizeof(stk));
					//for(register int j=0;j<sp;j++)printf("%d\n",stk[j]);
					for(register int j=1;j<=n;j++){
						if(deg[j]!=0&&!bbv[j]){
							sp=0;dfs(j);
							if(sp+tmp!=m){
								cout<<-1<<endl;return(0);
							}
							printf("%d\n",tmp);for(register int k=0;k<tmp;k++)printf("%d\n",back[k]);
							printf("%d\n",sp);for(register int k=0;k<sp;k++)printf("%d\n",stk[k]);
						}
					}return(0);
				}
				printf("1\n%d\n",stk[0]);
				printf("%d\n",sp-1);
				for(register int j=1;j<sp;j++)printf("%d\n",stk[j]);return(0);
			}
		}
	}
	for(register int i=1;i<=n;i++){
		if(deg[i]&1)v.push_back(i);
	}
	for(register int i=0;i<4;i++){
		for(register int j=i+1;j<4;j++){
			int aa=find(v[i]),ab=find(v[j]);
			if(aa!=ab){
				add(v[i],v[j],12345);add(v[j],v[i],12345);
				for(register int k=0;k<4;k++){
					if(k!=i&&k!=j){
						dfs(v[k]);int cnt1=0;for(register int l=0;l<sp;l++){
							if(stk[l]==12345)break;cnt1++;
						}
						if(sp!=m+1){
							cout<<-1<<endl;return(0);
						}
						printf("%d\n",cnt1);for(register int l=0;l<cnt1;l++)printf("%d\n",stk[l]);
						printf("%d\n",sp-cnt1-1);for(register int l=cnt1+1;l<sp;l++)printf("%d\n",stk[l]);return(0);
					}
				}
			}
		}
	}
	add(v[0],v[1],12345);add(v[1],v[0],12345);dfs(v[2]);
	int cnt1=0;
	for(register int l=0;l<sp;l++){
		if(stk[l]==12345)break;cnt1++;
	}
	if(sp!=m+1){
		cout<<-1<<endl;return(0);
	}
	printf("%d\n",cnt1);for(register int l=0;l<cnt1;l++)printf("%d\n",stk[l]);
	printf("%d\n",sp-cnt1-1);for(register int l=cnt1+1;l<sp;l++)printf("%d\n",stk[l]);
	return(0);
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
inline int get(){
	int n;char c;while((c=getchar())||1)if(c>='0'&&c<='9')break;
	n=c-'0';while((c=getchar())||1){
		if(c>='0'&&c<='9')n=n*10+c-'0';
		else return(n);
	}
}
typedef struct _b{
	int dest;int next;int num;
}bian;bian memchi[1000001];int gn=2;int heads[10001];
inline void add(int s,int t,int num){
	memchi[gn].dest=t;memchi[gn].next=heads[s];heads[s]=gn;memchi[gn].num=num;gn++;
}
unsigned char bv[100001];
int stk[10001];int sp=0;unsigned char bbv[10001];
void dfs(int pt){bbv[pt]=1;
	//printf("dfs(%d)\n",pt);
	for(register int i=heads[pt];i;i=memchi[i].next){
		//printf("(%d,%d)\n",pt,memchi[i].dest);
		if(bv[memchi[i].num])continue;bv[memchi[i].num]=1;dfs(memchi[i].dest);
		stk[sp]=memchi[i].num;sp++;
	}
}
int deg[10001];
vector<int> v;
int ints[10001];
int find(int n){
	if(ints[n]==n)return(n);return(ints[n]=find(ints[n]));
}
int main(){
	freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	for(register int i=1;i<=10000;i++)ints[i]=i;
	int n=0;int m=get();
	for(register int i=1;i<=m;i++){
		int s=get(),t=get();deg[s]++;deg[t]++;add(s,t,i);add(t,s,i);n=max(n,s);n=max(n,t);
		int aa=find(s),ab=find(t);if(aa!=ab)ints[aa]=ab;
	}
	int cnt=0;
	for(register int i=1;i<=n;i++){
		if(deg[i]&1)cnt++;
	}
	if(cnt!=0&&cnt!=2&&cnt!=4){
		printf("-1");return(0);
	}
	if(cnt==0){int me=0;for(register int i=1;i<=n;i++)if(deg[i])me=i;
		dfs(me);if(sp==0){
			printf("-1");return(0);
		}printf("1\n%d\n",stk[0]);
		printf("%d\n",sp-1);
		for(register int i=1;i<sp;i++)printf("%d\n",stk[i]);return(0);
	}int rn=0;for(register int i=1;i<=n;i++)if(deg[i]!=0)rn++;
	if(cnt==2){
		for(register int i=1;i<=n;i++){
			if(deg[i]&1){
				dfs(i);if(sp==1&&rn==2){
					printf("-1");return(0);
				}
				if(sp!=m){
					printf("%d\n",sp);for(register int j=0;j<sp;j++)printf("%d\n",stk[j]);
					for(register int j=1;j<=n;j++){
						if(deg[j]!=0&&!bbv[j]){
							sp=0;dfs(j);printf("%d\n",sp);for(register int k=0;k<sp;k++)printf("%d\n",stk[k]);
						}
					}return(0);
				}
				printf("1\n%d\n",stk[0]);
				printf("%d\n",sp-1);
				for(register int j=1;j<sp;j++)printf("%d\n",stk[j]);return(0);
			}
		}
	}
	for(register int i=1;i<=n;i++){
		if(deg[i]&1)v.push_back(i);
	}
	for(register int i=0;i<4;i++){
		for(register int j=i+1;j<4;j++){
			int aa=find(v[i]),ab=find(v[j]);
			if(aa!=ab){
				add(v[i],v[j],12345);add(v[j],v[i],12345);
				for(register int k=0;k<4;k++){
					if(k!=i&&k!=j){
						dfs(v[k]);int cnt1=0;for(register int l=0;l<sp;l++){
							if(stk[l]==12345)break;cnt1++;
						}
						printf("%d\n",cnt1);for(register int l=0;l<cnt1;l++)printf("%d\n",stk[l]);
						printf("%d\n",sp-cnt1-1);for(register int l=cnt1+1;l<sp;l++)printf("%d\n",stk[l]);return(0);
					}
				}
			}
		}
	}
	add(v[0],v[1],12345);add(v[1],v[0],12345);dfs(v[2]);
	int cnt1=0;
	for(register int l=0;l<sp;l++){
		if(stk[l]==12345)break;cnt1++;
	}
	printf("%d\n",cnt1);for(register int l=0;l<cnt1;l++)printf("%d\n",stk[l]);
	printf("%d\n",sp-cnt1-1);for(register int l=cnt1+1;l<sp;l++)printf("%d\n",stk[l]);
	return(0);
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
inline int get(){
	int n;char c;while((c=getchar())||1)if(c>='0'&&c<='9')break;
	n=c-'0';while((c=getchar())||1){
		if(c>='0'&&c<='9')n=n*10+c-'0';
		else return(n);
	}
}
typedef struct _b{
	int dest;int next;int num;
}bian;bian memchi[1000001];int gn=2;int heads[10001];
inline void add(int s,int t,int num){
	memchi[gn].dest=t;memchi[gn].next=heads[s];heads[s]=gn;memchi[gn].num=num;gn++;
}
unsigned char bv[100001];
int stk[10001];int sp=0;unsigned char bbv[10001];
void dfs(int pt){bbv[pt]=1;
	//printf("dfs(%d)\n",pt);
	for(register int i=heads[pt];i;i=memchi[i].next){
		//printf("(%d,%d)\n",pt,memchi[i].dest);
		if(bv[memchi[i].num])continue;bv[memchi[i].num]=1;dfs(memchi[i].dest);
		stk[sp]=memchi[i].num;sp++;
	}
}
int deg[10001];
vector<int> v;
int ints[10001];
int find(int n){
	if(ints[n]==n)return(n);return(ints[n]=find(ints[n]));
}int back[10001];
int main(){
	freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	for(register int i=1;i<=10000;i++)ints[i]=i;
	int n=0;int m=get();
	for(register int i=1;i<=m;i++){
		int s=get(),t=get();deg[s]++;deg[t]++;add(s,t,i);add(t,s,i);n=max(n,s);n=max(n,t);
		int aa=find(s),ab=find(t);if(aa!=ab)ints[aa]=ab;
	}
	int cnt=0;
	for(register int i=1;i<=n;i++){
		if(deg[i]&1)cnt++;
	}
	if(cnt!=0&&cnt!=2&&cnt!=4){
		printf("-1");return(0);
	}
	if(cnt==0){int me=0;for(register int i=1;i<=n;i++)if(deg[i])me=i;
		dfs(me);if(sp==0){
			printf("-1");return(0);
		}
		if(sp!=m){int tmp=sp;memcpy(back,stk,sizeof(stk));sp=0;
			//for(register int j=0;j<sp;j++)printf("%d\n",stk[j]);
			for(register int j=1;j<=n;j++){
				if(deg[j]&&!bbv[j]){
					sp=0;dfs(j);
					if(sp+tmp!=m){
						cout<<-1<<endl;return(0);
					}
					printf("%d\n",tmp);for(register int j=0;j<tmp;j++)printf("%d\n",back[j]);
					printf("%d\n",sp);for(register int j=0;j<sp;j++)printf("%d\n",stk[j]);
				}

			}return(0);
		}
		printf("1\n%d\n",stk[0]);
		printf("%d\n",sp-1);
		for(register int i=1;i<sp;i++)printf("%d\n",stk[i]);return(0);
	}int rn=0;for(register int i=1;i<=n;i++)if(deg[i]!=0)rn++;
	if(cnt==2){
		for(register int i=1;i<=n;i++){
			if(deg[i]&1){
				dfs(i);if(sp==1&&rn==2){
					printf("-1");return(0);
				}
				if(sp!=m){int tmp=sp;memcpy(back,stk,sizeof(stk));
					for(register int j=0;j<sp;j++)printf("%d\n",stk[j]);
					for(register int j=1;j<=n;j++){
						if(deg[j]!=0&&!bbv[j]){
							sp=0;dfs(j);
							if(sp+tmp!=m){
								cout<<-1<<endl;return(0);
							}
							printf("%d\n",tmp);for(register int k=0;k<tmp;k++)printf("%d\n",back[k]);
							printf("%d\n",sp);for(register int k=0;k<sp;k++)printf("%d\n",stk[k]);
						}
					}return(0);
				}
				printf("1\n%d\n",stk[0]);
				printf("%d\n",sp-1);
				for(register int j=1;j<sp;j++)printf("%d\n",stk[j]);return(0);
			}
		}
	}
	for(register int i=1;i<=n;i++){
		if(deg[i]&1)v.push_back(i);
	}
	for(register int i=0;i<4;i++){
		for(register int j=i+1;j<4;j++){
			int aa=find(v[i]),ab=find(v[j]);
			if(aa!=ab){
				add(v[i],v[j],12345);add(v[j],v[i],12345);
				for(register int k=0;k<4;k++){
					if(k!=i&&k!=j){
						dfs(v[k]);int cnt1=0;for(register int l=0;l<sp;l++){
							if(stk[l]==12345)break;cnt1++;
						}
						if(sp!=m+1){
							cout<<-1<<endl;return(0);
						}
						printf("%d\n",cnt1);for(register int l=0;l<cnt1;l++)printf("%d\n",stk[l]);
						printf("%d\n",sp-cnt1-1);for(register int l=cnt1+1;l<sp;l++)printf("%d\n",stk[l]);return(0);
					}
				}
			}
		}
	}
	add(v[0],v[1],12345);add(v[1],v[0],12345);dfs(v[2]);
	int cnt1=0;
	for(register int l=0;l<sp;l++){
		if(stk[l]==12345)break;cnt1++;
	}
	if(sp!=m+1){
		cout<<-1<<endl;return(0);
	}
	printf("%d\n",cnt1);for(register int l=0;l<cnt1;l++)printf("%d\n",stk[l]);
	printf("%d\n",sp-cnt1-1);for(register int l=cnt1+1;l<sp;l++)printf("%d\n",stk[l]);
	return(0);
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
inline int get(){
	int n;char c;while((c=getchar())||1)if(c>='0'&&c<='9')break;
	n=c-'0';while((c=getchar())||1){
		if(c>='0'&&c<='9')n=n*10+c-'0';
		else return(n);
	}
}
typedef struct _b{
	int dest;int next;int num;
}bian;bian memchi[1000001];int gn=2;int heads[10001];
inline void add(int s,int t,int num){
	memchi[gn].dest=t;memchi[gn].next=heads[s];heads[s]=gn;memchi[gn].num=num;gn++;
}
unsigned char bv[100001];
int stk[10001];int sp=0;
void dfs(int pt){
	//printf("dfs(%d)\n",pt);
	for(register int i=heads[pt];i;i=memchi[i].next){
		//printf("(%d,%d)\n",pt,memchi[i].dest);
		if(bv[memchi[i].num])continue;bv[memchi[i].num]=1;dfs(memchi[i].dest);
		stk[sp]=memchi[i].num;sp++;
	}
}
int deg[10001];
vector<int> v;
int ints[10001];
int find(int n){
	if(ints[n]==n)return(n);return(ints[n]=find(ints[n]));
}
int main(){
	freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	for(register int i=1;i<=10000;i++)ints[i]=i;
	int n=0;int m=get();
	for(register int i=1;i<=m;i++){
		int s=get(),t=get();deg[s]++;deg[t]++;add(s,t,i);add(t,s,i);n=max(n,s);n=max(n,t);
		int aa=find(s),ab=find(t);if(aa!=ab)ints[aa]=ab;
	}
	int cnt=0;
	for(register int i=1;i<=n;i++){
		if(deg[i]&1)cnt++;
	}
	if(cnt!=0&&cnt!=2&&cnt!=4){
		printf("-1");return(0);
	}
	if(cnt==0){int me=0;for(register int i=1;i<=n;i++)if(deg[i])me=i;
		dfs(me);if(sp==0){
			printf("-1");return(0);
		}printf("1\n%d\n",stk[0]);
		printf("%d\n",sp-1);
		for(register int i=1;i<sp;i++)printf("%d\n",stk[i]);return(0);
	}
	if(cnt==2){
		for(register int i=1;i<=n;i++){
			if(deg[i]&1){
				dfs(i);if(sp==1){
					printf("-1");return(0);
				}printf("1\n%d\n",stk[0]);
				printf("%d\n",sp-1);
				for(register int i=1;i<sp;i++)printf("%d\n",stk[i]);return(0);
			}
		}
	}
	for(register int i=1;i<=n;i++){
		if(deg[i]&1)v.push_back(i);
	}
	for(register int i=0;i<4;i++){
		for(register int j=i+1;j<4;j++){
			int aa=find(v[i]),ab=find(v[j]);
			if(aa!=ab){
				add(v[i],v[j],12345);add(v[j],v[i],12345);
				for(register int k=0;k<4;k++){
					if(k!=i&&k!=j){
						dfs(v[k]);int cnt1=0;for(register int l=0;l<sp;l++){
							if(stk[l]==12345)break;cnt1++;
						}
						printf("%d\n",cnt1);for(register int l=0;l<cnt1;l++)printf("%d\n",stk[l]);
						printf("%d\n",sp-cnt1-1);for(register int l=cnt1+1;l<sp;l++)printf("%d\n",stk[l]);return(0);
					}
				}
			}
		}
	}
	add(v[0],v[1],12345);add(v[1],v[0],12345);dfs(v[2]);
	int cnt1=0;
	for(register int l=0;l<sp;l++){
		if(stk[l]==12345)break;cnt1++;
	}
	printf("%d\n",cnt1);for(register int l=0;l<cnt1;l++)printf("%d\n",stk[l]);
	printf("%d\n",sp-cnt1-1);for(register int l=cnt1+1;l<sp;l++)printf("%d\n",stk[l]);
	return(0);
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
inline int get(){
	int n;char c;while((c=getchar())||1)if(c>='0'&&c<='9')break;
	n=c-'0';while((c=getchar())||1){
		if(c>='0'&&c<='9')n=n*10+c-'0';
		else return(n);
	}
}
typedef struct _b{
	int dest;int next;int num;
}bian;bian memchi[1000001];int gn=2;int heads[10001];
inline void add(int s,int t,int num){
	memchi[gn].dest=t;memchi[gn].next=heads[s];heads[s]=gn;memchi[gn].num=num;gn++;
}
unsigned char bv[100001];
int stk[10001];int sp=0;unsigned char bbv[10001];
void dfs(int pt){bbv[pt]=1;
	//printf("dfs(%d)\n",pt);
	for(register int i=heads[pt];i;i=memchi[i].next){
		//printf("(%d,%d)\n",pt,memchi[i].dest);
		if(bv[memchi[i].num])continue;bv[memchi[i].num]=1;dfs(memchi[i].dest);
		stk[sp]=memchi[i].num;sp++;
	}
}
int deg[10001];
vector<int> v;
int ints[10001];
int find(int n){
	if(ints[n]==n)return(n);return(ints[n]=find(ints[n]));
}
int main(){
	freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	for(register int i=1;i<=10000;i++)ints[i]=i;
	int n=0;int m=get();
	for(register int i=1;i<=m;i++){
		int s=get(),t=get();deg[s]++;deg[t]++;add(s,t,i);add(t,s,i);n=max(n,s);n=max(n,t);
		int aa=find(s),ab=find(t);if(aa!=ab)ints[aa]=ab;
	}
	int cnt=0;
	for(register int i=1;i<=n;i++){
		if(deg[i]&1)cnt++;
	}
	if(cnt!=0&&cnt!=2&&cnt!=4){
		printf("-1");return(0);
	}
	if(cnt==0){int me=0;for(register int i=1;i<=n;i++)if(deg[i])me=i;
		dfs(me);if(sp==0){
			printf("-1");return(0);
		}
		if(sp!=m){
			printf("%d\n",sp);for(register int j=0;j<sp;j++)printf("%d\n",stk[j]);
			for(register int j=1;j<=n;j++){
				if(deg[j]&&!bbv[j]){
					sp=0;dfs(j);printf("%d\n",sp);for(register int j=0;j<sp;j++)printf("%d\n",stk[j]);
				}

			}return(0);
		}
		printf("1\n%d\n",stk[0]);
		printf("%d\n",sp-1);
		for(register int i=1;i<sp;i++)printf("%d\n",stk[i]);return(0);
	}int rn=0;for(register int i=1;i<=n;i++)if(deg[i]!=0)rn++;
	if(cnt==2){
		for(register int i=1;i<=n;i++){
			if(deg[i]&1){
				dfs(i);if(sp==1&&rn==2){
					printf("-1");return(0);
				}
				if(sp!=m){
					printf("%d\n",sp);for(register int j=0;j<sp;j++)printf("%d\n",stk[j]);
					for(register int j=1;j<=n;j++){
						if(deg[j]!=0&&!bbv[j]){
							sp=0;dfs(j);printf("%d\n",sp);for(register int k=0;k<sp;k++)printf("%d\n",stk[k]);
						}
					}return(0);
				}
				printf("1\n%d\n",stk[0]);
				printf("%d\n",sp-1);
				for(register int j=1;j<sp;j++)printf("%d\n",stk[j]);return(0);
			}
		}
	}
	for(register int i=1;i<=n;i++){
		if(deg[i]&1)v.push_back(i);
	}
	for(register int i=0;i<4;i++){
		for(register int j=i+1;j<4;j++){
			int aa=find(v[i]),ab=find(v[j]);
			if(aa!=ab){
				add(v[i],v[j],12345);add(v[j],v[i],12345);
				for(register int k=0;k<4;k++){
					if(k!=i&&k!=j){
						dfs(v[k]);int cnt1=0;for(register int l=0;l<sp;l++){
							if(stk[l]==12345)break;cnt1++;
						}
						printf("%d\n",cnt1);for(register int l=0;l<cnt1;l++)printf("%d\n",stk[l]);
						printf("%d\n",sp-cnt1-1);for(register int l=cnt1+1;l<sp;l++)printf("%d\n",stk[l]);return(0);
					}
				}
			}
		}
	}
	add(v[0],v[1],12345);add(v[1],v[0],12345);dfs(v[2]);
	int cnt1=0;
	for(register int l=0;l<sp;l++){
		if(stk[l]==12345)break;cnt1++;
	}
	printf("%d\n",cnt1);for(register int l=0;l<cnt1;l++)printf("%d\n",stk[l]);
	printf("%d\n",sp-cnt1-1);for(register int l=cnt1+1;l<sp;l++)printf("%d\n",stk[l]);
	return(0);
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
inline int get(){
	int n;char c;while((c=getchar())||1)if(c>='0'&&c<='9')break;
	n=c-'0';while((c=getchar())||1){
		if(c>='0'&&c<='9')n=n*10+c-'0';
		else return(n);
	}
}
typedef struct _b{
	int dest;int next;int num;
}bian;bian memchi[1000001];int gn=2;int heads[10001];
inline void add(int s,int t,int num){
	memchi[gn].dest=t;memchi[gn].next=heads[s];heads[s]=gn;memchi[gn].num=num;gn++;
}
unsigned char bv[100001];
int stk[10001];int sp=0;
void dfs(int pt){
	//printf("dfs(%d)\n",pt);
	for(register int i=heads[pt];i;i=memchi[i].next){
		//printf("(%d,%d)\n",pt,memchi[i].dest);
		if(bv[memchi[i].num])continue;bv[memchi[i].num]=1;dfs(memchi[i].dest);
		stk[sp]=memchi[i].num;sp++;
	}
}
int deg[10001];
int main(){
	 freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int n=0;int m=get();
	for(register int i=1;i<=m;i++){
		int s=get(),t=get();deg[s]++;deg[t]++;add(s,t,i);add(t,s,i);n=max(n,s);n=max(n,t);
	}
	int cnt=0;
	for(register int i=1;i<=n;i++){
		if(deg[i]&1)cnt++;
	}
	if(cnt!=0&&cnt!=2&&cnt!=4){
		printf("-1");return(0);
	}
	if(cnt==0){int me=0;for(register int i=1;i<=n;i++)if(deg[i])me=i;
		dfs(me);if(sp==0){
			printf("-1");return(0);
		}printf("1\n%d\n",stk[0]);
		printf("%d\n",sp-1);
		for(register int i=1;i<sp;i++)printf("%d\n",stk[i]);return(0);
	}
	if(cnt==2){
		for(register int i=1;i<=n;i++){
			if(deg[i]&1){
				dfs(i);if(sp==1){
					printf("-1");return(0);
				}printf("1\n%d\n",stk[0]);
				printf("%d\n",sp-1);
				for(register int i=1;i<sp;i++)printf("%d\n",stk[i]);return(0);
			}
		}
	}
	for(register int i=1;i<=n;i++){
		if(deg[i]&1){
			for(register int j=i+1;j<=n;j++){
				if(deg[j]&1){
					//printf("???%d %d\n",i,j);
					add(i,j,13145);add(j,i,13145);
					for(register int k=j+1;k<=n;k++){
						if(deg[k]&1){
							dfs(k);int cnt1=0;for(register int l=0;l<sp;l++){
								if(stk[l]==13145)break;cnt1++;
							}
							printf("%d\n",cnt1);for(register int l=0;l<cnt1;l++)printf("%d\n",stk[l]);
							printf("%d\n",sp-cnt1-1);for(register int l=cnt1+1;l<sp;l++)printf("%d\n",stk[l]);
							return(0);
						}
					}
				}
			}
		}
	}
	cout<<-1<<endl;
	return(0);
}


#include <cstdio>
#include <map>
#include <vector>
#include <cstring>
#define maxn 10002

using namespace std;

struct edge {
    int to, id, next;
} e[2 * maxn];

int n, m, top, head[maxn], deg[maxn], visit[maxn], flag[maxn];
vector <int> ans[2];

inline void add_edge(int x, int y, int id) {
    e[++top].to = y;
    e[top].id = id;
    e[top].next = head[x], head[x] = top;
}

void DFS(int s, int ii) {
    visit[s] = 1;
    for (int j = head[s]; j != -1; j = e[j].next) {
        if (!flag[e[j].id]) {
            flag[e[j].id] = 1;
            flag[e[j^1].id] = 1;
            DFS(e[j].to, ii);
            ans[ii].push_back(e[j].id);
        }
    }
}

void solve() {
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if (deg[i] % 2)++cnt;
    }
    if (cnt > 4) {
        puts("-1");
        return;
    }
    ans[0].clear();
    ans[1].clear();
    memset(visit, 0, sizeof (visit));
    memset(flag, 0, sizeof (flag));
    if (cnt == 0) {
        DFS(0, 0);
        int xflag = 0;
        for (int i = 1; i < n; i++) {
            if (!visit[i]) {
                xflag = i;
                break;
            }
        }
        if (!xflag) {
            if (ans[0].size() == m) {
                printf("%d\n%d\n", 1, ans[0][0]);
                printf("%d\n%d", m - 1, ans[0][1]);
                for (int i = 2; i < m; i++) {
                    printf(" %d", ans[0][i]);
                }
                puts("");
            }
            else puts("-1");
        }
        else {
            DFS(xflag, 1);
            if (ans[0].size() + ans[1].size() != m) {
                puts("-1");
            }
            else {
                printf("%d\n%d", ans[0].size(), ans[0][0]);
                for (int i = 1; i < ans[0].size(); i++) {
                    printf(" %d", ans[0][i]);
                }
                puts("");
                printf("%d\n%d", ans[1].size(), ans[1][0]);
                for (int i = 1; i < ans[1].size(); i++) {
                    printf(" %d", ans[1][i]);
                }
                puts("");
            }
        }
    }
    else {
        cnt = 0;
        for (int i = 0; i < n; i++) {
            if (deg[i] % 2 == 1 && !visit[i]) {
                if (++cnt > 2)break;
                DFS(i, cnt - 1);
            }
        }
        if (cnt > 2)puts("-1");
        else {
            if (cnt == 1) {
                int xflag = -1;
                for (int i = 0; i < n; i++) {
                    if (!visit[i]) {
                        xflag = i;
                        break;
                    }
                }
                if (xflag == -1) {
                    if (ans[0].size() == m) {
                        printf("%d\n%d\n", 1, ans[0][0]);
                        printf("%d\n%d", m - 1, ans[0][1]);
                        for (int i = 2; i < m; i++) {
                            printf(" %d", ans[0][i]);
                        }
                        puts("");
                    }
                    else puts("-1");
                }
                else {
                    DFS(xflag, 1);
                    if (ans[0].size() + ans[1].size() != m) {
                        puts("-1");
                    }
                    else {
                        printf("%d\n%d", ans[0].size(), ans[0][0]);
                        for (int i = 1; i < ans[0].size(); i++) {
                            printf(" %d", ans[0][i]);
                        }
                        puts("");
                        printf("%d\n%d", ans[1].size(), ans[1][0]);
                        for (int i = 1; i < ans[1].size(); i++) {
                            printf(" %d", ans[1][i]);
                        }
                        puts("");
                    }
                }
            }
            else {
                if (ans[0].size() + ans[1].size() != m) {
                    puts("-1");
                }
                else {
                    printf("%d\n%d", ans[0].size(), ans[0][0]);
                    for (int i = 1; i < ans[0].size(); i++) {
                        printf(" %d", ans[0][i]);
                    }
                    puts("");
                    printf("%d\n%d", ans[1].size(), ans[1][0]);
                    for (int i = 1; i < ans[1].size(); i++) {
                        printf(" %d", ans[1][i]);
                    }
                    puts("");
                }
            }
        }
    }
}

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    while (scanf("%d", &m) != EOF) {
        n = 0, top = -1;
        map <int, int> mp;
        map <int, int> ::iterator p;
        memset(head, -1, sizeof (head));
        memset(deg, 0, sizeof (deg));
        for (int i = 0; i < m; i++) {
            int x, y;
            scanf("%d%d", &x, &y);
            p = mp.find(x);
            if (p == mp.end()) {
                mp.insert(make_pair(x, n));
                x = n++;
            }
            else x = p->second;

            p = mp.find(y);
            if (p == mp.end()) {
                mp.insert(make_pair(y, n));
                y = n++;
            }
            else y = p->second;
            add_edge(x, y, i + 1);
            add_edge(y, x, i + 1);
            ++deg[x], ++deg[y];
        }
        if (m < 2)
            puts("-1");
        else
            solve();
    }
    return 0;
}


#include <cstdio>
#include <vector>
#include <cstring>
#include <map>
#define maxn 10010

using namespace std;

struct edge {
    int to, id, next;
} e[2 * maxn];

int n, m, head[maxn], top, deg[maxn];
bool visit[maxn], flag[maxn];
vector <int> ans[2];

inline void add_edge(int x, int y, int id) {
    e[++top].to = y;
    e[top].id = id;
    e[top].next = head[x], head[x] = top;
}

void dfs(int s) {
    visit[s] = 1;
    for (int j = head[s]; j != -1; j = e[j].next) {
        if (!visit[e[j].to]) {
            dfs(e[j].to);
        }
    }
}

void DFS(int s, int ii) {
    visit[s] = 1;
    for (int j = head[s]; j != -1; j = e[j].next) {
        if (!flag[e[j].id]) {
            flag[e[j].id] = 1;
            DFS(e[j].to, ii);
            ans[ii].push_back(e[j].id);
        }
    }
}

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

void solve() {
    n = 0, top = -1;
    memset(head, -1, sizeof (head));
    memset(deg, 0, sizeof (deg));

    map <int, int> mp;
    map <int, int> ::iterator p;

    for (int i = 0; i < m; i++) {
        int x, y, u, v;
        scanf("%d%d", &x, &y);

        p = mp.find(x);
        if (p == mp.end()) {
            mp.insert(make_pair(x, n));
            u = n++;
        }
        else u = p->second;

        p = mp.find(y);
        if (p == mp.end()) {
            mp.insert(make_pair(y, n));
            v = n++;
        }
        else v = p->second;
        add_edge(u, v, i + 1);
        add_edge(v, u, i + 1);
        ++deg[u], ++deg[v];
    }
    if (m < 2) {
        puts("-1");
        return;
    }
    int cnt = 0;
    memset(visit, 0, sizeof (visit));
    for (int i = 0; i < n; i++) {
        if (!visit[i]) {
            if (++cnt > 2) {
                puts("-1");
                return;
            }
            dfs(i);
        }
    }

    memset(flag, 0, sizeof (flag));
    ans[0].clear();
    ans[1].clear();

    if (cnt == 1) {
        int xcnt = 0;
        for (int i = 0; i < n; i++) {
            if (deg[i] % 2) {
                ++xcnt;
            }
        }
        if (xcnt == 0) {
            DFS(0, 0);
        }
        else if (xcnt == 2) {
            for (int i = 0; i < n; i++) {
                if (deg[i] % 2) {
                    DFS(i, 0);
                    break;
                }
            }
        }
        else if (xcnt == 4) {
            int x1 = -1, x2 = -1;
            for (int i = 0; i < n; i++) {
                if (deg[i] % 2) {
                    if (x1 == -1) {
                        x1 = i;
                    }
                    else if (x2 == -1) {
                        x2 = i;
                        break;
                    }
                }
            }
            add_edge(x1, x2, m + 1);
            add_edge(x2, x1, m + 1);
            ++deg[x1], ++deg[x2];
            for (int i = 0; i < n; i++) {
                if (deg[i] % 2) {
                    DFS(i, 0);
                    break;
                }
            }
            if (ans[0].size() != m + 1) {
                puts("-1");
                return;
            }
            int i = 0;
            for (; i < ans[0].size(); i++) {
                if (ans[0][i] == m + 1) {
                    for (int j = i + 1; j < ans[0].size(); j++) {
                        ans[1].push_back(ans[0][j]);
                    }
                    break;
                }
            }
            ans[0].erase(ans[0].begin() + i, ans[0].end());
        }
        else {
            puts("-1");
            return;
        }
    }
    else {
        memset(visit, 0, sizeof (visit));
        int xcnt = 0;
        for (int i = 0; i < n; i++) {
            if (deg[i] % 2 && !visit[i]) {
                if (++xcnt > 2) {
                    puts("-1");
                    return;
                }
                DFS(i, xcnt - 1);
            }
        }
        if (xcnt == 0) {
            int ycnt = 0;
            for (int i = 0; i < n; i++) {
                if (!visit[i]) {
                    if (++ycnt > 2) {
                        puts("-1");
                        return;
                    }
                    DFS(i, ycnt - 1);
                }
            }
        }
        else if (xcnt == 1) {
            for (int i = 0; i < n; i++) {
                if (!visit[i]) {
                    DFS(i, 1);
                    break;
                }
            }
        }
    }
    output();
}

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    while (scanf("%d", &m) != EOF) {
        //scanf("%d", &m);
        solve();
    }
    return 0;
}


#include <cstdio>
#include <vector>
#include <cstring>
#include <map>
#define maxn 10010

using namespace std;

struct edge {
    int to, id, next;
} e[2 * maxn];

int n, m, head[maxn], top, deg[maxn], odd;
bool visit[maxn], flag[maxn];
vector <int> ans[2];

inline void add_edge(int x, int y, int id) {
    e[++top].to = y;
    e[top].id = id;
    e[top].next = head[x], head[x] = top;
}

void dfs(int s) {
    visit[s] = 1;
    if (deg[s] % 2)odd++;
    for (int j = head[s]; j != -1; j = e[j].next) {
        if (!visit[e[j].to]) {
            dfs(e[j].to);
        }
    }
}

void DFS(int s, int ii) {
    visit[s] = 1;
    for (int j = head[s]; j != -1; j = e[j].next) {
        if (!flag[e[j].id]) {
            flag[e[j].id] = 1;
            DFS(e[j].to, ii);
            ans[ii].push_back(e[j].id);
        }
    }
}

void output() {
    if (ans[0].size() + ans[1].size() != m) {
        puts("-1");
    }
    else {
        if (ans[0].size() == m) {
            printf("1\n%d\n%d\n", ans[0][0], m - 1);
            for (int i = 1; i < m; i++) {
                printf("%d ", ans[0][i]);
            }
            puts("");
        }
        else {
            printf("%d\n", ans[0].size());
            for (int i = 0; i < ans[0].size(); i++) {
                printf("%d ", ans[0][i]);
            }
            puts("");
            printf("%d\n", ans[1].size());
            for (int i = 0; i < ans[1].size(); i++) {
                printf("%d ", ans[1][i]);
            }
            puts("");
        }
    }
}

void solve() {
    n = 0, top = -1;
    memset(head, -1, sizeof (head));
    memset(deg, 0, sizeof (deg));

    map <int, int> mp;
    map <int, int> ::iterator p;

    for (int i = 0; i < m; i++) {
        int x, y, u, v;
        scanf("%d%d", &x, &y);

        p = mp.find(x);
        if (p == mp.end()) {
            mp.insert(make_pair(x, n));
            u = n++;
        }
        else u = p->second;

        p = mp.find(y);
        if (p == mp.end()) {
            mp.insert(make_pair(y, n));
            v = n++;
        }
        else v = p->second;
        add_edge(u, v, i + 1);
        add_edge(v, u, i + 1);
        ++deg[u], ++deg[v];
    }
    if (m < 2) {
        puts("-1");
        return;
    }
    int cnt = 0;
    memset(visit, 0, sizeof (visit));
    for (int i = 0; i < n; i++) {
        if (!visit[i]) {
            if (++cnt > 2) {
                puts("-1");
                return;
            }
            dfs(i);
        }
    }

    memset(flag, 0, sizeof (flag));
    ans[0].clear();
    ans[1].clear();

    if (cnt == 1) {
        int xcnt = 0;
        for (int i = 0; i < n; i++) {
            if (deg[i] % 2) {
                ++xcnt;
            }
        }
        if (xcnt == 0) {
            DFS(0, 0);
        }
        else if (xcnt == 2) {
            for (int i = 0; i < n; i++) {
                if (deg[i] % 2) {
                    DFS(i, 0);
                    break;
                }
            }
        }
        else if (xcnt == 4) {
            int x1 = -1, x2 = -1;
            for (int i = 0; i < n; i++) {
                if (deg[i] % 2) {
                    if (x1 == -1) {
                        x1 = i;
                    }
                    else if (x2 == -1) {
                        x2 = i;
                        break;
                    }
                }
            }
            add_edge(x1, x2, m + 1);
            add_edge(x2, x1, m + 1);
            ++deg[x1], ++deg[x2];
            for (int i = 0; i < n; i++) {
                if (deg[i] % 2) {
                    DFS(i, 0);
                    break;
                }
            }
            if (ans[0].size() != m + 1) {
                puts("-1");
                return;
            }
            int i = 0;
            for (; i < ans[0].size(); i++) {
                if (ans[0][i] == m + 1) {
                    for (int j = i + 1; j < ans[0].size(); j++) {
                        ans[1].push_back(ans[0][j]);
                    }
                    break;
                }
            }
            ans[0].erase(ans[0].begin() + i, ans[0].end());
        }
        else {
            puts("-1");
            return;
        }
    }
    else {
        memset(visit, 0, sizeof (visit));
        vector <int> oods;
        for (int i = 0; i < n; i++) {
            if (!visit[i]) {
                odd = 0;
                dfs(i);
                oods.push_back(odd);
            }
        }
        memset(visit, 0, sizeof (visit));
        if (oods[0] > 2 || oods[1] > 2) {
            puts("-1");
            return;
        }
        int required = (oods[0] == 2) + (oods[1] == 2), xcnt = 0;
        for (int i = 0; i < n; i++) {
            if (!visit[i]) {
                if (!required || deg[i] % 2) {
                    if (++xcnt > 2) {
                        puts("-1");
                        return;
                    }
                    if (required)--required;
                    DFS(i, xcnt - 1);
                }
            }
        }
        if (xcnt == 1) {
            for (int i = 0; i < n; i++) {
                if (!visit[i]) {
                    DFS(i, 1);
                    break;
                }
            }
        }
    }
    output();
}

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    while (scanf("%d", &m) != EOF) {
        solve();
    }
    return 0;
}


#include <cstdio>
#include <vector>
#include <cstring>
#include <map>
#define maxn 10010

using namespace std;

struct edge {
	int to, id, next;
} e[2 * maxn];

int n, m, head[maxn], top, deg[maxn], od;
bool visit[maxn], flag[maxn];
vector <int> ans[2];

inline void add_edge(int x, int y, int id) {
	e[++top].to = y;
	e[top].id = id;
	e[top].next = head[x], head[x] = top;
}

void dfs(int s) {
	visit[s] = 1;
	if (deg[s] % 2)++od;
	for (int j = head[s]; j != -1; j = e[j].next) {
		if (!visit[e[j].to]) {
			dfs(e[j].to);
		}
	}
}

void DFS(int s, int ii) {
	visit[s] = 1;
	for (int j = head[s]; j != -1; j = e[j].next) {
		if (!flag[e[j].id]) {
			flag[e[j].id] = 1;
			DFS(e[j].to, ii);
			ans[ii].push_back(e[j].id);
		}
	}
}

void output() {
	if (ans[0].size() + ans[1].size() != m) {
		puts("-1");
	}
	else {
		if (ans[0].size() == m) {
			printf("1\n%d\n", ans[0][0]);
			printf("%d\n", m - 1);
			for (int i = 1; i < m; i++) {
				printf("%d ", ans[0][i]);
			}
			puts("");
		}
		else {
			printf("%d\n", ans[0].size());
			for (int i = 0; i < ans[0].size(); i++) {
				printf("%d ", ans[0][i]);
			}
			puts("");
			printf("%d\n", ans[1].size());
			for (int i = 0; i < ans[1].size(); i++) {
				printf("%d ", ans[1][i]);
			}
			puts("");
		}
	}
}

void solve() {
	n = 0, top = -1;
	memset(head, -1, sizeof (head));
	memset(deg, 0, sizeof (deg));

	map <int, int> mp;
	map <int, int> ::iterator p;

	for (int i = 0; i < m; i++) {
		int x, y, u, v;
		scanf("%d%d", &x, &y);

		p = mp.find(x);
		if (p == mp.end()) {
			mp.insert(make_pair(x, n));
			u = n++;
		}
		else u = p->second;

		p = mp.find(y);
		if (p == mp.end()) {
			mp.insert(make_pair(y, n));
			v = n++;
		}
		else v = p->second;
		add_edge(u, v, i + 1);
		add_edge(v, u, i + 1);
		++deg[u], ++deg[v];
	}
	if (m < 2) {
		puts("-1");
		return;
	}
	int cnt = 0;
	vector <int> oods;
	memset(visit, 0, sizeof (visit));
	for (int i = 0; i < n; i++) {
		if (!visit[i]) {
			if (++cnt > 2) {
				puts("-1");
				return;
			}
			od = 0;
			dfs(i);
			oods.push_back(od);
		}
	}
	ans[0].clear(), ans[1].clear();
	memset(visit, 0, sizeof (visit));
	memset(flag, 0, sizeof (flag));
	if (cnt == 1) {
		if (oods[0] == 0) {
			DFS(0, 0);
		}
		else {
			if (oods[0] == 2) {
				for (int i = 0; i < n; i++) {
					if (deg[i] % 2) {
						DFS(i, 0);
						break;
					}
				}
			}
			else {
				int x1 = -1, x2 = -1;
				for (int i = 0; i < n; i++) {
					if (deg[i] % 2) {
						if (x1 == -1)x1 = i;
						else if (x2 == -1)x2 = i;
					}
				}
				add_edge(x1, x2, m + 1);
				add_edge(x2, x1, m + 1);
				for (int i = 0; i < n; i++) {
					if (i != x1 && i != x2 && deg[i] % 2) {
						DFS(i, 0);
						break;
					}
				}
				int i = 0;
				for (i = 0; i < ans[0].size(); i++) {
					if (ans[0][i] == m + 1) {
						for (int j = i + 1; j < ans[0].size(); j++) {
							ans[1].push_back(ans[0][j]);
						}
						break;
					}
				}
				ans[0].erase(ans[0].begin() + i, ans[0].end());
			}
		}
	}
	else {
		int xcnt = 0;
		for (int i = 0; i < n; i++) {
			if (deg[i] % 2 && !visit[i]) {
				if (++xcnt > 2) {
					puts("-1");
					return;
				}
				DFS(i, xcnt - 1);
			}
		}
		if (xcnt != 2) {
			for (int i = 0; i < n; i++) {
				if (!visit[i]) {
					DFS(i, 1);
					break;
				}
			}
		}
		if (xcnt == 0) {
			for (int i = 0; i < n; i++) {
				if (!visit[i]) {
					DFS(i, 0);
					break;
				}
			}
		}
	}
	output();
}

int main() {
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	while (scanf("%d", &m) != EOF) {
		solve();
	}
	return 0;
}


#include <cstdio>
#include <map>
#include <vector>
#include <cstring>
#define maxn 10002

using namespace std;

struct edge {
    int to, id, next;
} e[2 * maxn];

int n, m, top, head[maxn], deg[maxn], visit[maxn], flag[maxn];
vector <int> ans[2];

inline void add_edge(int x, int y, int id) {
    e[++top].to = y;
    e[top].id = id;
    e[top].next = head[x], head[x] = top;
}

void DFS(int s, int ii) {
    visit[s] = 1;
    for (int j = head[s]; j != -1; j = e[j].next) {
        if (!flag[e[j].id]) {
            flag[e[j].id] = 1;
            flag[e[j^1].id] = 1;
            DFS(e[j].to, ii);
            ans[ii].push_back(e[j].id);
        }
    }
}

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

void solve() {
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if (deg[i] % 2)++cnt;
    }
    if (cnt > 4) {
        puts("-1");
        return;
    }

    ans[0].clear();
    ans[1].clear();
    memset(visit, 0, sizeof (visit));
    memset(flag, 0, sizeof (flag));

    if (cnt == 0) {
        DFS(0, 0);
        int xflag = 0;
        for (int i = 1; i < n; i++) {
            if (!visit[i]) {
                xflag = i;
                break;
            }
        }
        if (!xflag) {
            output();
        }
        else {
            DFS(xflag, 1);
            output();
        }
    }
    else {
        cnt = 0;
        for (int i = 0; i < n; i++) {
            if (deg[i] % 2 == 1 && !visit[i]) {
                if (++cnt > 2)break;
                DFS(i, cnt - 1);
            }
        }
        if (cnt > 2)puts("-1");
        else {
            if (cnt == 1) {
                int xflag = -1;
                for (int i = 0; i < n; i++) {
                    if (!visit[i]) {
                        xflag = i;
                        break;
                    }
                }
                if (xflag == -1) {
                    output();
                }
                else {
                    DFS(xflag, 1);
                    output();
                }
            }
            else {
                output();
            }
        }
    }
}

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    while (scanf("%d", &m) != EOF) {
        n = 0, top = -1;
        map <int, int> mp;
        map <int, int> ::iterator p;
        memset(head, -1, sizeof (head));
        memset(deg, 0, sizeof (deg));
        for (int i = 0; i < m; i++) {
            int x, y;
            scanf("%d%d", &x, &y);
            p = mp.find(x);
            if (p == mp.end()) {
                mp.insert(make_pair(x, n));
                x = n++;
            }
            else x = p->second;

            p = mp.find(y);
            if (p == mp.end()) {
                mp.insert(make_pair(y, n));
                y = n++;
            }
            else y = p->second;
            add_edge(x, y, i + 1);
            add_edge(y, x, i + 1);
            ++deg[x], ++deg[y];
        }
        if (m < 2)
            puts("-1");
        else
            solve();
    }
    return 0;
}


#include <cstdio>
#include <vector>
#include <cstring>
#include <map>
#define maxn 10010

using namespace std;

struct edge {
    int to, id, next;
} e[2 * maxn];

int n, m, head[maxn], top, deg[maxn], odd;
bool visit[maxn], flag[maxn];
vector <int> ans[2];

inline void add_edge(int x, int y, int id) {
    e[++top].to = y;
    e[top].id = id;
    e[top].next = head[x], head[x] = top;
}

void dfs(int s) {
    visit[s] = 1;
    if (deg[s] % 2)odd++;
    for (int j = head[s]; j != -1; j = e[j].next) {
        if (!visit[e[j].to]) {
            dfs(e[j].to);
        }
    }
}

void DFS(int s, int ii) {
    visit[s] = 1;
    for (int j = head[s]; j != -1; j = e[j].next) {
        if (!flag[e[j].id]) {
            flag[e[j].id] = 1;
            DFS(e[j].to, ii);
            ans[ii].push_back(e[j].id);
        }
    }
}

void output() {
    if (ans[0].size() + ans[1].size() != m) {
        puts("-1");
    }
    else {
        if (ans[0].size() == m) {
            printf("1\n%d\n%d\n", ans[0][0], m - 1);
            for (int i = 1; i < m; i++) {
                printf("%d ", ans[0][i]);
            }
            puts("");
        }
        else {
            printf("%d\n", ans[0].size());
            for (int i = 0; i < ans[0].size(); i++) {
                printf("%d ", ans[0][i]);
            }
            puts("");
            printf("%d\n", ans[1].size());
            for (int i = 0; i < ans[1].size(); i++) {
                printf("%d ", ans[1][i]);
            }
            puts("");
        }
    }
}

void solve() {
    n = 0, top = -1;
    memset(head, -1, sizeof (head));
    memset(deg, 0, sizeof (deg));

    map <int, int> mp;
    map <int, int> ::iterator p;

    for (int i = 0; i < m; i++) {
        int x, y, u, v;
        scanf("%d%d", &x, &y);

        p = mp.find(x);
        if (p == mp.end()) {
            mp.insert(make_pair(x, n));
            u = n++;
        }
        else u = p->second;

        p = mp.find(y);
        if (p == mp.end()) {
            mp.insert(make_pair(y, n));
            v = n++;
        }
        else v = p->second;
        add_edge(u, v, i + 1);
        add_edge(v, u, i + 1);
        ++deg[u], ++deg[v];
    }
    if (m < 2) {
        puts("-1");
        return;
    }
    int cnt = 0;
    memset(visit, 0, sizeof (visit));
    for (int i = 0; i < n; i++) {
        if (!visit[i]) {
            if (++cnt > 2) {
                puts("-1");
                return;
            }
            dfs(i);
        }
    }

    memset(flag, 0, sizeof (flag));
    ans[0].clear();
    ans[1].clear();

    if (cnt == 1) {
        int xcnt = 0;
        for (int i = 0; i < n; i++) {
            if (deg[i] % 2) {
                ++xcnt;
            }
        }
        if (xcnt == 0) {
            DFS(0, 0);
        }
        else if (xcnt == 2) {
            for (int i = 0; i < n; i++) {
                if (deg[i] % 2) {
                    DFS(i, 0);
                    break;
                }
            }
        }
        else if (xcnt == 4) {
            int x1 = -1, x2 = -1;
            for (int i = 0; i < n; i++) {
                if (deg[i] % 2) {
                    if (x1 == -1) {
                        x1 = i;
                    }
                    else if (x2 == -1) {
                        x2 = i;
                        break;
                    }
                }
            }
            add_edge(x1, x2, m + 1);
            add_edge(x2, x1, m + 1);
            ++deg[x1], ++deg[x2];
            for (int i = 0; i < n; i++) {
                if (deg[i] % 2) {
                    DFS(i, 0);
                    break;
                }
            }
            if (ans[0].size() != m + 1) {
                puts("-1");
                return;
            }
            int i = 0;
            for (; i < ans[0].size(); i++) {
                if (ans[0][i] == m + 1) {
                    for (int j = i + 1; j < ans[0].size(); j++) {
                        ans[1].push_back(ans[0][j]);
                    }
                    break;
                }
            }
            ans[0].erase(ans[0].begin() + i, ans[0].end());
        }
        else {
            puts("-1");
            return;
        }
    }
    else {
        memset(visit, 0, sizeof (visit));
        vector <int> oods;
        for (int i = 0; i < n; i++) {
            if (!visit[i]) {
                odd = 0;
                dfs(i);
                oods.push_back(odd);
            }
        }
        int xcnt = 0;
        memset(visit, 0, sizeof (visit));
        if (oods[0] > 2 || oods[1] > 2) {
            puts("-1");
            return;
        }
        if (oods[0] + oods[1] == 2) {
            for (int i = 0; i < n; i++) {
                if (deg[i] % 2) {
                    DFS(i, 0);
                    break;
                }
            }
            for (int i = 0; i < n; i++) {
                if (!visit[i]) {
                    DFS(i, 1);
                    break;
                }
            }
        }
        else if (oods[0] + oods[1] == 4) {
            for (int i = 0; i < n; i++) {
                if (deg[i] % 2 && !visit[i]) {
                    if (++xcnt > 2) {
                        puts("-1");
                        return;
                    }
                    DFS(i, xcnt - 1);
                }
            }
        }
        else {
            for (int i = 0; i < n; i++) {
                if (!visit[i]) {
                    if (++xcnt > 2) {
                        puts("-1");
                        return;
                    }
                    DFS(i, xcnt - 1);
                }
            }
        }
    }
    output();
}

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    while (scanf("%d", &m) != EOF) {
        //scanf("%d", &m);
        solve();
    }
    return 0;
}


#include <cstdio>
#include <cstring>

using namespace std;

struct edge {
    int to, id, next;
} e[20010];

int tot[2], n, m, deg[10010], head[10010], path[2][10010];
bool flag[10010], visit[10010];

inline void add_edge(int x, int y, int &top, int id) {
    e[++top].to = y;
    e[top].id = id;
    e[top].next = head[x], head[x] = top;

    e[++top].to = x;
    e[top].id = id;
    e[top].next = head[y], head[y] = top;
}

void DFS(int s, int ii) {
    while (head[s] != -1) {
        int j = head[s];
        if (!visit[e[j].id]) {
            DFS(e[j].to, ii);
            path[ii][tot[ii]++] = e[j].id;
        }
    }
}

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    while (scanf("%d", &m) != EOF) {
        int top = -1;
        memset(deg, 0, sizeof (deg));
        memset(flag, 0, sizeof (flag));
        memset(head, -1, sizeof (head));
        for (int i = 0; i < m; i++) {
            int u, v;
            scanf("%d%d", &u, &v);
            add_edge(u, v, top, i);
            ++deg[u], ++deg[v];
            flag[u] = 1, flag[v] = 1;
        }
        memset(tot, 0, sizeof (tot));
        memset(visit, 0, sizeof (visit));
        int cnt = 0;
        for (int i = 1; i <= 10010; i++) {
            if (deg[i] % 2) {
                int xflag = 0;
                for (int j = head[i]; j != -1; j = e[j].next) {
                    if (!visit[e[j].id]) {
                        xflag = 1;
                    }
                }
                if (!xflag)continue;
                if (++cnt > 2)break;
                DFS(i, cnt - 1);
            }
        }
        if (cnt > 2)puts("-1");
        else {
            if (cnt == 0) {
                for (int i = 1; i < 10010; i++) {
                    if (flag[i]) {
                        int xflag = 0;
                        for (int j = head[i]; j != -1; j = e[j].next) {
                            if (!visit[e[j].to]) {
                                xflag = 1;
                            }
                        }
                        if (!xflag)continue;
                        if (++cnt > 2)break;
                        DFS(i, cnt - 1);
                    }
                }
            }
            if (tot[0] + tot[1] != m) {
                puts("-1");
                continue;
            }
            printf("%d\n", tot[0]);
            for (int i = 0; i < tot[0]; i++) {
                printf("%d ", path[0][i]);
            }
            puts("");
            printf("%d\n", tot[1]);
            for (int i = 0; i < tot[1]; i++) {
                printf("%d ", path[1][i]);
            }
            puts("");
        }
    }
    return 0;
}


#include <cstdio>
#include <vector>
#include <cstring>
#include <map>
#define maxn 10010

using namespace std;

struct edge {
	int to, id, next;
} e[2 * maxn];

int n, m, head[maxn], top, deg[maxn];
bool visit[maxn], flag[maxn];
vector <int> ans[2];

inline void add_edge(int x, int y, int id) {
	e[++top].to = y;
	e[top].id = id;
	e[top].next = head[x], head[x] = top;
}

void dfs(int s) {
	visit[s] = 1;
	for (int j = head[s]; j != -1; j = e[j].next) {
		if (!visit[e[j].to]) {
			dfs(e[j].to);
		}
	}
}

void DFS(int s, int ii) {
	visit[s] = 1;
	for (int j = head[s]; j != -1; j = e[j].next) {
		if (!flag[e[j].id]) {
			flag[e[j].id] = 1;
			DFS(e[j].to, ii);
			ans[ii].push_back(e[j].id);
		}
	}
}

void output() {
	if (ans[0].size() + ans[1].size() != m) {
		puts("-1");
	}
	else {
		if (ans[0].size() == m) {
			printf("1\n%d\n", ans[0][0]);
			printf("%d\n", m - 1);
			for (int i = 1; i < m; i++) {
				printf("%d ", ans[0][i]);
			}
			puts("");
		}
		else {
			printf("%d\n", ans[0].size());
			for (int i = 0; i < ans[0].size(); i++) {
				printf("%d ", ans[0][i]);
			}
			puts("");
			printf("%d\n", ans[1].size());
			for (int i = 0; i < ans[1].size(); i++) {
				printf("%d ", ans[1][i]);
			}
			puts("");
		}
	}
}

void solve() {
	n = 0, top = -1;
	memset(head, -1, sizeof (head));
	memset(deg, 0, sizeof (deg));

	map <int, int> mp;
	map <int, int> ::iterator p;

	for (int i = 0; i < m; i++) {
		int x, y, u, v;
		scanf("%d%d", &x, &y);

		p = mp.find(x);
		if (p == mp.end()) {
			mp.insert(make_pair(x, n));
			u = n++;
		}
		else u = p->second;

		p = mp.find(y);
		if (p == mp.end()) {
			mp.insert(make_pair(y, n));
			v = n++;
		}
		else v = p->second;
		add_edge(u, v, i + 1);
		add_edge(v, u, i + 1);
		++deg[u], ++deg[v];
	}
	if (m < 2) {
		puts("-1");
		return;
	}
	int cnt = 0;
	memset(visit, 0, sizeof (visit));
	for (int i = 0; i < n; i++) {
		if (!visit[i]) {
			if (++cnt > 2) {
				puts("-1");
				return;
			}
			dfs(i);
		}
	}

	memset(visit, 0, sizeof (visit));
	memset(flag, 0, sizeof (flag));
	ans[0].clear();
	ans[1].clear();

	if (cnt == 1) {
		int xcnt = 0;
		for (int i = 0; i < n; i++) {
			if (deg[i] % 2) {
				++xcnt;
			}
		}
		if (xcnt == 0) {
			DFS(0, 0);
		}
		else if (xcnt == 2) {
			for (int i = 0; i < n; i++) {
				if (deg[i] % 2) {
					DFS(i, 0);
					break;
				}
			}
		}
		else {
			int x1 = -1, x2 = -1;
			for (int i = 0; i < n; i++) {
				if (deg[i] % 2) {
					if (x1 == -1) {
						x1 = i;
					}
					else if (x2 == -1) {
						x2 = i;
					}
					else break;
				}
			}
			add_edge(x1, x2, m + 1);
			add_edge(x2, x1, m + 1);
			for (int i = 0; i < n; i++) {
				if (deg[i] % 2 == 1 && i != x1 && i != x2) {
					DFS(i, 0);
					break;
				}
			}
			if (ans[0].size() != m + 1) {
				puts("-1");
				return;
			}
			vector <int> temp;
			for (int i = 0; i < ans[0].size(); i++) {
				if (ans[0][i] == m + 1) {
					for (int j = 0; j < i; j++) {
						temp.push_back(ans[0][j]);
					}
					for (int j = i + 1; j < ans[0].size(); j++) {
						ans[1].push_back(ans[0][j]);
					}
					break;
				}
			}
			ans[0].clear();
			for (int i = 0; i < temp.size(); i++) {
				ans[0].push_back(temp[i]);
			}
		}
	}
	else {
		int xcnt = 0;
		for (int i = 0; i < n; i++) {
			if (deg[i] % 2 && !visit[i]) {
				if (++xcnt > 2) {
					puts("-1");
					return;
				}
				DFS(i, xcnt - 1);
			}
		}
		if (xcnt == 0) {
			int ycnt = 0;
			for (int i = 0; i < n; i++) {
				if (!visit[i]) {
					if (++ycnt > 2) {
						puts("-1");
						return;
					}
					DFS(i, ycnt - 1);
				}
			}
		}
		else if (xcnt == 1) {
			for (int i = 0; i < n; i++) {
				if (!visit[i]) {
					DFS(i, 1);
					break;
				}
			}
		}
	}
	output();
}

int main() {
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	while (scanf("%d", &m) != EOF) {
		//scanf("%d", &m);
		solve();
	}
	return 0;
}


#include <cstdio>
#include <map>
#include <vector>
#include <cstring>
#define maxn 10002

using namespace std;

struct edge {
    int to, id, next;
} e[2 * maxn];

int n, m, top, head[maxn], deg[maxn], visit[maxn], flag[maxn];
vector <int> ans[2];

inline void add_edge(int x, int y, int id) {
    e[++top].to = y;
    e[top].id = id;
    e[top].next = head[x], head[x] = top;
}

void DFS(int s, int ii) {
    visit[s] = 1;
    for (int j = head[s]; j != -1; j = e[j].next) {
        if (!flag[e[j].id]) {
            flag[e[j].id] = 1;
            flag[e[j^1].id] = 1;
            DFS(e[j].to, ii);
            ans[ii].push_back(e[j].id);
        }
    }
}

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

void solve() {
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if (deg[i] % 2)++cnt;
    }
    if (cnt > 4) {
        puts("-1");
        return;
    }

    ans[0].clear();
    ans[1].clear();
    memset(visit, 0, sizeof (visit));
    memset(flag, 0, sizeof (flag));

    if (cnt == 0) {
        DFS(0, 0);
        for (int i = 1; i < n; i++) {
            if (!visit[i]) {
                DFS(i, 1);
                break;
            }
        }
    }
    else {
        cnt = 0;
        for (int i = 0; i < n; i++) {
            if (deg[i] % 2 == 1 && !visit[i]) {
                if (++cnt > 2)break;
                DFS(i, cnt - 1);
            }
        }
        if (cnt == 1) {
            for (int i = 0; i < n; i++) {
                if (!visit[i]) {
                    DFS(i, 1);
                    break;
                }
            }
        }
    }
    output();
}

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    while (scanf("%d", &m) != EOF) {
        n = 0, top = -1;
        map <int, int> mp;
        map <int, int> ::iterator p;
        memset(head, -1, sizeof (head));
        memset(deg, 0, sizeof (deg));
        for (int i = 0; i < m; i++) {
            int x, y;
            scanf("%d%d", &x, &y);
            p = mp.find(x);
            if (p == mp.end()) {
                mp.insert(make_pair(x, n));
                x = n++;
            }
            else x = p->second;

            p = mp.find(y);
            if (p == mp.end()) {
                mp.insert(make_pair(y, n));
                y = n++;
            }
            else y = p->second;
            add_edge(x, y, i + 1);
            add_edge(y, x, i + 1);
            ++deg[x], ++deg[y];
        }
        if (m < 2)
            puts("-1");
        else
            solve();
    }
    return 0;
}


#include <cstdio>
#include <vector>
#include <cstring>
#include <map>
#define maxn 10010

using namespace std;

struct edge {
    int to, id, next;
} e[2 * maxn];

int n, m, head[maxn], top, deg[maxn], od;
bool visit[maxn], flag[maxn];
vector <int> ans[2];

inline void add_edge(int x, int y, int id) {
    e[++top].to = y;
    e[top].id = id;
    e[top].next = head[x], head[x] = top;
}

void dfs(int s) {
    visit[s] = 1;
    if (deg[s] % 2)++od;
    for (int j = head[s]; j != -1; j = e[j].next) {
        if (!visit[e[j].to]) {
            dfs(e[j].to);
        }
    }
}

void DFS(int s, int ii) {
    visit[s] = 1;
    for (int j = head[s]; j != -1; j = e[j].next) {
        if (!flag[e[j].id]) {
            flag[e[j].id] = 1;
            DFS(e[j].to, ii);
            ans[ii].push_back(e[j].id);
        }
    }
}

void output() {
    if (ans[0].size() + ans[1].size() != m) {
        puts("-1");
    }
    else {
        if (ans[0].size() == m) {
            printf("1\n%d\n", ans[0][0]);
            printf("%d\n", m - 1);
            for (int i = 1; i < m; i++) {
                printf("%d ", ans[0][i]);
            }
            puts("");
        }
        else {
            printf("%d\n", ans[0].size());
            for (int i = 0; i < ans[0].size(); i++) {
                printf("%d ", ans[0][i]);
            }
            puts("");
            printf("%d\n", ans[1].size());
            for (int i = 0; i < ans[1].size(); i++) {
                printf("%d ", ans[1][i]);
            }
            puts("");
        }
    }
}

void solve() {
    n = 0, top = -1;
    memset(head, -1, sizeof (head));
    memset(deg, 0, sizeof (deg));

    map <int, int> mp;
    map <int, int> ::iterator p;

    for (int i = 0; i < m; i++) {
        int x, y, u, v;
        scanf("%d%d", &x, &y);

        p = mp.find(x);
        if (p == mp.end()) {
            mp.insert(make_pair(x, n));
            u = n++;
        }
        else u = p->second;

        p = mp.find(y);
        if (p == mp.end()) {
            mp.insert(make_pair(y, n));
            v = n++;
        }
        else v = p->second;
        add_edge(u, v, i + 1);
        add_edge(v, u, i + 1);
        ++deg[u], ++deg[v];
    }
    if (m < 2) {
        puts("-1");
        return;
    }
    int cnt = 0;
    memset(visit, 0, sizeof (visit));
    for (int i = 0; i < n; i++) {
        if (!visit[i]) {
            if (++cnt > 2) {
                puts("-1");
                return;
            }
            dfs(i);
        }
    }

    ans[0].clear(), ans[1].clear();
    memset(visit, 0, sizeof (visit));
    memset(flag, 0, sizeof (flag));
    if (cnt == 1) {
        int xcnt = 0;
        for (int i = 0; i < n; i++) {
            if (deg[i] % 2) {
                ++xcnt;
            }
        }
        if (xcnt == 0) {
            DFS(0, 0);
        }
        else if (xcnt == 2) {
            for (int i = 0; i < n; i++) {
                if (deg[i] % 2) {
                    DFS(i, 0);
                    break;
                }
            }
        }
        else {
            int x1 = -1, x2 = -1;
            for (int i = 0; i < n; i++) {
                if (deg[i] % 2) {
                    if (x1 == -1) {
                        x1 = i;
                    }
                    else if (x2 == -1) {
                        x2 = i;
                    }
                    else break;
                }
            }
            add_edge(x1, x2, m + 1);
            add_edge(x2, x1, m + 1);
            for (int i = 0; i < n; i++) {
                if (deg[i] % 2 == 1 && i != x1 && i != x2) {
                    DFS(i, 0);
                    break;
                }
            }
            if (ans[0].size() != m + 1) {
                puts("-1");
                return;
            }
            int i = 0;
            for (; i < ans[0].size(); i++) {
                if (ans[0][i] == m + 1) {
                    for (int j = i + 1; j < ans[0].size(); j++) {
                        ans[1].push_back(ans[0][j]);
                    }
                    break;
                }
            }
            ans[0].erase(ans[0].begin() + i, ans[0].end());
        }
    }
    else {
        int xcnt = 0;
        for (int i = 0; i < n; i++) {
            if (deg[i] % 2 && !visit[i]) {
                if (++xcnt > 2) {
                    puts("-1");
                    return;
                }
                DFS(i, xcnt - 1);
            }
        }
        if (xcnt != 2) {
            for (int i = 0; i < n; i++) {
                if (!visit[i]) {
                    DFS(i, 1);
                    break;
                }
            }
        }
        if (xcnt == 0) {
            for (int i = 0; i < n; i++) {
                if (!visit[i]) {
                    DFS(i, 0);
                    break;
                }
            }
        }
    }
    output();
}

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    while (scanf("%d", &m) != EOF) {
        solve();
    }
    return 0;
}


#include <cstdio>
#include <vector>
#include <cstring>
#include <map>
#define maxn 10010

using namespace std;

struct edge {
    int to, id, next;
} e[2 * maxn];

int n, m, head[maxn], top, deg[maxn];
bool visit[maxn], flag[maxn];
vector <int> ans[2];

inline void add_edge(int x, int y, int id) {
    e[++top].to = y;
    e[top].id = id;
    e[top].next = head[x], head[x] = top;
}

void dfs(int s) {
    visit[s] = 1;
    for (int j = head[s]; j != -1; j = e[j].next) {
        if (!visit[e[j].to]) {
            dfs(e[j].to);
        }
    }
}

void DFS(int s, int ii) {
    visit[s] = 1;
    for (int j = head[s]; j != -1; j = e[j].next) {
        if (!flag[e[j].id]) {
            flag[e[j].id] = 1;
            DFS(e[j].to, ii);
            ans[ii].push_back(e[j].id);
        }
    }
}

void output() {
    if (ans[0].size() + ans[1].size() != m) {
        puts("-1");
    }
    else {
        if (ans[0].size() == m) {
            printf("1\n%d\n", ans[0][0]);
            printf("%d\n", m - 1);
            for (int i = 1; i < m; i++) {
                printf("%d ", ans[0][i]);
            }
            puts("");
        }
        else {
            printf("%d\n", ans[0].size());
            for (int i = 0; i < ans[0].size(); i++) {
                printf("%d ", ans[0][i]);
            }
            puts("");
            printf("%d\n", ans[1].size());
            for (int i = 0; i < ans[1].size(); i++) {
                printf("%d ", ans[1][i]);
            }
            puts("");
        }
    }
}

void solve() {
    n = 0, top = -1;
    memset(head, -1, sizeof (head));
    memset(deg, 0, sizeof (deg));
    ans[0].clear(), ans[1].clear();

    map <int, int> mp;
    map <int, int> ::iterator p;

    for (int i = 0; i < m; i++) {
        int x, y, u, v;
        scanf("%d%d", &x, &y);

        p = mp.find(x);
        if (p == mp.end()) {
            mp.insert(make_pair(x, n));
            u = n++;
        }
        else u = p->second;

        p = mp.find(y);
        if (p == mp.end()) {
            mp.insert(make_pair(y, n));
            v = n++;
        }
        else v = p->second;
        add_edge(u, v, i + 1);
        add_edge(v, u, i + 1);
        ++deg[u], ++deg[v];
    }
    if (m < 2) {
        puts("-1");
        return;
    }
    int cnt = 0;
    memset(visit, 0, sizeof (visit));
    for (int i = 0; i < n; i++) {
        if (!visit[i]) {
            dfs(i);
            ++cnt;
        }
    }
    if (cnt > 2) {
        puts("-1");
        return;
    }
    memset(visit, 0, sizeof (visit));
    memset(flag, 0, sizeof (flag));
    if (cnt == 1) {
        int xcnt = 0, x1 = -1, x2 = -1;
        for (int i = 0; i < n; i++) {
            if (deg[i] % 2) {
                ++xcnt;
                if (x1 == -1) {
                    x1 = i;
                }
                else if (x2 == -1) {
                    x2 = i;
                }
            }
        }
        if (xcnt != 0) {
            if (xcnt == 2) {
                DFS(x1, 0);
            }
            else {
                add_edge(x1, x2, m);
                add_edge(x2, x1, m);
                for (int i = 0; i < n; i++) {
                    if (deg[i] % 2) {
                        DFS(i, 0);
                        break;
                    }
                }
                if (ans[0].size() != m + 1) {
                    puts("-1");
                    return;
                }
                vector <int> temp;
                for (int i = 0; i < ans[0].size(); i++) {
                    if (ans[0][i] == m) {
                        for (int j = 0; j < i; j++) {
                            temp.push_back(ans[0][j]);
                        }
                        for (int j = i + 1; j < ans[0].size(); j++) {
                            ans[1].push_back(ans[0][j]);
                        }
                        break;
                    }
                }
                ans[0].clear();
                for (int i = 0; i < temp.size(); i++) {
                    ans[0].push_back(temp[i]);
                }
            }
        }
        else {
            DFS(0, 0);
        }
    }
    else {
        int xcnt = 0;
        for (int i = 0; i < n; i++) {
            if (deg[i] % 2 && !visit[i]) {
                if (++xcnt > 2)break;
                DFS(i, xcnt - 1);
            }
        }
        for (int i = 0; i < n; i++) {
            if (!visit[i]) {
                if (++xcnt > 2)break;
                DFS(i, xcnt - 1);
            }
        }
        if (xcnt > 2) {
            puts("-1");
            return;
        }
    }
    output();
}

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    while (scanf("%d", &m) != EOF) {
        solve();
    }
    return 0;
}


#include <cstdio>
#include <vector>
#include <cstring>
#include <map>
#define maxn 10010

using namespace std;

struct edge {
    int to, id, next;
} e[2 * maxn];

int n, m, head[maxn], top, deg[maxn], odd;
bool visit[maxn], flag[maxn];
vector <int> ans[2];

inline void add_edge(int x, int y, int id) {
    e[++top].to = y;
    e[top].id = id;
    e[top].next = head[x], head[x] = top;
}

void dfs(int s) {
    visit[s] = 1;
    if (deg[s] % 2)odd++;
    for (int j = head[s]; j != -1; j = e[j].next) {
        if (!visit[e[j].to]) {
            dfs(e[j].to);
        }
    }
}

void DFS(int s, int ii) {
    visit[s] = 1;
    for (int j = head[s]; j != -1; j = e[j].next) {
        if (!flag[e[j].id]) {
            flag[e[j].id] = 1;
            DFS(e[j].to, ii);
            ans[ii].push_back(e[j].id);
        }
    }
}

void output() {
    if (ans[0].size() + ans[1].size() != m) {
        puts("-1");
    }
    else {
        if (ans[0].size() == m) {
            printf("1\n%d\n%d\n", ans[0][0], m - 1);
            for (int i = 1; i < m; i++) {
                printf("%d ", ans[0][i]);
            }
            puts("");
        }
        else {
            printf("%d\n", ans[0].size());
            for (int i = 0; i < ans[0].size(); i++) {
                printf("%d ", ans[0][i]);
            }
            puts("");
            printf("%d\n", ans[1].size());
            for (int i = 0; i < ans[1].size(); i++) {
                printf("%d ", ans[1][i]);
            }
            puts("");
        }
    }
}

void solve() {
    n = 0, top = -1;
    memset(head, -1, sizeof (head));
    memset(deg, 0, sizeof (deg));

    map <int, int> mp;
    map <int, int> ::iterator p;

    for (int i = 0; i < m; i++) {
        int x, y, u, v;
        scanf("%d%d", &x, &y);

        p = mp.find(x);
        if (p == mp.end()) {
            mp.insert(make_pair(x, n));
            u = n++;
        }
        else u = p->second;

        p = mp.find(y);
        if (p == mp.end()) {
            mp.insert(make_pair(y, n));
            v = n++;
        }
        else v = p->second;
        add_edge(u, v, i + 1);
        add_edge(v, u, i + 1);
        ++deg[u], ++deg[v];
    }
    if (m < 2) {
        puts("-1");
        return;
    }
    int cnt = 0;
    memset(visit, 0, sizeof (visit));
    for (int i = 0; i < n; i++) {
        if (!visit[i]) {
            if (++cnt > 2) {
                puts("-1");
                return;
            }
            dfs(i);
        }
    }

    memset(flag, 0, sizeof (flag));
    ans[0].clear();
    ans[1].clear();

    if (cnt == 1) {
        int xcnt = 0;
        for (int i = 0; i < n; i++) {
            if (deg[i] % 2) {
                ++xcnt;
            }
        }
        if (xcnt == 0) {
            DFS(0, 0);
        }
        else if (xcnt == 2) {
            for (int i = 0; i < n; i++) {
                if (deg[i] % 2) {
                    DFS(i, 0);
                    break;
                }
            }
        }
        else if (xcnt == 4) {
            int x1 = -1, x2 = -1;
            for (int i = 0; i < n; i++) {
                if (deg[i] % 2) {
                    if (x1 == -1) {
                        x1 = i;
                    }
                    else if (x2 == -1) {
                        x2 = i;
                        break;
                    }
                }
            }
            add_edge(x1, x2, m + 1);
            add_edge(x2, x1, m + 1);
            ++deg[x1], ++deg[x2];
            for (int i = 0; i < n; i++) {
                if (deg[i] % 2) {
                    DFS(i, 0);
                    break;
                }
            }
            if (ans[0].size() != m + 1) {
                puts("-1");
                return;
            }
            int i = 0;
            for (; i < ans[0].size(); i++) {
                if (ans[0][i] == m + 1) {
                    for (int j = i + 1; j < ans[0].size(); j++) {
                        ans[1].push_back(ans[0][j]);
                    }
                    break;
                }
            }
            ans[0].erase(ans[0].begin() + i, ans[0].end());
        }
        else {
            puts("-1");
            return;
        }
    }
    else {
        memset(visit, 0, sizeof (visit));
        vector <int> oods;
        for (int i = 0; i < n; i++) {
            if (!visit[i]) {
                odd = 0;
                dfs(i);
                oods.push_back(odd);
            }
        }
        memset(visit, 0, sizeof (visit));
        if (oods[0] > 2 || oods[1] > 2) {
            puts("-1");
            return;
        }
        int required = oods[0] == 2 + oods[1] == 2, xcnt = 0;
        for (int i = 0; i < n; i++) {
            if (!visit[i]) {
                if (!required || deg[i] % 2) {
                    if (++xcnt > 2) {
                        puts("-1");
                        return;
                    }
                    if (required)--required;
                    DFS(i, xcnt - 1);
                }
            }
        }
    }
    output();
}

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    while (scanf("%d", &m) != EOF) {
        solve();
    }
    return 0;
}


#include <cstdio>
#include <vector>
#include <cstring>
#include <map>
#define maxn 10010

using namespace std;

struct edge {
    int to, id, next;
} e[2 * maxn];

int n, m, head[maxn], top, deg[maxn], odd;
bool visit[maxn], flag[maxn];
vector <int> ans[2];

inline void add_edge(int x, int y, int id) {
    e[++top].to = y;
    e[top].id = id;
    e[top].next = head[x], head[x] = top;
}

void dfs(int s) {
    visit[s] = 1;
    if (deg[s] % 2)odd++;
    for (int j = head[s]; j != -1; j = e[j].next) {
        if (!visit[e[j].to]) {
            dfs(e[j].to);
        }
    }
}

void DFS(int s, int ii) {
    visit[s] = 1;
    for (int j = head[s]; j != -1; j = e[j].next) {
        if (!flag[e[j].id]) {
            flag[e[j].id] = 1;
            DFS(e[j].to, ii);
            ans[ii].push_back(e[j].id);
        }
    }
}

void output() {
    if (ans[0].size() + ans[1].size() != m) {
        puts("-1");
    }
    else {
        if (ans[0].size() == m) {
            printf("1\n%d\n%d\n", ans[0][0], m - 1);
            for (int i = 1; i < m; i++) {
                printf("%d ", ans[0][i]);
            }
            puts("");
        }
        else {
            printf("%d\n", ans[0].size());
            for (int i = 0; i < ans[0].size(); i++) {
                printf("%d ", ans[0][i]);
            }
            puts("");
            printf("%d\n", ans[1].size());
            for (int i = 0; i < ans[1].size(); i++) {
                printf("%d ", ans[1][i]);
            }
            puts("");
        }
    }
}

void solve() {
    n = 0, top = -1;
    memset(head, -1, sizeof (head));
    memset(deg, 0, sizeof (deg));

    map <int, int> mp;
    map <int, int> ::iterator p;

    for (int i = 0; i < m; i++) {
        int x, y, u, v;
        scanf("%d%d", &x, &y);

        p = mp.find(x);
        if (p == mp.end()) {
            mp.insert(make_pair(x, n));
            u = n++;
        }
        else u = p->second;

        p = mp.find(y);
        if (p == mp.end()) {
            mp.insert(make_pair(y, n));
            v = n++;
        }
        else v = p->second;
        add_edge(u, v, i + 1);
        add_edge(v, u, i + 1);
        ++deg[u], ++deg[v];
    }
    if (m < 2) {
        puts("-1");
        return;
    }
    int cnt = 0;
    memset(visit, 0, sizeof (visit));
    for (int i = 0; i < n; i++) {
        if (!visit[i]) {
            if (++cnt > 2) {
                puts("-1");
                return;
            }
            dfs(i);
        }
    }

    memset(flag, 0, sizeof (flag));
    ans[0].clear();
    ans[1].clear();

    if (cnt == 1) {
        int xcnt = 0;
        for (int i = 0; i < n; i++) {
            if (deg[i] % 2) {
                ++xcnt;
            }
        }
        if (xcnt == 0) {
            DFS(0, 0);
        }
        else if (xcnt == 2) {
            for (int i = 0; i < n; i++) {
                if (deg[i] % 2) {
                    DFS(i, 0);
                    break;
                }
            }
        }
        else if (xcnt == 4) {
            int x1 = -1, x2 = -1;
            for (int i = 0; i < n; i++) {
                if (deg[i] % 2) {
                    if (x1 == -1) {
                        x1 = i;
                    }
                    else if (x2 == -1) {
                        x2 = i;
                        break;
                    }
                }
            }
            add_edge(x1, x2, m + 1);
            add_edge(x2, x1, m + 1);
            ++deg[x1], ++deg[x2];
            for (int i = 0; i < n; i++) {
                if (deg[i] % 2) {
                    DFS(i, 0);
                    break;
                }
            }
            if (ans[0].size() != m + 1) {
                puts("-1");
                return;
            }
            int i = 0;
            for (; i < ans[0].size(); i++) {
                if (ans[0][i] == m + 1) {
                    for (int j = i + 1; j < ans[0].size(); j++) {
                        ans[1].push_back(ans[0][j]);
                    }
                    break;
                }
            }
            ans[0].erase(ans[0].begin() + i, ans[0].end());
        }
        else {
            puts("-1");
            return;
        }
    }
    else {
        memset(visit, 0, sizeof (visit));
        vector <int> oods;
        for (int i = 0; i < n; i++) {
            if (!visit[i]) {
                odd = 0;
                dfs(i);
                oods.push_back(odd);
            }
        }
        memset(visit, 0, sizeof (visit));
        if (oods[0] > 2 || oods[1] > 2) {
            puts("-1");
            return;
        }
        int required = oods[0] == 2 + oods[1] == 2, xcnt = 0;
        for (int i = 0; i < n; i++) {
            if (!visit[i]) {
                if (!required || deg[i] % 2) {
                    if (++xcnt > 2) {
                        puts("-1");
                        return;
                    }
                    DFS(i, xcnt - 1);
                }
            }
        }
    }
    output();
}

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    while (scanf("%d", &m) != EOF) {
        //scanf("%d", &m);
        solve();
    }
    return 0;
}


#include <cstdio>
#include <map>
#include <vector>
#include <cstring>
#define maxn 10002

using namespace std;

struct edge {
    int to, id, next;
} e[2 * maxn];

int n, m, top, head[maxn], deg[maxn], visit[maxn], flag[maxn];
vector <int> ans[2];

inline void add_edge(int x, int y, int id) {
    e[++top].to = y;
    e[top].id = id;
    e[top].next = head[x], head[x] = top;
}

void DFS(int s, int ii) {
    visit[s] = 1;
    for (int j = head[s]; j != -1; j = e[j].next) {
        if (!flag[e[j].id]) {
            flag[e[j].id] = 1;
            flag[e[j^1].id] = 1;
            DFS(e[j].to, ii);
            ans[ii].push_back(e[j].id);
        }
    }
}

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

void solve() {
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if (deg[i] % 2)++cnt;
    }
    if (cnt > 4) {
        puts("-1");
        return;
    }

    ans[0].clear();
    ans[1].clear();
    memset(visit, 0, sizeof (visit));
    memset(flag, 0, sizeof (flag));

    if (cnt == 0) {
        DFS(0, 0);
        for (int i = 1; i < n; i++) {
            if (!visit[i]) {
                DFS(i, 1);
                break;
            }
        }
    }
    else {
        cnt = 0;
        for (int i = 0; i < n; i++) {
            if (deg[i] % 2 == 1 && !visit[i]) {
                if (++cnt > 2)break;
                DFS(i, cnt - 1);
            }
        }
        if (cnt == 1) {
            for (int i = 0; i < n; i++) {
                if (!visit[i]) {
                    DFS(i, 1);
                    break;
                }
            }
        }
    }
    output();
}

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    while (scanf("%d", &m) != EOF) {
        n = 0, top = -1;
        map <int, int> mp;
        map <int, int> ::iterator p;
        memset(head, -1, sizeof (head));
        memset(deg, 0, sizeof (deg));
        for (int x, y, i = 0; i < m; i++) {
            scanf("%d%d", &x, &y);
            p = mp.find(x);
            if (p == mp.end()) {
                mp.insert(make_pair(x, n));
                x = n++;
            }
            else x = p->second;

            p = mp.find(y);
            if (p == mp.end()) {
                mp.insert(make_pair(y, n));
                y = n++;
            }
            else y = p->second;
            add_edge(x, y, i + 1);
            add_edge(y, x, i + 1);
            ++deg[x], ++deg[y];
        }
        if (m < 2) {
            puts("-1");
        }
        else {
            solve();
        }
    }
    return 0;
}


#include <cstdio>
#include <vector>
#include <cstring>
#include <map>
#define maxn 10010

using namespace std;

struct edge {
	int to, id, next;
} e[2 * maxn];

int n, m, head[maxn], top, deg[maxn];
bool visit[maxn], flag[maxn];
vector <int> ans[2];

inline void add_edge(int x, int y, int id) {
	e[++top].to = y;
	e[top].id = id;
	e[top].next = head[x], head[x] = top;
}

void dfs(int s) {
	visit[s] = 1;
	for (int j = head[s]; j != -1; j = e[j].next) {
		if (!visit[e[j].to]) {
			dfs(e[j].to);
		}
	}
}

void DFS(int s, int ii) {
	visit[s] = 1;
	for (int j = head[s]; j != -1; j = e[j].next) {
		if (!flag[e[j].id]) {
			flag[e[j].id] = 1;
			DFS(e[j].to, ii);
			ans[ii].push_back(e[j].id);
		}
	}
}

void output() {
	if (ans[0].size() + ans[1].size() != m) {
		puts("-1");
	}
	else {
		if (ans[0].size() == m) {
			printf("1\n%d\n", ans[0][0]);
			printf("%d\n", m - 1);
			for (int i = 1; i < m; i++) {
				printf("%d ", ans[0][i]);
			}
			puts("");
		}
		else {
			printf("%d\n", ans[0].size());
			for (int i = 0; i < ans[0].size(); i++) {
				printf("%d ", ans[0][i]);
			}
			puts("");
			printf("%d\n", ans[1].size());
			for (int i = 0; i < ans[1].size(); i++) {
				printf("%d ", ans[1][i]);
			}
			puts("");
		}
	}
}

void solve() {
	n = 0, top = -1;
	memset(head, -1, sizeof (head));
	memset(deg, 0, sizeof (deg));

	map <int, int> mp;
	map <int, int> ::iterator p;

	for (int i = 0; i < m; i++) {
		int x, y, u, v;
		scanf("%d%d", &x, &y);

		p = mp.find(x);
		if (p == mp.end()) {
			mp.insert(make_pair(x, n));
			u = n++;
		}
		else u = p->second;

		p = mp.find(y);
		if (p == mp.end()) {
			mp.insert(make_pair(y, n));
			v = n++;
		}
		else v = p->second;
		add_edge(u, v, i + 1);
		add_edge(v, u, i + 1);
		++deg[u], ++deg[v];
	}
	if (m < 2) {
		puts("-1");
		return;
	}
	int cnt = 0;
	memset(visit, 0, sizeof (visit));
	for (int i = 0; i < n; i++) {
		if (!visit[i]) {
			if (++cnt > 2) {
				puts("-1");
				return;
			}
			dfs(i);
		}
	}

	memset(visit, 0, sizeof (visit));
	memset(flag, 0, sizeof (flag));
	ans[0].clear();
	ans[1].clear();

	if (cnt == 1) {
		int xcnt = 0;
		for (int i = 0; i < n; i++) {
			if (deg[i] % 2) {
				++xcnt;
			}
		}
		if (xcnt == 0) {
			DFS(0, 0);
		}
		else if (xcnt == 2) {
			for (int i = 0; i < n; i++) {
				if (deg[i] % 2) {
					DFS(i, 0);
					break;
				}
			}
		}
		else {
			int x1 = -1, x2 = -1;
			for (int i = 0; i < n; i++) {
				if (deg[i] % 2) {
					if (x1 == -1) {
						x1 = i;
					}
					else if (x2 == -1) {
						x2 = i;
					}
					else break;
				}
			}
			add_edge(x1, x2, m + 1);
			add_edge(x2, x1, m + 1);
			for (int i = 0; i < n; i++) {
				if (deg[i] % 2 == 1 && i != x1 && i != x2) {
					DFS(i, 0);
					break;
				}
			}
			if (ans[0].size() != m + 1) {
				puts("-1");
				return;
			}
			vector <int> temp;
			for (int i = 0; i < ans[0].size(); i++) {
				if (ans[0][i] == m + 1) {
					for (int j = 0; j < i; j++) {
						temp.push_back(ans[0][j]);
					}
					for (int j = i + 1; j < ans[0].size(); j++) {
						ans[1].push_back(ans[0][j]);
					}
					break;
				}
			}
			ans[0].clear();
			for (int i = 0; i < temp.size(); i++) {
				ans[0].push_back(temp[i]);
			}
		}
	}
	else {
		int xcnt = 0;
		for (int i = 0; i < n; i++) {
			if (deg[i] % 2 && !visit[i]) {
				if (++xcnt > 2) {
					puts("-1");
					return;
				}
				DFS(i, xcnt - 1);
			}
		}
		if (xcnt != 2) {
			for (int i = 0; i < n; i++) {
				if (!visit[i]) {
					DFS(i, 1);
					break;
				}
			}
		}
		if (xcnt == 0) {
			for (int i = 0; i < n; i++) {
				if (!visit[i]) {
					DFS(i, 0);
					break;
				}
			}
		}
	}
	output();
}

int main() {
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	//while (scanf("%d", &m) != EOF) {
	scanf("%d", &m);
	solve();
	//}
	return 0;
}