import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class B {

	public static long gcd(long x, long y){
		if(x == 0){
			return y;
		}else{
			return gcd(y % x, x);
		}
	}

	public static void main(String[] args) throws IOException{
		Scanner sc = new Scanner(System.in);

		String input = sc.next();

		int[] map = new int[input.length()];
		for(int i = 0; i < input.length(); i++){
			map[i] = input.charAt(i) == '.' ? 1 : 0;
		}

		int[] sums = new int[map.length];

		int prev = -1;
		int count = 0;
		int sum = 0;
		for(int j = 0; j < map.length; j++){
			if(prev == -1){
				prev = map[j];
				count = 1;
			}else if(prev == map[j]){
				sum++;
				count++;
			}else {
				//System.out.println(" " + count);
				count = 1;
				prev = map[j];
			}

			sums[j] = sum;
		}

		//System.out.println(Arrays.toString(sums));

		final int m = sc.nextInt();

		for(int i = 0; i < m; i++){
			final int l = sc.nextInt() - 1;
			final int r = sc.nextInt() - 1;

			System.out.println(sums[r] - sums[l]);
		}
	}

	public static class Scanner {

		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException{
			br = new BufferedReader(new InputStreamReader(is));
			getLine();
		}

		private void getLine() throws IOException{
			while(tok == null || !tok.hasMoreTokens()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext(){
			return tok.hasMoreTokens();
		}

		public String next() throws IOException{
			if(hasNext()){
				return tok.nextToken();
			}else{
				getLine();
				return tok.nextToken();
			}
		}

		public int nextInt() throws IOException{
			if(hasNext()){
				return Integer.parseInt(tok.nextToken());
			}else{
				getLine();
				return Integer.parseInt(tok.nextToken());
			}
		}

		public long nextLong() throws IOException{
			if(hasNext()){
				return Long.parseLong(tok.nextToken());
			}else{
				getLine();
				return Long.parseLong(tok.nextToken());
			}
		}

		public double nextDouble() throws IOException{
			if(hasNext()){
				return Double.parseDouble(tok.nextToken());
			}else{
				getLine();
				return Double.parseDouble(tok.nextToken());
			}
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class B {

	public static long gcd(long x, long y){
		if(x == 0){
			return y;
		}else{
			return gcd(y % x, x);
		}
	}

	public static void main(String[] args) throws IOException{
		Scanner sc = new Scanner(System.in);

		String input = sc.next();

		int[] map = new int[input.length()];
		for(int i = 0; i < input.length(); i++){
			map[i] = input.charAt(i) == '.' ? 1 : 0;
		}

		final int m = sc.nextInt();

		for(int i = 0; i < m; i++){
			final int l = sc.nextInt() - 1;
			final int r = sc.nextInt() - 1;

			int prev = -1;
			int count = 0;
			int max = 0;
			for(int j = l; j <= r; j++){
				if(prev == -1){
					prev = map[j];
					count = 0;
				}else if(prev == map[j]){
					count++;
				}else {
					max = Math.max(max, count);
					count = 0;
					prev = map[j];
				}
			}
			max = Math.max(max, count);

			System.out.println(max);
		}
	}

	public static class Scanner {

		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException{
			br = new BufferedReader(new InputStreamReader(is));
			getLine();
		}

		private void getLine() throws IOException{
			while(tok == null || !tok.hasMoreTokens()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext(){
			return tok.hasMoreTokens();
		}

		public String next() throws IOException{
			if(hasNext()){
				return tok.nextToken();
			}else{
				getLine();
				return tok.nextToken();
			}
		}

		public int nextInt() throws IOException{
			if(hasNext()){
				return Integer.parseInt(tok.nextToken());
			}else{
				getLine();
				return Integer.parseInt(tok.nextToken());
			}
		}

		public long nextLong() throws IOException{
			if(hasNext()){
				return Long.parseLong(tok.nextToken());
			}else{
				getLine();
				return Long.parseLong(tok.nextToken());
			}
		}

		public double nextDouble() throws IOException{
			if(hasNext()){
				return Double.parseDouble(tok.nextToken());
			}else{
				getLine();
				return Double.parseDouble(tok.nextToken());
			}
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class B {

	public static long gcd(long x, long y){
		if(x == 0){
			return y;
		}else{
			return gcd(y % x, x);
		}
	}

	public static void main(String[] args) throws IOException{
		Scanner sc = new Scanner(System.in);

		String input = sc.next();

		int[] map = new int[input.length()];
		for(int i = 0; i < input.length(); i++){
			map[i] = input.charAt(i) == '.' ? 1 : 0;
		}

		final int m = sc.nextInt();

		for(int i = 0; i < m; i++){
			final int l = sc.nextInt() - 1;
			final int r = sc.nextInt() - 1;

			int prev = -1;
			int count = 0;
			int max = 0;
			for(int j = l; j <= r; j++){
				if(prev == -1){
					prev = map[j];
					count = 1;
				}else if(prev == map[j]){
					count++;
				}else {
					//System.out.println(" " + count);
					max += (count - 1);
					count = 1;
					prev = map[j];
				}
			}
			max += (count - 1);

			System.out.println(max);
		}
	}

	public static class Scanner {

		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException{
			br = new BufferedReader(new InputStreamReader(is));
			getLine();
		}

		private void getLine() throws IOException{
			while(tok == null || !tok.hasMoreTokens()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext(){
			return tok.hasMoreTokens();
		}

		public String next() throws IOException{
			if(hasNext()){
				return tok.nextToken();
			}else{
				getLine();
				return tok.nextToken();
			}
		}

		public int nextInt() throws IOException{
			if(hasNext()){
				return Integer.parseInt(tok.nextToken());
			}else{
				getLine();
				return Integer.parseInt(tok.nextToken());
			}
		}

		public long nextLong() throws IOException{
			if(hasNext()){
				return Long.parseLong(tok.nextToken());
			}else{
				getLine();
				return Long.parseLong(tok.nextToken());
			}
		}

		public double nextDouble() throws IOException{
			if(hasNext()){
				return Double.parseDouble(tok.nextToken());
			}else{
				getLine();
				return Double.parseDouble(tok.nextToken());
			}
		}
	}
}


import java.util.Scanner;

public class B {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        String s = sc.nextLine();
        int m = s.length();
        int[] count = new int[m+5];
        for(int i = 1; i < m; i++){
            if (s.charAt(i) == s.charAt(i-1)){
                count[i] = 1;
                //System.out.println(i + " : " +count[i]);
            } else
                count[i] = 0;
            count[i] = count[i] + count[i-1];
        }

        int n = sc.nextInt();
        for(int i = 0; i < n; i++){
            int l = sc.nextInt();
            int r = sc.nextInt();
            int ans = count[r-1] - count[l];
            if (s.charAt(l) == s.charAt(l-1)) ans++;
            System.out.println(ans);
        }

        sc.close();
    }

}


import java.io.*;
import java.util.StringTokenizer;

import static java.lang.Integer.*;
import static java.lang.Math.*;
public class B {
	public static void main(String[] args) throws Throwable{
		BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
		char[] ln=in.readLine().trim().toCharArray();
		int[] arr=new int[ln.length];
		for(int i=0;i<arr.length-1;i++)arr[i]=ln[i]==ln[i+1]?1:0;
		for(int i=1;i<arr.length;i++)arr[i]+=arr[i-1];
		for(int M=parseInt(in.readLine().trim()),m=0;m++<M;) {
			StringTokenizer st=new StringTokenizer(in.readLine());
			int desde=parseInt(st.nextToken())-1,hasta=parseInt(st.nextToken())-1;
			System.out.println(arr[hasta-1]-(desde>0?arr[desde-1]:0));
		}
	}
}


import java.io.StreamTokenizer;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.PrintStream;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		TokenizerReader in = new TokenizerReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskB {
    public void solve(@SuppressWarnings("UnusedParameters") int testNumber, TokenizerReader in, PrintWriter out) {
        char[] s = in.nextString().toCharArray();
        int n = s.length;
        int m = in.nextInt();
        int[] cnt = new int[n];
        cnt[0] = 0;
        for (int i = 0; i < n-1; ++i) {
            if (s[i] == s[i+1])
                cnt[i+1] = cnt[i] + 1;
            else
                cnt[i+1] = cnt[i];
        }
        for (int i = 0; i < m; ++i) {
            int l = in.nextInt() - 1, r = in.nextInt() - 1;
            out.println(cnt[r] - cnt[l]);
        }
    }
}

class TokenizerReader extends StreamTokenizer {
    public TokenizerReader(InputStream in) {
        super(new BufferedReader(new InputStreamReader(in)));
        defaultConfig();
    }

    public String nextString() {
        try {
            nextToken();
        } catch (IOException e) {
            throw new RuntimeException("nextString: exception in line " + lineno(), e);
        }
        return sval;
    }

    public int nextInt() {
        return Integer.parseInt(nextString());
    }

    public void defaultConfig() {
        resetSyntax();
        wordChars(33, 126);
        whitespaceChars(0, ' ');
    }

    }


/**
 * TEAM: BROGRAMMERS
 */
import java.util.*;
import static java.lang.Math.*;
public class ProblemB {
    void run() {
        Scanner sc = new Scanner(System.in);
		char[] c = sc.next().toCharArray();
		int n = c.length;
		int m = sc.nextInt();
		int[] sum = new int[n+1];
		for (int i = 1; i < n; ++i) {
			sum[i] = sum[i-1];
			if (c[i-1] == c[i]) {
				++sum[i];
			}
		}
		d(sum);
		sum[n] = sum[n-1];
		for (int i = 0; i < m; ++i) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			p("%d\n", sum[r-1] - sum[l-1]);
		}
    }

    boolean debug = false;
    void p(String f, Object...params) {
        System.out.printf(f, params);
    }
    void d(Object...params) {
        if (debug) {
            p("DEBUG: %s\n", Arrays.deepToString(params));
        }
    }
    void die() {
        throw new RuntimeException();
    }
    void timeout() {
        for (int x = 0; ; ++x);
    }
    String join(Collection<?> s, String delimiter) {
        StringBuilder builder = new StringBuilder();
        Iterator<?> iter = s.iterator();
        while (iter.hasNext()) {
            builder.append(iter.next());
            if (iter.hasNext()) {
                builder.append(delimiter);
            }
        }
        return builder.toString();
    }
    public ProblemB(String[] args) {
        if (args.length > 0 && args[0].equals("debug")) {
            debug = true;
        }
    }
    public static void main(String[] args) {
        new ProblemB(args).run();
    }
}


import java.awt.Point;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.StringTokenizer;

public class B {

	public static void main(String[] Args) throws IOException {
		new B().solve();
	}

	int o = -INF;

	void solve() throws IOException {
		tok();
		String s = toks();
		int[] a = new int[s.length()];
		int c = 0;
		for (int i = 1; i < s.length(); i++) {
			if (s.charAt(i)==s.charAt(i-1)) c++;
			a[i] = c;
		}
		tok();
		int m = toki();
		PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
		for (int i = 0; i < m; i++) {
			tok();
			int l=toki()-1, r=toki()-1;
			out.println(a[r]-a[l]);
		}
		out.close();
	}

	// ----------------------- Library ------------------------
	void initSystem() throws IOException {
		if (br != null)
			br.close();
		br = new BufferedReader(new InputStreamReader(System.in));
	}

	void initFile() throws IOException {
		if (br != null)
			br.close();
		br = new BufferedReader(new InputStreamReader(new FileInputStream(
				"input.txt")));
	}

	void printWriter() {
		try {
			PrintWriter pr = new PrintWriter("output.txt");
			pr.println("hello world");
			pr.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	void comparator() {
		Point[] v = new Point[10];
		Arrays.sort(v, new Comparator<Point>() {
			@Override
			public int compare(Point a, Point b) {
				if (a.x != b.x)
					return -(a.x - b.x);
				return a.y - b.y;
			}
		});
	}

	double distance(Point a, Point b) {
		double dx = a.x - b.x, dy = a.y - b.y;
		return Math.sqrt(dx * dx + dy * dy);
	}

	Scanner in = new Scanner(System.in);

	String ss() {
		return in.next();
	}

	String sline() {
		return in.nextLine();
	}

	int si() {
		return in.nextInt();
	}

	int[] sai(int n) {
		int[] a = new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = in.nextInt();
		}
		return a;
	}

	int[] sai_(int n) {
		int[] a = new int[n + 1];
		for (int i = 1; i <= n; i++) {
			a[i] = in.nextInt();
		}
		return a;
	}

	BufferedReader br;
	StringTokenizer tokenizer;
	{
		br = new BufferedReader(new InputStreamReader(System.in));
	}

	void tok() throws IOException {
		tokenizer = new StringTokenizer(br.readLine());
	}

	int toki() throws IOException {

		return Integer.parseInt(tokenizer.nextToken());
	}

	int[] rint(int n) throws IOException {
		int[] a = new int[n];
		for (int i = 0; i < a.length; i++)
			a[i] = Integer.parseInt(tokenizer.nextToken());

		return a;
	}

	int[] rint_(int n) throws IOException {
		int[] a = new int[n + 1];
		for (int i = 1; i <= n; i++)
			a[i] = Integer.parseInt(tokenizer.nextToken());

		return a;
	}

	String[] rstrlines(int n) throws IOException {
		String[] a = new String[n];
		for (int i = 0; i < n; i++) {
			a[i] = br.readLine();
		}
		return a;
	}

	long tokl() {
		return Long.parseLong(tokenizer.nextToken());
	}

	double tokd() {
		return Double.parseDouble(tokenizer.nextToken());
	}

	String toks() {
		return tokenizer.nextToken();
	}

	String rline() throws IOException {
		return br.readLine();
	}

	List<Integer> toList(int[] a) {
		List<Integer> v = new ArrayList<Integer>();
		for (int i : a)
			v.add(i);
		return v;
	}

	static void pai(int[] a) {
		System.out.println(Arrays.toString(a));
	}

	static int toi(Object s) {
		return Integer.parseInt(s.toString());
	}

	static int[] dx_ = { 0, 0, 1, -1 };
	static int[] dy_ = { 1, -1, 0, 0 };

	static int[] dx3 = { 1, -1, 0, 0, 0, 0 };
	static int[] dy3 = { 0, 0, 1, -1, 0, 0 };
	static int[] dz3 = { 0, 0, 0, 0, 1, -1 };

	static int[] dx = { 1, 0, -1, 1, -1, 1, 0, -1 }, dy = { 1, 1, 1, 0, 0, -1,
			-1, -1 };

	static int INF = 2147483647; // =2^31-1 // -8
	static long LINF = 922337203854775807L; // -8
	static short SINF = 32767; // -32768

	// finds GCD of a and b using Euclidian algorithm
	public int GCD(int a, int b) {
		if (b == 0)
			return a;
		return GCD(b, a % b);
	}

	static List<String> toList(String[] a) {
		return Arrays.asList(a);
	}

	static String[] toArray(List<String> a) {
		String[] o = new String[a.size()];
		a.toArray(o);
		return o;
	}

	static int[] pair(int... a) {
		return a;
	}
}


/**
 * Created by nitin.s on 01/01/15.
 */
import java.util.*;
public class LLyaAndQueries {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.nextLine();
        int n = in.nextInt();
        int[] dp = new int[s.length() + 3];
        for(int i = 0; i < n+1; ++i )
            for(int j = 0; j < n+1; ++j)
                dp[i] = 0;
        dp[0] = 0;
        for(int i = 1; i < s.length(); ++i) {
            int t = 0;
            if(s.charAt(i) == s.charAt(i-1))
                t = 1;
            dp[i] = dp[i-1] + t;
        }
        for(int i = 0; i < n; ++i) {
            int l = in.nextInt();
            int r = in.nextInt();
            l = l - 1;
            r = r - 1;

            int ans = dp[r] - dp[l];

            System.out.println(ans);
        }
        in.close();
    }
}


/**
 * Created by nitin.s on 01/01/15.
 */
import java.util.*;
public class LLyaAndQueries {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.nextLine();
        int n = in.nextInt();
        int[] dp = new int[s.length() + 3];
        for(int i = 0; i < n+1; ++i )
            for(int j = 0; j < n+1; ++j)
                dp[i] = 0;
        dp[0] = 0;
        for(int i = 1; i < s.length(); ++i) {
            int t = 0;
            if(s.charAt(i) == s.charAt(i-1))
                t = 1;
            dp[i] = dp[i-1] + t;
        }
        for(int i = 0; i < n; ++i) {

            int ans = -dp[in.nextInt()-1] + dp[in.nextInt()-1];

            System.out.println(ans);
        }
        in.close();
    }
}


/**
 * Created by nitin.s on 01/01/15.
 */
import java.util.*;
public class LLyaAndQueries {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next();
        int n = in.nextInt();
        int[] dp = new int[s.length() + 3];

        dp[0] = 0;
        for(int i = 1; i < s.length(); ++i) {
            int t = 0;
            if(s.charAt(i) == s.charAt(i-1))
                t = 1;
            dp[i] = dp[i-1] + t;
        }
        for(int i = 0; i < n; ++i) {

            int ans = -dp[in.nextInt()-1] + dp[in.nextInt()-1];

            System.out.println(ans);
        }
        in.close();
    }
}


/**
 * Created by nitin.s on 01/01/15.
 */
import java.util.*;
public class LLyaAndQueries {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.nextLine();
        int n = in.nextInt();
        int[] dp = new int[n+3];
        for(int i = 0; i < n+1; ++i )
            for(int j = 0; j < n+1; ++j)
                dp[i] = 0;
        dp[0] = 0;
        for(int i = 1; i < s.length(); ++i) {
            int t = 0;
            if(s.charAt(i) == s.charAt(i-1))
                t = 1;
            dp[i] = dp[i-1] + t;
        }
        for(int i = 0; i < n; ++i) {
            int l = in.nextInt();
            int r = in.nextInt();
            l = l - 1;
            r = r - 1;

            int ans = dp[r] - dp[l];

            System.out.println(ans);
        }
        in.close();
    }
}


/**
 * Created by nitin.s on 01/01/15.
 */
import java.util.*;
public class LLyaAndQueries {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next();
        int arr[]=new int[s.length()];
        arr[0]= 0;
        int i,m,l,r;
        for(i=1;i<s.length();i++){
            if (s.charAt(i)==s.charAt(i-1)){arr[i]=arr[i-1]+1;}
            else {arr[i] = arr[i-1];}
        }
        m=in.nextInt();
        for(i=0;i<m;i++){
            l=in.nextInt(); r=in.nextInt();
            System.out.println(arr[r-1]-arr[l-1]);
        }
    }
}


/**
 * Created by nitin.s on 01/01/15.
 */
import java.util.*;
public class LLyaAndQueries {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.nextLine();
        int n = in.nextInt();
        int[] dp = new int[s.length() + 3];

        dp[0] = 0;
        for(int i = 1; i < s.length(); ++i) {
            int t = 0;
            if(s.charAt(i) == s.charAt(i-1))
                t = 1;
            dp[i] = dp[i-1] + t;
        }
        for(int i = 0; i < n; ++i) {

            int ans = -dp[in.nextInt()-1] + dp[in.nextInt()-1];

            System.out.println(ans);
        }
        in.close();
    }
}


/**
 * Created by nitin.s on 01/01/15.
 */
import java.util.*;
public class LLyaAndQueries {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.nextLine();
        int n = in.nextInt();
        int[] dp = new int[s.length() + 3];
        for(int i = 0; i < n+1; ++i )
            for(int j = 0; j < n+1; ++j)
                dp[i] = 0;
        dp[0] = 0;
        for(int i = 1; i < s.length(); ++i) {
            int t = 0;
            if(s.charAt(i) == s.charAt(i-1))
                t = 1;
            dp[i] = dp[i-1] + t;
        }
        for(int i = 0; i < n; ++i) {

            int ans = dp[in.nextInt() - 1] - dp[in.nextInt() - 1];

            System.out.println(ans);
        }
        in.close();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class CF {

    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        String s = in.next();
        int n = in.nextInt();
        int[] l = new int[n];
        int[] r = new int[n];
        for (int i = 0; i < r.length; i++) {
            l[i] = in.nextInt() - 1;
            r[i] = in.nextInt() - 1;
        }

        int[] sum = new int[s.length()];
        sum[0] = s.charAt(0) == s.charAt(1) ? 1 : 0;
        for (int i = 1; i < sum.length - 1; i++) {
            sum[i] += sum[i - 1] + (s.charAt(i) == s.charAt(i + 1) ? 1 : 0);
        }

        for (int i = 0; i < n; i++) {
            int left = l[i] == 0 ? 0 : sum[l[i] - 1];

            out.println(sum[r[i] - 1] - left);
        }
        out.close();
    }
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

}


import java.util.*;
import java.util.Map.Entry;
import java.io.*;
import java.awt.Point;
import java.math.BigInteger;

import static java.lang.Math.*;

public class Codeforces_Solution_A implements Runnable{

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void init() throws FileNotFoundException{
        if (ONLINE_JUDGE){
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }else{
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        }
    }

    String readString() throws IOException{
        while(!tok.hasMoreTokens()){
            try{
                tok = new StringTokenizer(in.readLine());
            }catch (Exception e){
                return null;
            }
        }
        return tok.nextToken();
    }

    int readInt() throws IOException{
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException{
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException{
        return Double.parseDouble(readString());
    }

    public static void main(String[] args){
        new Thread(null, new Codeforces_Solution_A(), "", 128 * (1L << 20)).start();
    }

    long timeBegin, timeEnd;

    void time(){
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    long memoryTotal, memoryFree;

    void memory(){
        memoryFree = Runtime.getRuntime().freeMemory();
        System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10) + " KB");
    }

    void debug(Object... objects){
        if (DEBUG){
            for (Object o: objects){
                System.err.println(o.toString());
            }
        }
    }

    public void run(){
        try{
            timeBegin = System.currentTimeMillis();
            memoryTotal = Runtime.getRuntime().freeMemory();
            init();
            solve();
            out.close();
            time();
            memory();
        }catch (Exception e){
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }

    boolean DEBUG = false;

    void solve() throws IOException{

        String s = readString();
        int n = s.length();
        int[] d = new int[n];

        d[0]=0;

        for (int i=0; i<n-1; i++) {
            if (i>0) d[i]=d[i-1];
            if (s.charAt(i)==s.charAt(i+1)) d[i]++;
        }

        int m = readInt();

        for (int i=0; i<m; i++) {
            int l = readInt()-1;
            int r = readInt()-1;
            if (l==0) out.println(d[r-1]);
            else out.println(d[r-1]-d[l-1]);
        }

    }

}


import java.util.*;

public class Queries
{
    public static void main(String[] args)
    {
        // Set up scanner
        Scanner sc = new Scanner(System.in);
        // System.out.println("Enter the string");
        String st = sc.next();

        // System.out.println("Enter number of queries");
        int m = sc.nextInt();

        // Process the string into an array--all pairs == up to that point
        int[] a = new int[st.length()-1];
        int pairstohere = 0;
        for (int i=0; i<a.length; i++)
        {
            if (st.substring(i, i+1).equals(st.substring(i+1,i+2)))
            {
                pairstohere++;
            }
            a[i] = pairstohere;
        }

        // Loop over all queries
        for (int i=0; i<m; i++)
        {
            // System.out.println("Input left bound");
            int left = sc.nextInt();
            // System.out.println("Input right bound");
            int right = sc.nextInt();
            if (left == 1)
            {
                System.out.println(a[right-2]);
            }
            else
            {
                System.out.println(a[right-2] - a[left-2]);
            }
        }
    }
}


import java.util.*;

public class TaskB {
    public static void main(String[] args) {
        new TaskB().solve();
    }

    TaskB() {
    }

    public void solve() {
        Scanner in = new Scanner(System.in);
        String s = in.next();
        int n = s.length();
        int m = in.nextInt();
        int[] sum = new int[n];
        for (int i = n - 2; i >= 0; --i)
            sum[i] = sum[i + 1] + (s.charAt(i) == s.charAt(i + 1) ? 1 : 0);
        for (int i = 0; i < m; ++i) {
            int l = in.nextInt();
            int r = in.nextInt();
            System.out.println(sum[l - 1] - sum[r - 1]);
        }
    }
}


import java.io.*;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] s) {
		try {
			InputStream inputStream = System.in;
			InputReader in = new InputReader(inputStream);
			PrintWriter writer = new PrintWriter(System.out);

			Task solution = new Task();
			solution.solve(in,writer);

			writer.close();
			inputStream.close();

		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}

class Task {

	private int[] range;

	public void solve(InputReader in, PrintWriter out) throws IOException {

		String str = in.next();
		preProcess(str);

		int query = in.nextInt();

		// answer each query

		for (int i=0;i<query;i++) {
			int left = in.nextInt();
			int right = in.nextInt();

			int match = range[right-1] - range[left-1];

			out.println(match);
		}
	}

	private void preProcess(String str) {
		char[] strArray = str.toCharArray();

		range = new int[strArray.length];

		range[0] = 0;

		for (int i=1;i<strArray.length;i++) {
			if (strArray[i] == strArray[i-1]) {
				range[i] = range[i-1] + 1;
			} else {
				range[i] = range[i-1];
			}
		}
	}

}

class InputReader {
	public BufferedReader reader;
	public StringTokenizer tokenizer;

	public InputReader(InputStream stream) {
		reader = new BufferedReader(new InputStreamReader(stream));
		tokenizer = null;
	}

	public String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;

public class TwoPaths implements Runnable {
    static class Edge {
        Vertex destination;
        Edge sameEdgeOtherDirection;
        private int id;
        boolean covered = false;

        Edge(Vertex destination, Edge sameEdgeOtherDirection, int id) {
            this.destination = destination;
            this.sameEdgeOtherDirection = sameEdgeOtherDirection;
            this.id = id;
        }
    }

    static class Vertex {
        List<Edge> adj = new ArrayList<Edge>();
        int dfsPosition = -1;
        boolean mark = false;
        Edge prevDist = null;
        int component = -1;

        public void dfs(int id) {
            if (mark)
                return;
            if (component != -1)
                throw new RuntimeException();
            mark = true;
            component = id;
            for (Edge e : adj)
                e.destination.dfs(id);
        }
    }

    static class Path {
        Vertex start;
        List<Edge> edges = new ArrayList<Edge>();

        public void printOut(PrintWriter writer) {
            writer.println(edges.size());
            boolean first = true;
            for (Edge e : edges) {
                if (first) first = false; else writer.print(" ");
                writer.print(e.id);
            }
            writer.println();
        }
    }

    static final int MAX_VERTEX = 10000;

    private void solve() throws IOException {
        int m = nextInt();
        Vertex[] v = new Vertex[MAX_VERTEX];
        for (int i = 0; i < MAX_VERTEX; ++i)
            v[i] = new Vertex();
        for (int i = 0; i < m; ++i) {
            int a = nextInt() - 1;
            int b = nextInt() - 1;
            Edge ab = new Edge(v[b], null, i + 1);;
            Edge ba = new Edge(v[a], null, i + 1);;
            ab.sameEdgeOtherDirection = ba;
            ba.sameEdgeOtherDirection = ab;
            v[a].adj.add(ab);
            v[b].adj.add(ba);
        }
        if (m < 2) {
            writer.println(-1);
            return;
        }
        int components = 0;
        for (Vertex x : v) {
            if (!x.adj.isEmpty()) {
                if (!x.mark) {
                    x.dfs(components++);
                }
            }
        }
        if (components > 2) {
            writer.println(-1);
            return;
        }
        if (components == 2) {
            Path p1 = buildPathForComponent(v, 0);
            Path p2 = buildPathForComponent(v, 1);
            if (p1 == null || p2 == null) {
                writer.println(-1);
                return;
            }
            p1.printOut(writer);
            p2.printOut(writer);
        } else {
            Vertex[] odds = new Vertex[4];
            int numOdds = 0;
            for (Vertex x : v) {
                if (x.adj.size() % 2 != 0) {
                    ++numOdds;
                    if (numOdds > 4) {
                        writer.println(-1);
                        return;
                    }
                    odds[numOdds - 1] = x;
                }
            }
            if (numOdds <= 2) {
                Path p = buildPathForComponent(v, 0);
                Edge last = p.edges.get(p.edges.size() - 1);
                p.edges.remove(p.edges.size() - 1);
                p.printOut(writer);
                writer.println(1);
                writer.println(last.id);
            } else {
                Path[] p = findTwoPaths(odds, v);
                if (p == null) {
                    writer.println(-1);
                    return;
                }
                p[0].printOut(writer);
                p[1].printOut(writer);
            }
        }
    }

    private Path[] findTwoPaths(Vertex[] ends, Vertex[] v) {
        Path[] res = new Path[2];
        Path p = buildShortestPath(ends[0], ends[1]);
        for (Edge e : p.edges) {
            e.covered = true;
            e.sameEdgeOtherDirection.covered = true;
        }
        for (Vertex x : v) x.dfsPosition = 0;
        res[0] = buildEulerianPath(ends[2]);
        for (Edge e : p.edges) {
            e.covered = false;
            e.sameEdgeOtherDirection.covered = false;
        }
        for (Vertex x : v) x.dfsPosition = 0;
        res[1] = buildEulerianPath(ends[0]);
        return res;
    }

    private Path buildShortestPath(Vertex a, Vertex b) {
        Queue<Vertex> q = new ArrayDeque<Vertex>();
        q.add(a);
        Edge sentinel = new Edge(null, null, -1);
        a.prevDist = sentinel;
        while (!q.isEmpty()) {
            Vertex cur = q.poll();
            for (Edge e : cur.adj) {
                if (e.covered)
                    continue;
                if (e.destination.prevDist != null)
                    continue;
                e.destination.prevDist = e.sameEdgeOtherDirection;
                q.add(e.destination);
                if (e.destination == b) {
                    Path res = new Path();
                    cur = b;
                    while (cur != a) {
                        res.edges.add(cur.prevDist);
                        cur = cur.prevDist.destination;
                    }
                    return res;
                }
            }
        }
        return null;
    }

    private Path buildPathForComponent(Vertex[] v, int componentId) {
        Vertex[] odds = new Vertex[2];
        int numOdds = 0;
        Vertex any = null;
        for (Vertex x : v)
            if (x.component == componentId) {
                any = x;
                if (x.adj.size() % 2 != 0) {
                    ++numOdds;
                    if (numOdds > 2)
                        return null;
                    odds[numOdds - 1] = x;
                }
            }
        if (numOdds > 0)
            any = odds[0];
        for (Vertex x : v) x.dfsPosition = 0;
        Path p = buildEulerianPath(any);
        return p;
    }

    private Path buildEulerianPath(Vertex start) {
        Path res = new Path();
        Stack<Vertex> dfsStack = new Stack<Vertex>();
        Stack<Edge> dfsBy = new Stack<Edge>();
        dfsStack.add(start);
        start.dfsPosition = 0;
        while (!dfsStack.isEmpty()) {
            Vertex last = dfsStack.peek();
            boolean anyNew = false;
            for (int i = last.dfsPosition; i < last.adj.size(); ++i) {
                Edge e = last.adj.get(i);
                last.dfsPosition = i + 1;
                if (!e.covered) {
                    anyNew = true;
                    e.covered = true;
                    e.sameEdgeOtherDirection.covered = true;
                    dfsStack.add(e.destination);
                    dfsBy.add(e.sameEdgeOtherDirection);
                    break;
                }
            }
            if (!anyNew) {
                if (res.edges.isEmpty()) {
                    res.start = last;
                }
                dfsStack.pop();
                if (!dfsBy.isEmpty())
                    res.edges.add(dfsBy.pop());
            }
        }
        return res;
    }

    public static void main(String[] args) {
        new TwoPaths().run();
    }

    static final String IN_FILE = "input.txt";
    static final String OUT_FILE = "output.txt";

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new FileReader(IN_FILE));
            tokenizer = null;
            writer = new PrintWriter(OUT_FILE);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
}


#include<cstdio>
#include<vector>
#include<cstring>
#include<cstdlib>
#include<iostream>
using namespace std;
const int N_MAX=10000+10;
#ifndef ONLINE_JUDGE
	#define Debug(x){ cerr<<#x<<"="<<x<<endl; }
	#define Error() { cerr<<"Error"<<endl; }
	#define Fuck()  { cerr<<"Fuck"<<endl; }
#else
	#define Debug(x){}
	#define Error() {}
	#define Fuck()  {}
#endif
#define viter(x) vector<x>::iterator
inline void BAD(){ puts("-1");exit(0); }
int M;
struct Tedge{
	int son,id;
	Tedge(){}
	Tedge(int _son,int _id):son(_son),id(_id){}
};
vector <Tedge> EDGE[N_MAX];int idx[N_MAX];
void dfs(int x,int fa){
	if (idx[x]!=-1) return;
	idx[x]=fa;
	for (viter(Tedge) it=EDGE[x].begin(); it!=EDGE[x].end(); ++it)
		dfs(it->son,fa);
}
vector <int> path,ans1,ans2;bool used[N_MAX];int at[N_MAX];
void euler(int x){
	while (at[x]<EDGE[x].size()){
		int son=EDGE[x][at[x]].son,id=EDGE[x][at[x]++].id;
		if (used[id]) continue;
		used[id]=1;
		euler(son);
		path.push_back(id);
	}
}
int main(){
	freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	scanf("%d", &M);
	for (int i=1; i<=M; ++i){
		int a,b;scanf("%d%d", &a, &b);
		EDGE[a].push_back(Tedge(b,i));
		EDGE[b].push_back(Tedge(a,i));
	}
	memset(idx,-1,sizeof(idx));vector <int> BLOCK;
	for (int i=1; i<=N_MAX; ++i)
		if (idx[i]==-1 && !EDGE[i].empty()){
			dfs(i,i);
			BLOCK.push_back(i);
		}
	if (BLOCK.size()>2) BAD();
	vector <int> ODD;
	for (int i=1; i<=N_MAX; ++i)
		if (EDGE[i].size()%2)
			ODD.push_back(i);
	if (ODD.size()>4) BAD();
	if (BLOCK.size()==2){
		vector <int> odd1,odd2;
		for (viter(int) it=ODD.begin(); it!=ODD.end(); ++it)
			if (idx[*it]==BLOCK[0])
				odd1.push_back(*it);
			else
				odd2.push_back(*it);
		if (odd1.size()>2 || odd2.size()>2) BAD();
		odd1.push_back(BLOCK[0]); odd2.push_back(BLOCK[1]);
		euler(BLOCK[0]); ans1=path;
		path.clear();
		euler(BLOCK[1]); ans2=path;
	}
	else{
		if (ODD.size()<=2){
			ODD.push_back(BLOCK[0]);
			euler(BLOCK[0]);
			if (path.size()<2) BAD();
			ans1=path; ans2.push_back(ans1.back());
			ans1.pop_back();
		}
		else{
			int x=ODD[2],y=ODD[3];
			EDGE[x].push_back(Tedge(y,N_MAX));
			EDGE[y].push_back(Tedge(x,N_MAX));
			euler(ODD[0]);
			bool flag=0;
			for (viter(int) it=path.begin(); it!=path.end(); ++it)
				if (*it==N_MAX) flag=1;
				else if (flag) ans1.push_back(*it);
				else ans2.push_back(*it);
		}
	}
	printf("%d\n", ans1.size());
	for (viter(int) it=ans1.begin(); it!=ans1.end()-1; ++it)
		printf("%d ", *it);
	printf("%d\n%d\n", ans1.back(), ans2.size());
	for (viter(int) it=ans2.begin(); it!=ans2.end()-1; ++it)
		printf("%d ", *it);
	printf("%d\n", ans2.back());
	return 0;
}


#include<cstdio>
#include<vector>
#include<cstring>
#include<cstdlib>
#include<iostream>
using namespace std;
const int N_MAX=10000+10;
#ifndef ONLINE_JUDGE
    #define Debug(x){ cerr<<#x<<"="<<x<<endl; }
    #define Error() { cerr<<"Error"<<endl; }
    #define Fuck()  { cerr<<"Fuck"<<endl; }
#else
    #define Debug(x){}
    #define Error() {}
    #define Fuck()  {}
#endif
#define viter(x) vector<x>::iterator
inline void BAD(){ puts("-1");exit(0); }
int M;
struct Tedge{
    int son,id;
    Tedge(){}
    Tedge(int _son,int _id):son(_son),id(_id){}
};
vector <Tedge> EDGE[N_MAX];int idx[N_MAX];
void dfs(int x,int fa){
    if (idx[x]!=-1) return;
    idx[x]=fa;
    for (viter(Tedge) it=EDGE[x].begin(); it!=EDGE[x].end(); ++it)
        dfs(it->son,fa);
}
vector <int> path,ans1,ans2;bool used[N_MAX];int at[N_MAX];
void euler(int x){
    while (at[x]<EDGE[x].size()){
        int son=EDGE[x][at[x]].son,id=EDGE[x][at[x]++].id;
        if (used[id]) continue;
        used[id]=1;
        euler(son);
        path.push_back(id);
    }
}
vector <int> ODD,odd1,odd2;
int main(){
    freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    scanf("%d", &M);
    for (int i=1; i<=M; ++i){
        int a,b;scanf("%d%d", &a, &b);
        EDGE[a].push_back(Tedge(b,i));
        EDGE[b].push_back(Tedge(a,i));
    }
    memset(idx,-1,sizeof(idx));vector <int> BLOCK;
    for (int i=1; i<=N_MAX; ++i)
        if (idx[i]==-1 && !EDGE[i].empty()){
            dfs(i,i);
            BLOCK.push_back(i);
        }
    if (BLOCK.size()>2) BAD();
    for (int i=1; i<=N_MAX; ++i)
        if (EDGE[i].size()%2)
            ODD.push_back(i);
    if (ODD.size()>4) BAD();
    if (BLOCK.size()==2){
        for (viter(int) it=ODD.begin(); it!=ODD.end(); ++it)
            if (idx[*it]==BLOCK[0])
                odd1.push_back(*it);
            else
                odd2.push_back(*it);
        if (odd1.size()>2 || odd2.size()>2) BAD();
        odd1.push_back(BLOCK[0]); odd2.push_back(BLOCK[1]);
        euler(BLOCK[0]); ans1=path;
        path.clear();
        euler(BLOCK[1]); ans2=path;
    }
    else{
        if (ODD.size()<=2){
            ODD.push_back(BLOCK[0]);
            euler(BLOCK[0]);
            if (path.size()<2) BAD();
            ans1=path; ans2.push_back(ans1.back());
            ans1.pop_back();
        }
        else{
            int x=ODD[2],y=ODD[3];
            EDGE[x].push_back(Tedge(y,N_MAX));
            EDGE[y].push_back(Tedge(x,N_MAX));
            euler(ODD[0]);
            bool flag=0;
            for (viter(int) it=path.begin(); it!=path.end(); ++it)
                if (*it==N_MAX) flag=1;
                else if (flag) ans1.push_back(*it);
                else ans2.push_back(*it);
        }
    }
    printf("%d\n", ans1.size());
    for (viter(int) it=ans1.begin(); it!=ans1.end()-1; ++it)
        printf("%d ", *it);
    printf("%d\n%d\n", ans1.back(), ans2.size());
    for (viter(int) it=ans2.begin(); it!=ans2.end()-1; ++it)
        printf("%d ", *it);
    printf("%d\n", ans2.back());
    fclose(stdin); fclose(stdout);
    return 0;
}


#include<cstdio>
#include<vector>
#include<cstring>
#include<cstdlib>
#include<iostream>
using namespace std;
const int N_MAX=10000+10;
#ifndef ONLINE_JUDGE
	#define Debug(x){ cerr<<#x<<"="<<x<<endl; }
	#define Error() { cerr<<"Error"<<endl; }
	#define Fuck()  { cerr<<"Fuck"<<endl; }
#else
	#define Debug(x){}
	#define Error() {}
	#define Fuck()  {}
#endif
#define viter(x) vector<x>::iterator
inline void BAD(){ puts("-1");exit(0); }
int M;
struct Tedge{
	int son,id;
	Tedge(){}
	Tedge(int _son,int _id):son(_son),id(_id){}
};
vector <Tedge> EDGE[N_MAX];int idx[N_MAX];
void dfs(int x,int fa){
	if (idx[x]!=-1) return;
	idx[x]=fa;
	for (viter(Tedge) it=EDGE[x].begin(); it!=EDGE[x].end(); ++it)
		dfs(it->son,fa);
}
vector <int> path,ans1,ans2;bool used[N_MAX];int at[N_MAX];
void euler(int x){
	while (at[x]<EDGE[x].size()){
		int son=EDGE[x][at[x]].son,id=EDGE[x][at[x]++].id;
		if (used[id]) continue;
		used[id]=1;
		euler(son);
		path.push_back(id);
	}
}
int main(){
	scanf("%d", &M);
	for (int i=1; i<=M; ++i){
		int a,b;scanf("%d%d", &a, &b);
		EDGE[a].push_back(Tedge(b,i));
		EDGE[b].push_back(Tedge(a,i));
	}
	memset(idx,-1,sizeof(idx));vector <int> BLOCK;
	for (int i=1; i<=N_MAX; ++i)
		if (idx[i]==-1 && !EDGE[i].empty()){
			dfs(i,i);
			BLOCK.push_back(i);
		}
	if (BLOCK.size()>2) BAD();
	vector <int> ODD;
	for (int i=1; i<=N_MAX; ++i)
		if (EDGE[i].size()%2)
			ODD.push_back(i);
	if (ODD.size()>4) BAD();
	if (BLOCK.size()==2){
		vector <int> odd1,odd2;
		for (viter(int) it=ODD.begin(); it!=ODD.end(); ++it)
			if (idx[*it]==BLOCK[0])
				odd1.push_back(*it);
			else
				odd2.push_back(*it);
		if (odd1.size()>2 || odd2.size()>2) BAD();
		odd1.push_back(BLOCK[0]); odd2.push_back(BLOCK[1]);
		euler(BLOCK[0]); ans1=path;
		path.clear();
		euler(BLOCK[1]); ans2=path;
	}
	else{
		if (ODD.size()<=2){
			ODD.push_back(BLOCK[0]);
			euler(BLOCK[0]);
			if (path.size()<2) BAD();
			ans1=path; ans2.push_back(ans1.back());
			ans1.pop_back();
		}
		else{
			int x=ODD[2],y=ODD[3];
			EDGE[x].push_back(Tedge(y,N_MAX));
			EDGE[y].push_back(Tedge(x,N_MAX));
			euler(ODD[0]);
			bool flag=0;
			for (viter(int) it=path.begin(); it!=path.end(); ++it)
				if (*it==N_MAX) flag=1;
				else if (flag) ans1.push_back(*it);
				else ans2.push_back(*it);
		}
	}
	printf("%d\n", ans1.size());
	for (viter(int) it=ans1.begin(); it!=ans1.end()-1; ++it)
		printf("%d ", *it);
	printf("%d\n%d\n", ans1.back(), ans2.size());
	for (viter(int) it=ans2.begin(); it!=ans2.end()-1; ++it)
		printf("%d ", *it);
	printf("%d\n", ans2.back());
	return 0;
}


#include<cstdio>
#include<vector>
#include<cstring>
#include<cstdlib>
#include<iostream>
using namespace std;
const int N_MAX=10000+10;
#ifndef ONLINE_JUDGE
    #define Debug(x){ cerr<<#x<<"="<<x<<endl; }
    #define Error() { cerr<<"Error"<<endl; }
    #define Fuck()  { cerr<<"Fuck"<<endl; }
#else
    #define Debug(x){}
    #define Error() {}
    #define Fuck()  {}
#endif
#define viter(x) vector<x>::iterator
inline void BAD(){ puts("-1");exit(0); }
int M;
struct Tedge{
    int son,id;
    Tedge(){}
    Tedge(int _son,int _id):son(_son),id(_id){}
};
vector <Tedge> EDGE[N_MAX];int idx[N_MAX];
void dfs(int x,int fa){
    if (idx[x]!=-1) return;
    idx[x]=fa;
    for (viter(Tedge) it=EDGE[x].begin(); it!=EDGE[x].end(); ++it)
        dfs(it->son,fa);
}
vector <int> path,ans1,ans2;bool used[N_MAX];int at[N_MAX];
void euler(int x){
    while (at[x]<EDGE[x].size()){
        int son=EDGE[x][at[x]].son,id=EDGE[x][at[x]++].id;
        if (used[id]) continue;
        used[id]=1;
        euler(son);
        path.push_back(id);
    }
}
int main(){
    freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    scanf("%d", &M);
    for (int i=1; i<=M; ++i){
        int a,b;scanf("%d%d", &a, &b);
        EDGE[a].push_back(Tedge(b,i));
        EDGE[b].push_back(Tedge(a,i));
    }
    memset(idx,-1,sizeof(idx));vector<int> BLOCK;
    for (int i=0; i<N_MAX; ++i)
        if (idx[i]==-1 && !EDGE[i].empty()){
            dfs(i,i);
            BLOCK.push_back(i);
        }
    if (BLOCK.size()>2) BAD();
    vector<int> ODD;
    for (int i=0; i<N_MAX; ++i)
        if (EDGE[i].size()%2)
            ODD.push_back(i);
    if (ODD.size()>4) BAD();
    if (BLOCK.size()==2){
        vector<int> odd1,odd2;
        for (viter(int) it=ODD.begin(); it!=ODD.end(); ++it)
            if (idx[*it]==BLOCK[0])
                odd1.push_back(*it);
            else
                odd2.push_back(*it);
        if (odd1.size()>2 || odd2.size()>2) BAD();
        odd1.push_back(BLOCK[0]); odd2.push_back(BLOCK[1]);
        euler(odd1[0]); ans1=path;
        path.clear();
        euler(odd2[1]); ans2=path;
        path.clear();
    }
    else{
        if (ODD.size()<=2){
            ODD.push_back(BLOCK[0]);
            euler(ODD[0]);
            ans1=path;
            if (ans1.size()<2) BAD();
            ans2.push_back(ans1.back());
            ans1.pop_back();
        }
        else{
            int x=ODD[2],y=ODD[3];
            EDGE[x].push_back(Tedge(y,N_MAX));
            EDGE[y].push_back(Tedge(x,N_MAX));
            euler(ODD[0]);
            bool flag=0;
            for (viter(int) it=path.begin(); it!=path.end(); ++it)
                if (*it==N_MAX) flag=1;
                else if (flag) ans1.push_back(*it);
                else ans2.push_back(*it);
        }
    }
    printf("%d\n", ans1.size());
    for (viter(int) it=ans1.begin(); it!=ans1.end()-1; ++it)
        printf("%d ", *it);
    printf("%d\n%d\n", ans1.back(), ans2.size());
    for (viter(int) it=ans2.begin(); it!=ans2.end()-1; ++it)
        printf("%d ", *it);
    printf("%d\n", ans2.back());
    fclose(stdin); fclose(stdout);
    return 0;
}


#include<cstdio>
#include<vector>
#include<cstring>
#include<cstdlib>
#include<iostream>
using namespace std;
const int N_MAX=10000+10;
#ifndef ONLINE_JUDGE
	#define Debug(x){ cerr<<#x<<"="<<x<<endl; }
	#define Error() { cerr<<"Error"<<endl; }
	#define Fuck()  { cerr<<"Fuck"<<endl; }
#else
	#define Debug(x){}
	#define Error() {}
	#define Fuck()  {}
#endif
#define viter(x) vector<x>::iterator
inline void BAD(){ puts("-1");exit(0); }
int M;
struct Tedge{
	int son,id;
	Tedge(){}
	Tedge(int _son,int _id):son(_son),id(_id){}
};
vector <Tedge> EDGE[N_MAX];int idx[N_MAX];
void dfs(int x,int fa){
	if (idx[x]!=-1) return;
	idx[x]=fa;
	for (viter(Tedge) it=EDGE[x].begin(); it!=EDGE[x].end(); ++it)
		dfs(it->son,fa);
}
vector <int> path,ans1,ans2;bool used[N_MAX];int at[N_MAX];
void euler(int x){
	while (at[x]<EDGE[x].size()){
		int son=EDGE[x][at[x]].son,id=EDGE[x][at[x]++].id;
		if (used[id]) continue;
		used[id]=1;
		euler(son);
		path.push_back(id);
	}
}
int main(){
	freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	scanf("%d", &M);
	for (int i=1; i<=M; ++i){
		int a,b;scanf("%d%d", &a, &b);
		EDGE[a].push_back(Tedge(b,i));
		EDGE[b].push_back(Tedge(a,i));
	}
	memset(idx,-1,sizeof(idx));vector<int> BLOCK;
	for (int i=0; i<N_MAX; ++i)
		if (idx[i]==-1 && !EDGE[i].empty()){
			dfs(i,i);
			BLOCK.push_back(i);
		}
	if (BLOCK.size()>2) BAD();
	vector<int> ODD;
	for (int i=0; i<N_MAX; ++i)
		if (EDGE[i].size()%2)
			ODD.push_back(i);
	if (ODD.size()>4) BAD();
	if (BLOCK.size()==2){
		vector<int> odd1,odd2;
		for (viter(int) it=ODD.begin(); it!=ODD.end(); ++it)
			if (idx[*it]==BLOCK[0])
				odd1.push_back(*it);
			else
				odd2.push_back(*it);
		if (odd1.size()>2 || odd2.size()>2) BAD();
		odd1.push_back(BLOCK[0]);
		odd2.push_back(BLOCK[1]);
		euler(odd1[0]); ans1=path;
		path.clear();
		euler(odd2[0]); ans2=path;
		path.clear();
	}
	else{
		if (ODD.size()<=2){
			ODD.push_back(BLOCK[0]);
			euler(ODD[0]);
			ans1=path;
			if (ans1.size()<2) BAD();
			ans2.push_back(ans1.back());
			ans1.pop_back();
		}
		else{
			int x=ODD[2],y=ODD[3];
			EDGE[x].push_back(Tedge(y,N_MAX-1));
			EDGE[y].push_back(Tedge(x,N_MAX-1));
			euler(ODD[0]);
			bool flag=0;
			for (viter(int) it=path.begin(); it!=path.end(); ++it)
				if (*it==N_MAX-1) flag=1;
				else if (flag) ans1.push_back(*it);
				else ans2.push_back(*it);
		}
	}
	printf("%d\n", ans1.size());
	for (viter(int) it=ans1.begin(); it!=ans1.end()-1; ++it)
		printf("%d ", *it);
	printf("%d\n%d\n", ans1.back(), ans2.size());
	for (viter(int) it=ans2.begin(); it!=ans2.end()-1; ++it)
		printf("%d ", *it);
	printf("%d\n", ans2.back());
	fclose(stdin); fclose(stdout);
	return 0;
}


#include<cstdio>
#include<vector>
#include<cstring>
#include<cstdlib>
#include<iostream>
using namespace std;
const int N_MAX=10000+10;
#ifndef ONLINE_JUDGE
	#define Debug(x){ cerr<<#x<<"="<<x<<endl; }
	#define Error() { cerr<<"Error"<<endl; }
	#define Fuck()  { cerr<<"Fuck"<<endl; }
#else
	#define Debug(x){}
	#define Error() {}
	#define Fuck()  {}
#endif
#define viter(x) vector<x>::iterator
inline void BAD(){ puts("-1");exit(0); }
int M;
struct Tedge{
	int son,id;
	Tedge(){}
	Tedge(int _son,int _id):son(_son),id(_id){}
};
vector <Tedge> EDGE[N_MAX];int idx[N_MAX];
void dfs(int x,int fa){
	if (idx[x]!=-1) return;
	idx[x]=fa;
	for (viter(Tedge) it=EDGE[x].begin(); it!=EDGE[x].end(); ++it)
		dfs(it->son,fa);
}
vector <int> path,ans1,ans2;bool used[N_MAX];int at[N_MAX];
void euler(int x){
	while (at[x]<EDGE[x].size()){
		int son=EDGE[x][at[x]].son,id=EDGE[x][at[x]++].id;
		if (used[id]) continue;
		used[id]=1;
		euler(son);
		path.push_back(id);
	}
}
int main(){
	freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	scanf("%d", &M);
	for (int i=1; i<=M; ++i){
		int a,b;scanf("%d%d", &a, &b);
		EDGE[a].push_back(Tedge(b,i));
		EDGE[b].push_back(Tedge(a,i));
	}
	memset(idx,-1,sizeof(idx));vector <int> BLOCK;
	for (int i=1; i<=N_MAX; ++i)
		if (idx[i]==-1 && !EDGE[i].empty()){
			dfs(i,i);
			BLOCK.push_back(i);
		}
	if (BLOCK.size()>2) BAD();
	vector <int> ODD;
	for (int i=1; i<=N_MAX; ++i)
		if (EDGE[i].size()%2)
			ODD.push_back(i);
	if (ODD.size()>4) BAD();
	if (BLOCK.size()==2){
		vector <int> odd1,odd2;
		for (viter(int) it=ODD.begin(); it!=ODD.end(); ++it)
			if (idx[*it]==BLOCK[0])
				odd1.push_back(*it);
			else
				odd2.push_back(*it);
		if (odd1.size()>2 || odd2.size()>2) BAD();
		odd1.push_back(BLOCK[0]); odd2.push_back(BLOCK[1]);
		euler(BLOCK[0]); ans1=path;
		path.clear();
		euler(BLOCK[1]); ans2=path;
	}
	else{
		if (ODD.size()<=2){
			ODD.push_back(BLOCK[0]);
			euler(BLOCK[0]);
			if (path.size()<2) BAD();
			ans1=path; ans2.push_back(ans1.back());
			ans1.pop_back();
		}
		else{
			int x=ODD[2],y=ODD[3];
			EDGE[x].push_back(Tedge(y,N_MAX));
			EDGE[y].push_back(Tedge(x,N_MAX));
			euler(ODD[0]);
			bool flag=0;
			for (viter(int) it=path.begin(); it!=path.end(); ++it)
				if (*it==N_MAX) flag=1;
				else if (flag) ans1.push_back(*it);
				else ans2.push_back(*it);
		}
	}
	printf("%d\n", ans1.size());
	for (viter(int) it=ans1.begin(); it!=ans1.end()-1; ++it)
		printf("%d ", *it);
	printf("%d\n%d\n", ans1.back(), ans2.size());
	for (viter(int) it=ans2.begin(); it!=ans2.end()-1; ++it)
		printf("%d ", *it);
	printf("%d\n", ans2.back());
	fclose(stdin); fclose(stdout);
	return 0;
}


#include <cstdio>

const int maxn = 10010;
int m, a, b, fa[maxn], cnt, d[maxn], odd[4], ans[maxn];
int head[maxn], next[maxn * 2], px[maxn * 2];
bool exist[maxn], v[maxn];

inline int getanc(int x){return fa[x] <= 0 ? x : fa[x] = getanc(fa[x]);}

void euler(int x){
	for (int ptr = head[x]; ptr; ptr = next[ptr])
		if (!v[(ptr + 1) >> 1]){
			v[(ptr + 1) >> 1] = true;
			euler(px[ptr]);
			ans[cnt++] = (ptr + 1) >> 1;
		}
}

int main(){
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	scanf("%d", &m);
	for (int i = 1; i <= m; i++){
		scanf("%d%d", &a, &b);
		px[++cnt] = b; next[cnt] = head[a]; head[a] = cnt;
		px[++cnt] = a; next[cnt] = head[b]; head[b] = cnt;
		exist[a] = exist[b] = true; d[a]++; d[b]++;
		if (getanc(a) != getanc(b)) fa[getanc(a)] = getanc(b);
	}
	cnt = 0;
	for (int i = 1; i < maxn; i++) if (exist[i] && fa[i] == 0) cnt++;
	if (cnt > 2 || m == 1){
		printf("-1\n");
		return 0;
	}
	if (cnt == 1){
		cnt = 0;
		for (int i = 1; i < maxn; i++) if (exist[i] && (d[i] & 1)) odd[cnt++] = i;
		if (cnt > 4 || (cnt & 1)){
			printf("-1\n");
			return 0;
		}
		if (cnt == 0){
			printf("1\n%d\n%d\n", m, m - 1);
			v[m] = true;
			cnt = 0;
			euler(a);
			for (int i = 0; i < cnt; i++) printf("%d ", ans[i]);
		} else if (cnt == 2){
			int x = px[head[odd[0]]];
			printf("1\n%d\n%d\n", (head[odd[0]] + 1) >> 1, m - 1);
			v[(head[odd[0]] + 1) >> 1] = true;
			cnt = 0;
			euler(x);
			for (int i = 0; i < cnt; i++) printf("%d ", ans[i]);
		} else{
			px[m + m + 1] = odd[1]; next[m + m + 1] = head[odd[0]]; head[odd[0]] = m + m + 1;
			px[m + m + 2] = odd[0]; next[m + m + 2] = head[odd[1]]; head[odd[1]] = m + m + 2;
			cnt = 0;
			euler(odd[2]);
			cnt = 0;
			for (int i = 0; i <= m; i++) if (ans[i] > m){
				printf("%d\n", i);
				for (int j = 0; j < i; j++) printf("%d ", ans[j]);
				printf("\n%d\n", m - i);
				for (int j = i + 1; j <= m; j++) printf("%d ", ans[j]);
				break;
			}
		}
	}else{
		for (int i = 1; i < maxn; i++) if (exist[i] && (d[i] & 1)) fa[getanc(i)]--;
		for (int i = 1; i < maxn; i++)
			if ((fa[i] <= 0 && fa[i] % 2 != 0) || fa[i] < -2){
				printf("-1\n");
				return 0;
			}
		for (int i = 1; i < maxn; i++)
			if (exist[i] && fa[i] == 0){
				cnt = 0;
				euler(i);
				printf("%d\n", cnt);
				for (int i = 0; i < cnt; i++) printf("%d ", ans[i]);
				printf("\n");
			}
		for (int i = 1; i < maxn; i++){
			if ((d[i] & 1) && fa[getanc(i)] < 0){
				cnt = fa[getanc(i)] = 0;
				euler(i);
				printf("%d\n", cnt);
				for (int i = 0; i < cnt; i++) printf("%d ", ans[i]);
				printf("\n");
			}
		}
	}
}


#include <cstdio>

const int maxn = 10010;
int m, a, b, fa[maxn], cnt, d[maxn], odd[4], ans[maxn];
int head[maxn], next[maxn * 2], px[maxn * 2];
bool exist[maxn], v[maxn];

inline int getanc(int x){return fa[x] <= 0 ? x : fa[x] = getanc(fa[x]);}

void euler(int x){
	for (int ptr = head[x]; ptr; ptr = next[ptr])
		if (!v[(ptr + 1) >> 1]){
			v[(ptr + 1) >> 1] = true;
			euler(px[ptr]);
			ans[cnt++] = (ptr + 1) >> 1;
		}
}

int main(){
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	scanf("%d", &m);
	for (int i = 1; i <= m; i++){
		scanf("%d%d", &a, &b);
		px[++cnt] = b; next[cnt] = head[a]; head[a] = cnt;
		px[++cnt] = a; next[cnt] = head[b]; head[b] = cnt;
		exist[a] = exist[b] = true; d[a]++; d[b]++;
		if (getanc(a) != getanc(b)) fa[getanc(a)] = getanc(b);
	}
	cnt = 0;
	for (int i = 1; i < maxn; i++) if (exist[i] && fa[i] == 0) cnt++;
	if (cnt > 2 || m == 1){
		printf("-1\n");
		return 0;
	}
	if (cnt == 1){
		cnt = 0;
		for (int i = 1; i < maxn; i++) if (exist[i] && (d[i] & 1)) odd[cnt++] = i;
		if (cnt > 4 || (cnt & 1)){
			printf("-1\n");
			return 0;
		}
		if (cnt == 0){
			printf("1\n%d\n%d\n", m, m - 1);
			v[m] = true;
			cnt = 0;
			euler(a);
			for (int i = 0; i < cnt; i++) printf("%d ", ans[i]);
		} else if (cnt == 2){
			int x = px[head[odd[0]]];
			printf("1\n%d\n%d\n", (head[odd[0]] + 1) >> 1, m - 1);
			v[(head[odd[0]] + 1) >> 1] = true;
			cnt = 0;
			euler(x);
			if (cnt == 0) euler(odd[0]);
			for (int i = 0; i < cnt; i++) printf("%d ", ans[i]);
		} else{
			px[m + m + 1] = odd[1]; next[m + m + 1] = head[odd[0]]; head[odd[0]] = m + m + 1;
			px[m + m + 2] = odd[0]; next[m + m + 2] = head[odd[1]]; head[odd[1]] = m + m + 2;
			cnt = 0;
			euler(odd[2]);
			cnt = 0;
			for (int i = 0; i <= m; i++) if (ans[i] > m){
				printf("%d\n", i);
				for (int j = 0; j < i; j++) printf("%d ", ans[j]);
				printf("\n%d\n", m - i);
				for (int j = i + 1; j <= m; j++) printf("%d ", ans[j]);
				break;
			}
		}
	}else{
		for (int i = 1; i < maxn; i++) if (exist[i] && (d[i] & 1)) fa[getanc(i)]--;
		for (int i = 1; i < maxn; i++)
			if ((fa[i] <= 0 && fa[i] % 2 != 0) || fa[i] < -2){
				printf("-1\n");
				return 0;
			}
		for (int i = 1; i < maxn; i++)
			if (exist[i] && fa[i] == 0){
				cnt = 0;
				euler(i);
				printf("%d\n", cnt);
				for (int i = 0; i < cnt; i++) printf("%d ", ans[i]);
				printf("\n");
			}
		for (int i = 1; i < maxn; i++){
			if ((d[i] & 1) && fa[getanc(i)] < 0){
				cnt = fa[getanc(i)] = 0;
				euler(i);
				printf("%d\n", cnt);
				for (int i = 0; i < cnt; i++) printf("%d ", ans[i]);
				printf("\n");
			}
		}
	}
}


#include <cstdio>

const int maxn = 10010;
int m, a, b, fa[maxn], cnt, d[maxn], odd[4], ans[maxn];
int head[maxn], next[maxn * 2], px[maxn * 2];
bool exist[maxn], v[maxn];

inline int getanc(int x){return !fa[x] ? x : fa[x] = getanc(fa[x]);}

void euler(int x){
	for (int ptr = head[x]; ptr; ptr = next[ptr])
		if (!v[(ptr + 1) >> 1]){
			v[(ptr + 1) >> 1] = true;
			euler(px[ptr]);
			ans[cnt++] = (ptr + 1) >> 1;
		}
}

int main(){
	scanf("%d", &m);
	for (int i = 1; i <= m; i++){
		scanf("%d%d", &a, &b);
		px[++cnt] = b; next[cnt] = head[a]; head[a] = cnt;
		px[++cnt] = a; next[cnt] = head[b]; head[b] = cnt;
		exist[a] = exist[b] = true; d[a]++; d[b]++;
		if (getanc(a) != getanc(b)) fa[getanc(a)] = getanc(b);
	}
	cnt = 0;
	for (int i = 1; i < maxn; i++) if (exist[i] && fa[i] == 0) cnt++;
	if (cnt > 2 || m == 1){
		printf("-1\n");
		return 0;
	}
	if (cnt == 1){
		cnt = 0;
		for (int i = 1; i < maxn; i++) if (exist[i] && (d[i] & 1)) odd[cnt++] = i;
		if (cnt > 4 || (cnt & 1)){
			printf("-1\n");
			return 0;
		}
		if (cnt == 0){
			printf("1\n%d\n%d\n", m, m - 1);
			v[m] = true;
			cnt = 0;
			euler(a);
			for (int i = 0; i < cnt; i++) printf("%d ", ans[i]);
		} else if (cnt == 2){
			int x = px[head[odd[0]]];
			printf("1\n%d\n%d\n", (head[odd[0]] + 1) >> 1, m - 1);
			v[(head[odd[0]] + 1) >> 1] = true;
			cnt = 0;
			euler(x);
			for (int i = 0; i < cnt; i++) printf("%d ", ans[i]);
		} else{
			px[m + m + 1] = odd[1]; next[m + m + 1] = head[odd[0]]; head[odd[0]] = m + m + 1;
			px[m + m + 2] = odd[0]; next[m + m + 2] = head[odd[1]]; head[odd[1]] = m + m + 2;
			cnt = 0;
			euler(odd[2]);
			cnt = 0;
			for (int i = 0; i <= m; i++) if (ans[i] > m){
				printf("%d\n", i);
				for (int j = 0; j < i; j++) printf("%d ", ans[j]);
				printf("\n%d\n", m - i);
				for (int j = i + 1; j <= m; j++) printf("%d ", ans[j]);
				break;
			}
		}
	}else{
		for (int i = 1; i < maxn; i++) if (exist[i] && (d[i] & 1)) fa[getanc(i)]--;
		for (int i = 1; i < maxn; i++)
			if ((fa[i] <= 0 && fa[i] % 2 != 0) || fa[i] < -2){
				printf("-1\n");
				return 0;
			}
		for (int i = 1; i < maxn; i++)
			if (fa[i] == 0){
				cnt = 0;
				euler(i);
				printf("%d\n", cnt);
				for (int i = 0; i < cnt; i++) printf("%d ", ans[i]);
				printf("\n");
			}
		for (int i = 1; i < maxn; i++){
			if ((d[i] & 1) && fa[getanc(i)] < 0){
				cnt = fa[getanc(i)] = 0;
				euler(i);
				printf("%d\n", cnt);
				for (int i = 0; i < cnt; i++) printf("%d ", ans[i]);
				printf("\n");
			}
		}
	}
}


#include <cstdio>

const int maxn = 10010;
int m, a, b, fa[maxn], cnt, d[maxn], odd[4], ans[maxn];
int head[maxn], next[maxn * 2], px[maxn * 2];
bool exist[maxn], v[maxn];

inline int getanc(int x){return fa[x] <= 0 ? x : fa[x] = getanc(fa[x]);}

void euler(int x){
	for (int ptr = head[x]; ptr; ptr = next[ptr])
		if (!v[(ptr + 1) >> 1]){
			v[(ptr + 1) >> 1] = true;
			euler(px[ptr]);
			ans[cnt++] = (ptr + 1) >> 1;
		}
}

int main(){
	scanf("%d", &m);
	for (int i = 1; i <= m; i++){
		scanf("%d%d", &a, &b);
		px[++cnt] = b; next[cnt] = head[a]; head[a] = cnt;
		px[++cnt] = a; next[cnt] = head[b]; head[b] = cnt;
		exist[a] = exist[b] = true; d[a]++; d[b]++;
		if (getanc(a) != getanc(b)) fa[getanc(a)] = getanc(b);
	}
	cnt = 0;
	for (int i = 1; i < maxn; i++) if (exist[i] && fa[i] == 0) cnt++;
	if (cnt > 2 || m == 1){
		printf("-1\n");
		return 0;
	}
	if (cnt == 1){
		cnt = 0;
		for (int i = 1; i < maxn; i++) if (exist[i] && (d[i] & 1)) odd[cnt++] = i;
		if (cnt > 4 || (cnt & 1)){
			printf("-1\n");
			return 0;
		}
		if (cnt == 0){
			printf("1\n%d\n%d\n", m, m - 1);
			v[m] = true;
			cnt = 0;
			euler(a);
			for (int i = 0; i < cnt; i++) printf("%d ", ans[i]);
		} else if (cnt == 2){
			int x = px[head[odd[0]]];
			printf("1\n%d\n%d\n", (head[odd[0]] + 1) >> 1, m - 1);
			v[(head[odd[0]] + 1) >> 1] = true;
			cnt = 0;
			euler(x);
			for (int i = 0; i < cnt; i++) printf("%d ", ans[i]);
		} else{
			px[m + m + 1] = odd[1]; next[m + m + 1] = head[odd[0]]; head[odd[0]] = m + m + 1;
			px[m + m + 2] = odd[0]; next[m + m + 2] = head[odd[1]]; head[odd[1]] = m + m + 2;
			cnt = 0;
			euler(odd[2]);
			cnt = 0;
			for (int i = 0; i <= m; i++) if (ans[i] > m){
				printf("%d\n", i);
				for (int j = 0; j < i; j++) printf("%d ", ans[j]);
				printf("\n%d\n", m - i);
				for (int j = i + 1; j <= m; j++) printf("%d ", ans[j]);
				break;
			}
		}
	}else{
		for (int i = 1; i < maxn; i++) if (exist[i] && (d[i] & 1)) fa[getanc(i)]--;
		for (int i = 1; i < maxn; i++)
			if ((fa[i] <= 0 && fa[i] % 2 != 0) || fa[i] < -2){
				printf("-1\n");
				return 0;
			}
		for (int i = 1; i < maxn; i++)
			if (exist[i] && fa[i] == 0){
				cnt = 0;
				euler(i);
				printf("%d\n", cnt);
				for (int i = 0; i < cnt; i++) printf("%d ", ans[i]);
				printf("\n");
			}
		for (int i = 1; i < maxn; i++){
			if ((d[i] & 1) && fa[getanc(i)] < 0){
				cnt = fa[getanc(i)] = 0;
				euler(i);
				printf("%d\n", cnt);
				for (int i = 0; i < cnt; i++) printf("%d ", ans[i]);
				printf("\n");
			}
		}
	}
}


#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]];
			}
		}

		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;
		}
	} 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, 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);
				pap[make_pair(j,i)].erase(pap[make_pair(j,i)].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);
			pap[make_pair(j,i)].erase(pap[make_pair(j,i)].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);
			pap[make_pair(j,i)].erase(pap[make_pair(j,i)].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);
			pap[make_pair(j,i)].erase(pap[make_pair(j,i)].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);
			pap[make_pair(j,i)].erase(pap[make_pair(j,i)].end()-1);
			i = j;
		}
	}

	// imprime resposta
	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 <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;
set< pair<int, int> > adj[NN];
vector< vector<int> > ans;
vector<int> odd, path;

void find_tour(int u) {
	while(!adj[u].empty()) {
		int v = adj[u].begin()->first, p = adj[u].begin()->second;
		adj[u].erase(make_pair(v, p));
		adj[v].erase(make_pair(u, p));
		find_tour(v);
		path.push_back(p);
	}
}

void split(vector<int> path) {
	int i, j;
	for(i = 0, j = 0; i < (int)path.size(); i++) {
		if(path[i] == -1) {
			if(j == i) j++;
			else {
				ans.push_back(vector<int>(path.begin()+j, path.begin()+j));
				j = i+1;
			}
		}
	}
	if(i == (int)path.size() && j < i)
		ans.push_back(vector<int>(path.begin()+j, path.begin()+i));
}

int main(void) {
	int i, j;

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

	n = 0;
	scanf("%d", &m);
	for(i = 1; i <= m; i++) {
		int a, b;
		scanf("%d %d", &a, &b), n = max(n, max(a--, b--));
		adj[a].insert(make_pair(b, i));
		adj[b].insert(make_pair(a, i));
	}
	for(i = 0; i < n; i++)
		if(adj[i].size()%2)
			odd.push_back(i);
	if(odd.size() != 0 && odd.size() != 2 && odd.size() != 4) {
		printf("-1\n");
		return 0;
	}
	for(i = 0; i < (int)odd.size(); i += 2)
		adj[odd[i]].insert(make_pair(odd[i+1], -1)), adj[odd[i+1]].insert(make_pair(odd[i], -1));
	for(i = 0; i < n; i++) {
		path.clear();
		find_tour(i);
		if(path.size()) split(path);
	}
	if(ans.size() == 1 && ans[0].size() > 1) {
		ans.push_back(vector<int>(ans[0].begin(), ans[0].begin()+1));
		ans.push_back(vector<int>(ans[0].begin()+1, ans[0].begin()+ans[0].size()));
		ans.erase(ans.begin());
	}

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

	return 0;
}


#include <vector>
#include <set>
#include <cstdio>

#define NN 11234

using namespace std;

int n, m;
set< pair<int, int> > adj[NN];
vector< vector<int> > ans;
vector<int> odd, path;

void find_tour(int u) {
	while(!adj[u].empty()) {
		int v = adj[u].begin()->first, p = adj[u].begin()->second;
		adj[u].erase(make_pair(v, p));
		adj[v].erase(make_pair(u, p));
		find_tour(v);
		path.push_back(p);
	}
}

void split(vector<int> path) {
	int i, j, n = path.size();
	vector<int> cur;
	for(i = n-1; i && path[i] != -1; i--);
	for(j = 0; j < n; i++, j++) {
		if(path[i%n] == -1) {
			if(cur.size()) ans.push_back(cur);
			cur.clear();
		} else cur.push_back(path[i%n]);
	}
	if(cur.size()) ans.push_back(cur);
}

int main(void) {
	int i, j;

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

	n = 0;
	scanf("%d", &m);
	for(i = 1; i <= m; i++) {
		int a, b;
		scanf("%d %d", &a, &b), n = max(n, max(a--, b--));
		adj[a].insert(make_pair(b, i));
		adj[b].insert(make_pair(a, i));
	}
	for(i = 0; i < n; i++)
		if(adj[i].size()%2)
			odd.push_back(i);
	for(i = 0; i < (int)odd.size(); i += 2)
		adj[odd[i]].insert(make_pair(odd[i+1], -1)), adj[odd[i+1]].insert(make_pair(odd[i], -1));
	for(i = 0; i < n; i++) {
		find_tour(i);
		if(path.size()) split(path), path.clear();
	}
	if(ans.size() == 1 && ans[0].size() > 1) {
		ans.push_back(vector<int>(ans[0].begin(), ans[0].begin()+1));
		ans.push_back(vector<int>(ans[0].begin()+1, ans[0].begin()+ans[0].size()));
		ans.erase(ans.begin());
	}

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

	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);
				pap[make_pair(j,i)].erase(pap[make_pair(j,i)].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);
			pap[make_pair(j,i)].erase(pap[make_pair(j,i)].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);
			pap[make_pair(j,i)].erase(pap[make_pair(j,i)].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);
			pap[make_pair(j,i)].erase(pap[make_pair(j,i)].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);
			pap[make_pair(j,i)].erase(pap[make_pair(j,i)].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 <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;
set< pair<int, int> > adj[NN];
vector< vector<int> > ans;
vector<int> odd, path;

void find_tour(int u) {
	while(!adj[u].empty()) {
		int v = adj[u].begin()->first, p = adj[u].begin()->second;
		adj[u].erase(make_pair(v, p));
		adj[v].erase(make_pair(u, p));
		find_tour(v);
		path.push_back(p);
	}
}

void split(vector<int> path) {
	int i, j, n = path.size();
	vector<int> cur;
	for(i = n-1; i && path[i] != -1; i--);
	for(j = 0; j < n; i++, j++) {
		if(path[i%n] == -1) {
			if(cur.size()) ans.push_back(cur);
			cur.clear();
		} else cur.push_back(path[i%n]);
	}
	if(cur.size()) ans.push_back(cur);
}

int main(void) {
	int i, j;

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

	n = 0;
	scanf("%d", &m);
	for(i = 1; i <= m; i++) {
		int a, b;
		scanf("%d %d", &a, &b), n = max(n, max(a--, b--));
		adj[a].insert(make_pair(b, i));
		adj[b].insert(make_pair(a, i));
	}
	for(i = 0; i < n; i++)
		if(adj[i].size()%2)
			odd.push_back(i);
	if(odd.size() != 0 && odd.size() != 2 && odd.size() != 4) {
		printf("-1\n");
		return 0;
	}
	for(i = 0; i < (int)odd.size(); i += 2)
		adj[odd[i]].insert(make_pair(odd[i+1], -1)), adj[odd[i+1]].insert(make_pair(odd[i], -1));
	for(i = 0; i < n; i++) {
		path.clear();
		find_tour(i);
		if(path.size()) split(path);
	}
	if(ans.size() == 1 && ans[0].size() > 1) {
		ans.push_back(vector<int>(ans[0].begin(), ans[0].begin()+1));
		ans.push_back(vector<int>(ans[0].begin()+1, ans[0].begin()+ans[0].size()));
		ans.erase(ans.begin());
	}

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

	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) 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;
set< pair<int, int> > adj[NN];
vector< vector<int> > ans;
vector<int> odd, path;

void find_tour(int u) {
	while(!adj[u].empty()) {
		int v = adj[u].begin()->first, p = adj[u].begin()->second;
		adj[u].erase(make_pair(v, p));
		adj[v].erase(make_pair(u, p));
		find_tour(v);
		path.push_back(p);
	}
}

void split(vector<int> path) {
	int i, j, n = path.size();
	vector<int> cur;
	for(i = n-1; i && path[i] != -1; i--);
	for(j = 0; j < n; i++, j++) {
		if(path[i%n] == -1) {
			if(cur.size()) ans.push_back(cur);
			cur.clear();
		} else cur.push_back(path[i%n]);
	}
	if(cur.size()) ans.push_back(cur);
}

int main(void) {
	int i, j;

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

	n = 0;
	scanf("%d", &m);
	for(i = 1; i <= m; i++) {
		int a, b;
		scanf("%d %d", &a, &b), n = max(n, max(a--, b--));
		adj[a].insert(make_pair(b, i));
		adj[b].insert(make_pair(a, i));
	}
	for(i = 0; i < n; i++)
		if(adj[i].size()%2)
			odd.push_back(i);
	for(i = 0; i < (int)odd.size(); i += 2)
		adj[odd[i]].insert(make_pair(odd[i+1], -1)), adj[odd[i+1]].insert(make_pair(odd[i], -1));
	for(i = 0; i < n; i++) {
		path.clear();
		find_tour(i);
		if(path.size()) split(path);
	}
	if(ans.size() == 1 && ans[0].size() > 1) {
		ans.push_back(vector<int>(ans[0].begin(), ans[0].begin()+1));
		ans.push_back(vector<int>(ans[0].begin()+1, ans[0].begin()+ans[0].size()));
		ans.erase(ans.begin());
	}

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

	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) {
		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;
		}
	} 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;
set< pair<int, int> > adj[NN];
vector< vector<int> > ans;
vector<int> odd, path;

void find_tour(int u) {
	while(!adj[u].empty()) {
		int v = adj[u].begin()->first, p = adj[u].begin()->second;
		adj[u].erase(make_pair(v, p));
		adj[v].erase(make_pair(u, p));
		find_tour(v);
		path.push_back(p);
	}
}

void split(vector<int> path) {
	int i, j;
	for(i = 0, j = 0; i < (int)path.size(); i++) {
		if(path[i] == -1) {
			if(j == i) j++;
			else {
				ans.push_back(vector<int>(path.begin()+j, path.begin()+i));
				j = i+1;
			}
		}
	}
	if(i == (int)path.size() && j < i)
		ans.push_back(vector<int>(path.begin()+j, path.begin()+i));
}

int main(void) {
	int i, j;

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

	n = 0;
	scanf("%d", &m);
	for(i = 1; i <= m; i++) {
		int a, b;
		scanf("%d %d", &a, &b), n = max(n, max(a--, b--));
		adj[a].insert(make_pair(b, i));
		adj[b].insert(make_pair(a, i));
	}
	for(i = 0; i < n; i++)
		if(adj[i].size()%2)
			odd.push_back(i);
	if(odd.size() != 0 && odd.size() != 2 && odd.size() != 4) {
		printf("-1\n");
		return 0;
	}
	for(i = 0; i < (int)odd.size(); i += 2)
		adj[odd[i]].insert(make_pair(odd[i+1], -1)), adj[odd[i+1]].insert(make_pair(odd[i], -1));
	for(i = 0; i < n; i++) {
		path.clear();
		find_tour(i);
		if(path.size()) split(path);
	}
	if(ans.size() == 1 && ans[0].size() > 1) {
		ans.push_back(vector<int>(ans[0].begin(), ans[0].begin()+1));
		ans.push_back(vector<int>(ans[0].begin()+1, ans[0].begin()+ans[0].size()));
		ans.erase(ans.begin());
	}

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

	return 0;
}