using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;
using Library;

namespace Program
{
    public static class CODEFORCES2
    {
        static bool SAIKI = false;
        static public int numberOfRandomCases = 0;
        static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker)
        {
        }
        static public void Solve()
        {
            var t = NN;
            for (var i = 0; i < t; i++)
            {
                var n = NN;
                var sum = 1L;
                var zouka = 1L;
                var ans = new List<long>();
                while (sum < n)
                {
                    ans.Add(zouka);
                    zouka <<= 1;
                    sum += zouka;
                }
                ans.RemoveAt(ans.Count - 1);
                sum -= zouka;
                if (sum + zouka / 2 <= n)
                {
                    ans.Add(n - sum - zouka / 2);
                    Console.WriteLine(ans.Count);
                    Console.WriteLine(string.Join(" ", ans));
                }
                else
                {
                    ans.RemoveAt(ans.Count - 1);
                    zouka >>= 1;
                    sum -= zouka;
                    ans.Add(zouka / 2);
                    sum += ans.Last();
                    ans.Add(n - sum - zouka / 2);
                    Console.WriteLine(ans.Count);
                    Console.WriteLine(string.Join(" ", ans));
                }
            }
        }
        class Printer : StreamWriter
        {
            public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
            public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; }
            public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; }
        }
        static LIB_FastIO fastio = new LIB_FastIODebug();
        static public void Main(string[] args) { if (args.Length == 0) { fastio = new LIB_FastIO(); Console.SetOut(new Printer(Console.OpenStandardOutput())); } if (SAIKI) { var t = new Thread(Solve, 134217728); t.Start(); t.Join(); } else Solve(); Console.Out.Flush(); }
        static long NN => fastio.Long();
        static double ND => fastio.Double();
        static string NS => fastio.Scan();
        static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
        static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
        static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
        static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred);
        static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n);
        static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c);
        static IOrderedEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x, _ => xorshift);
        static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x.OrderByRand(), e => e);
        static IOrderedEnumerable<T1> OrderBy<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderBy(x.OrderByRand(), selector);
        static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x) => Enumerable.OrderByDescending(x.OrderByRand(), e => e);
        static IOrderedEnumerable<T1> OrderByDescending<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderByDescending(x.OrderByRand(), selector);
        static IOrderedEnumerable<string> OrderBy(this IEnumerable<string> x) => x.OrderByRand().OrderBy(e => e, StringComparer.OrdinalIgnoreCase);
        static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderBy(selector, StringComparer.OrdinalIgnoreCase);
        static IOrderedEnumerable<string> OrderByDescending(this IEnumerable<string> x) => x.OrderByRand().OrderByDescending(e => e, StringComparer.OrdinalIgnoreCase);
        static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderByDescending(selector, StringComparer.OrdinalIgnoreCase);
        static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } }
        static IEnumerator<uint> _xsi = _xsc();
        static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } }
    }
}
namespace Library {
    class LIB_FastIO
    {
        public LIB_FastIO() { str = Console.OpenStandardInput(); }
        readonly Stream str;
        readonly byte[] buf = new byte[1024];
        int len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream { get { return isEof; } }
        byte read()
        {
            if (isEof) throw new EndOfStreamException();
            if (ptr >= len)
            {
                ptr = 0;
                if ((len = str.Read(buf, 0, 1024)) <= 0)
                {
                    isEof = true;
                    return 0;
                }
            }
            return buf[ptr++];
        }
        char Char()
        {
            byte b = 0;
            do b = read();
            while (b < 33 || 126 < b);
            return (char)b;
        }
        virtual public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
        virtual public long Long()
        {
            long ret = 0; byte b = 0; var ng = false;
            do b = read();
            while (b != '-' && (b < '0' || '9' < b));
            if (b == '-') { ng = true; b = read(); }
            for (; true; b = read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = ret * 10 + b - '0';
            }
        }
        virtual public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); }
    }
    class LIB_FastIODebug : LIB_FastIO
    {
        Queue<string> param = new Queue<string>();
        string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); }
        public LIB_FastIODebug() { }
        public override string Scan() => NextString();
        public override long Long() => long.Parse(NextString());
        public override double Double() => double.Parse(NextString());
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;
using Library;

namespace Program
{
    public static class CODEFORCES2
    {
        static bool SAIKI = false;
        static public int numberOfRandomCases = 0;
        static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker)
        {
        }
        static public void Solve()
        {
            var t = NN;
            for (var i = 0; i < t; i++)
            {
                var n = NN;
                var sum = 1L;
                var zouka = 1L;
                var ans = new List<long>();
                while (sum < n)
                {
                    ans.Add(zouka);
                    zouka <<= 1;
                    sum += zouka;
                }
                ans.RemoveAt(ans.Count - 1);
                sum -= zouka;
                if (sum + zouka / 2 <= n)
                {
                    ans.Add(n - sum - zouka / 2);
                    Console.WriteLine(ans.Count);
                    Console.WriteLine(string.Join(" ", ans));
                }
                else
                {
                    ans.RemoveAt(ans.Count - 1);
                    zouka >>= 1;
                    sum -= zouka;
                    ans.Add(0);
                    sum += zouka / 2;
                    ans.Add(n - sum - zouka / 2);
                    Console.WriteLine(ans.Count);
                    Console.WriteLine(string.Join(" ", ans));
                }
            }
        }
        class Printer : StreamWriter
        {
            public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
            public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; }
            public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; }
        }
        static LIB_FastIO fastio = new LIB_FastIODebug();
        static public void Main(string[] args) { if (args.Length == 0) { fastio = new LIB_FastIO(); Console.SetOut(new Printer(Console.OpenStandardOutput())); } if (SAIKI) { var t = new Thread(Solve, 134217728); t.Start(); t.Join(); } else Solve(); Console.Out.Flush(); }
        static long NN => fastio.Long();
        static double ND => fastio.Double();
        static string NS => fastio.Scan();
        static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
        static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
        static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
        static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred);
        static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n);
        static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c);
        static IOrderedEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x, _ => xorshift);
        static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x.OrderByRand(), e => e);
        static IOrderedEnumerable<T1> OrderBy<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderBy(x.OrderByRand(), selector);
        static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x) => Enumerable.OrderByDescending(x.OrderByRand(), e => e);
        static IOrderedEnumerable<T1> OrderByDescending<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderByDescending(x.OrderByRand(), selector);
        static IOrderedEnumerable<string> OrderBy(this IEnumerable<string> x) => x.OrderByRand().OrderBy(e => e, StringComparer.OrdinalIgnoreCase);
        static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderBy(selector, StringComparer.OrdinalIgnoreCase);
        static IOrderedEnumerable<string> OrderByDescending(this IEnumerable<string> x) => x.OrderByRand().OrderByDescending(e => e, StringComparer.OrdinalIgnoreCase);
        static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderByDescending(selector, StringComparer.OrdinalIgnoreCase);
        static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } }
        static IEnumerator<uint> _xsi = _xsc();
        static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } }
    }
}
namespace Library {
    class LIB_FastIO
    {
        public LIB_FastIO() { str = Console.OpenStandardInput(); }
        readonly Stream str;
        readonly byte[] buf = new byte[1024];
        int len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream { get { return isEof; } }
        byte read()
        {
            if (isEof) throw new EndOfStreamException();
            if (ptr >= len)
            {
                ptr = 0;
                if ((len = str.Read(buf, 0, 1024)) <= 0)
                {
                    isEof = true;
                    return 0;
                }
            }
            return buf[ptr++];
        }
        char Char()
        {
            byte b = 0;
            do b = read();
            while (b < 33 || 126 < b);
            return (char)b;
        }
        virtual public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
        virtual public long Long()
        {
            long ret = 0; byte b = 0; var ng = false;
            do b = read();
            while (b != '-' && (b < '0' || '9' < b));
            if (b == '-') { ng = true; b = read(); }
            for (; true; b = read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = ret * 10 + b - '0';
            }
        }
        virtual public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); }
    }
    class LIB_FastIODebug : LIB_FastIO
    {
        Queue<string> param = new Queue<string>();
        string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); }
        public LIB_FastIODebug() { }
        public override string Scan() => NextString();
        public override long Long() => long.Parse(NextString());
        public override double Double() => double.Parse(NextString());
    }
}


using System;
using System.Collections.Generic;
using System.Linq;

namespace ContestTemplateStartUp
{
    class Program
    {
        public static int GetPower_(int num, int power)
        {
            if (power == 0) return 1;
            if (power == 1) return num;
            var prev = GetPower_(num, power / 2);
            var prev2 = ((long)prev * prev);
            if (power % 2 != 0) return (int)((prev2 * num));
            return (int)prev2;
        }
        static void Main(string[] args)
        {
            var results = new List<List<int>>();
            foreach (var t in Enumerable.Range(0, int.Parse(Console.ReadLine())))
            {
                int n = (int) GetInt();
                int mas = 1;
                int count = 1;
                var ans = new List<int>() { 0 };
                for (int index = 1; index < n; index++)
                {
                    if (mas + 2 * count >= n) {
                        ans[0] = index;
                        var rest = n - mas;
                        if (rest == 0)
                        {
                            ans.Add(2 * count);
                        } else if (rest >= count)
                        {
                            ans.Add(rest);
                        }
                        else
                        {
                            var j = 1;
                            while (rest < ans[j]) { ++j; }
                            ans.Insert(j, rest);
                        }

                        break;
                    }
                    else
                    {
                        var newCount = 2 * count;
                        var newMas = mas + newCount;
                        mas = newMas;
                        count = newCount;
                        ans.Add(newCount);
                    }
                }
                results.Add(ans);
            }

            foreach (var result in results)
            {
                Console.WriteLine(result[0]);
                var prev = 1;
                for (int index = 1; index < result.Count; index++)
                {
                    Console.Write($"{result[index] - prev} ");
                    prev = result[index];
                }
                Console.WriteLine();
            }
        }

        static int GetInt()
        {
            int integer = 0;
            int n = Console.Read();
            while (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
                n = Console.Read();
            while (n >= '0' && n <= '9')
            {
                integer = integer * 10 + n - '0';
                n = Console.Read();
            }
            return integer;
        }
        static int[] ReadArray(int count)
        {
            int[] arr = new int[count];
            for (var index = 0; index < count; ++index)
            {
                arr[index] = GetInt();
            }
            return arr;

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;

namespace ContestTemplateStartUp
{
    class Program
    {
        public static int GetPower_(int num, int power)
        {
            if (power == 0) return 1;
            if (power == 1) return num;
            var prev = GetPower_(num, power / 2);
            var prev2 = ((long)prev * prev);
            if (power % 2 != 0) return (int)((prev2 * num));
            return (int)prev2;
        }
        static void Main(string[] args)
        {
            var results = new List<List<int>>();

            foreach (var t in Enumerable.Range(0, int.Parse(Console.ReadLine())))
            //foreach (var t in Enumerable.Range(0, 1000))
            {
              int n = (int) GetInt();
              //int n = t + 2;
                int mas = 1;
                int count = 1;
                var ans = new List<int>() { 0 };
                for (int index = 1; index < n; index++)
                {
                    if (mas + 2 * count >= n) {
                        ans[0] = index;
                        var rest = n - mas;
                        if (rest == 0)
                        {
                            ans.Add(2 * count);
                        } else if (rest >= count)
                        {
                            ans.Add(rest);
                        }
                        else
                        {
                            if (rest != 1) {
                                var j = 1;
                                while (rest > ans[j]) { ++j; }
                                ans.Insert(j, rest);
                            }
                            else
                            {
                                ans.Insert(1, 1);
                            }

                        }

                        break;
                    }
                    else
                    {
                        var newCount = 2 * count;
                        var newMas = mas + newCount;
                        mas = newMas;
                        count = newCount;
                        ans.Add(newCount);
                    }
                }
                results.Add(ans);
            }
            int num = 1;

            foreach (var result in results)
            {
                Console.WriteLine(result[0]);

                var prev = 1;
                for (int index = 1; index < result.Count; index++)
                {
                    Console.Write($"{result[index] - prev} ");
                    prev = result[index];
                }
                num++;
                Console.WriteLine();
            }
        }

        static int GetInt()
        {
            int integer = 0;
            int n = Console.Read();
            while (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
                n = Console.Read();
            while (n >= '0' && n <= '9')
            {
                integer = integer * 10 + n - '0';
                n = Console.Read();
            }
            return integer;
        }
        static int[] ReadArray(int count)
        {
            int[] arr = new int[count];
            for (var index = 0; index < count; ++index)
            {
                arr[index] = GetInt();
            }
            return arr;

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;

namespace ContestTemplateStartUp
{
    class Program
    {
        public static int GetPower_(int num, int power)
        {
            if (power == 0) return 1;
            if (power == 1) return num;
            var prev = GetPower_(num, power / 2);
            var prev2 = ((long)prev * prev);
            if (power % 2 != 0) return (int)((prev2 * num));
            return (int)prev2;
        }
        static void Main(string[] args)
        {
            var results = new List<List<int>>();

            foreach (var t in Enumerable.Range(0, int.Parse(Console.ReadLine())))
            //foreach (var t in Enumerable.Range(0, 1000))
            {
                int n = (int) GetInt();
                //int n = t + 2;
                int mas = 1;
                int count = 1;
                var ans = new List<int>() { 0 };
                for (int index = 1; index < n; index++)
                {
                    if (mas + 2 * count >= n) {
                        ans[0] = index;
                        var rest = n - mas;
                        if (rest == 0)
                        {
                            ans.Add(2 * count);
                        } else if (rest >= count)
                        {
                            ans.Add(rest);
                        }
                        else
                        {
                            var j = 1;
                            if (rest != 1) {
                                while (rest < ans[j]) { ++j; }
                            }
                            ans.Insert(j+1, rest);
                        }

                        break;
                    }
                    else
                    {
                        var newCount = 2 * count;
                        var newMas = mas + newCount;
                        mas = newMas;
                        count = newCount;
                        ans.Add(newCount);
                    }
                }
                results.Add(ans);
            }

            foreach (var result in results)
            {
                Console.WriteLine(result[0]);
                var prev = 1;
                for (int index = 1; index < result.Count; index++)
                {
                    Console.Write($"{result[index] - prev} ");
                    prev = result[index];
                }
                Console.WriteLine();
            }
        }

        static int GetInt()
        {
            int integer = 0;
            int n = Console.Read();
            while (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
                n = Console.Read();
            while (n >= '0' && n <= '9')
            {
                integer = integer * 10 + n - '0';
                n = Console.Read();
            }
            return integer;
        }
        static int[] ReadArray(int count)
        {
            int[] arr = new int[count];
            for (var index = 0; index < count; ++index)
            {
                arr[index] = GetInt();
            }
            return arr;

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;

namespace ContestTemplateStartUp
{
    class Program
    {
        public static int GetPower_(int num, int power)
        {
            if (power == 0) return 1;
            if (power == 1) return num;
            var prev = GetPower_(num, power / 2);
            var prev2 = ((long)prev * prev);
            if (power % 2 != 0) return (int)((prev2 * num));
            return (int)prev2;
        }
        static void Main(string[] args)
        {
            var results = new List<List<int>>();

            foreach (var t in Enumerable.Range(0, int.Parse(Console.ReadLine())))
            //foreach (var t in Enumerable.Range(0, 1000))
            {
                int n = (int) GetInt();
                //int n = t + 2;
                int mas = 1;
                int count = 1;
                var ans = new List<int>() { 0 };
                for (int index = 1; index < n; index++)
                {
                    if (mas + 2 * count >= n) {
                        ans[0] = index;
                        var rest = n - mas;
                        if (rest == 0)
                        {
                            ans.Add(2 * count);
                        } else if (rest >= count)
                        {
                            ans.Add(rest);
                        }
                        else
                        {
                            if (rest != 1) {
                                var j = 1;
                                while (rest < ans[j]) { ++j; }
                                ans.Insert(j + 1, rest);
                            }
                            else
                            {
                                ans.Insert(1, 1);
                            }

                        }

                        break;
                    }
                    else
                    {
                        var newCount = 2 * count;
                        var newMas = mas + newCount;
                        mas = newMas;
                        count = newCount;
                        ans.Add(newCount);
                    }
                }
                results.Add(ans);
            }
            int num = 1;

            foreach (var result in results)
            {
                Console.WriteLine(result[0]);

                var prev = 1;
                for (int index = 1; index < result.Count; index++)
                {
                    Console.Write($"{result[index] - prev} ");
                    prev = result[index];
                }
                num++;
                Console.WriteLine();
            }
        }

        static int GetInt()
        {
            int integer = 0;
            int n = Console.Read();
            while (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
                n = Console.Read();
            while (n >= '0' && n <= '9')
            {
                integer = integer * 10 + n - '0';
                n = Console.Read();
            }
            return integer;
        }
        static int[] ReadArray(int count)
        {
            int[] arr = new int[count];
            for (var index = 0; index < count; ++index)
            {
                arr[index] = GetInt();
            }
            return arr;

        }
    }
}


macro_rules! input {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    let stdin = std::io::stdin();
    let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
    let mut next = move || -> String{
        bytes
            .by_ref()
            .map(|r|r.unwrap() as char)
            .skip_while(|c|c.is_whitespace())
            .take_while(|c|!c.is_whitespace())
            .collect()
    };
    input! {next,
        ts: usize,
    }
    for _ in 0..ts {
        input! {next,
            n: u64,
        }
        // 1001 -> 1 + 2 + 2 + 4
        // 1011 -> 1 + 2 + 3 + 5
        // 1+2+4+8+16+...
        let mut num = 0;
        let mut arr = Vec::new();
        for i in 0.. {
            num += 1 << i;
            arr.push(1 << i);
            if num >= n {
                break;
            }
        }

        // dbg!(&arr);
        let mut pos = arr.len() - 1;
        while num > n {
            num -= arr[pos] - arr[pos-1];
            arr[pos] = arr[pos-1];
            pos -= 1;
        }
        if num < n {
            pos += 1;
            arr[pos] += n - num;
        }
        let ans: Vec<_> = arr.iter().zip(arr.iter().skip(1)).map(|(i,j)| j - i).collect();
        let z = ans.iter().map(|x| format!("{} ", x)).collect::<String>();
        println!("{}", ans.len());
        println!("{}", z);
    }
}


use std::io::{ self, Write, BufWriter };
use std::str::{ self, SplitAsciiWhitespace };

/// Copied from https://github.com/EbTech/rust-algorithms/blob/master/src/scanner.rs
/// Same API as Scanner but nearly twice as fast, using horribly unsafe dark arts
/// **REQUIRES** Rust 1.34 or higher
pub struct UnsafeScanner<R> {
    reader: R,
    buf_str: Vec<u8>,
    buf_iter: SplitAsciiWhitespace<'static>,
}

impl<R: io::BufRead> UnsafeScanner<R> {
    pub fn new(reader: R) -> Self {
        Self {
            reader,
            buf_str: vec![],
            buf_iter: "".split_ascii_whitespace(),
        }
    }

    /// This function should be marked unsafe, but noone has time for that in a
    /// programming contest. Use at your own risk!
    pub fn token<T: str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buf_iter.next() {
                return token.parse().ok().expect("Failed parse");
            }
            self.buf_str.clear();
            self.reader
                .read_until(b'\n', &mut self.buf_str)
                .expect("Failed read");
            self.buf_iter = unsafe {
                let slice = str::from_utf8_unchecked(&self.buf_str);
                std::mem::transmute(slice.split_ascii_whitespace())
            }
        }
    }

    pub fn pair<T: str::FromStr>(&mut self) -> (T, T) {
        (self.token(), self.token())
    }
}

// That's a really cool clamp!
fn next(lo: i32, hi: i32, target: i32, repeat: i32) -> i32 {
    (target / repeat).max(lo).min(hi)
}

fn solve(mut x: i32) -> Option<Vec<i32>> {
    let k = 31 - x.leading_zeros() as usize;

    let mut delta = vec![0_i32; k+1];
    delta[0] = 1;
    x -= 1;
    for i in 1..=k {
        delta[i] = next(delta[i-1], 2*delta[i-1], x, (k-i+1) as i32);
        x -= delta[i];
    }

    let splits: Vec<_> = (0..k).map(|i| delta[i+1] - delta[i]).collect();
    Some(splits)
}

fn main() {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let mut scan = UnsafeScanner::new(stdin.lock());
    let mut out = BufWriter::new(stdout.lock());

    let t: i32 = scan.token();
    for _ in 0..t {
        let n: i32 = scan.token();
        match solve(n) {
            None => { writeln!(out, "-1").ok(); },
            Some(v) => {
                writeln!(out, "{}", v.len()).ok();
                for x in v {
                    write!(out, "{} ", x).ok();
                }
                writeln!(out, "").ok();
            }
        }
    }
}


use std::io::{ self, Write, BufWriter };
use std::str::{ self, SplitAsciiWhitespace };

/// Copied from https://github.com/EbTech/rust-algorithms/blob/master/src/scanner.rs
/// Same API as Scanner but nearly twice as fast, using horribly unsafe dark arts
/// **REQUIRES** Rust 1.34 or higher
pub struct UnsafeScanner<R> {
    reader: R,
    buf_str: Vec<u8>,
    buf_iter: SplitAsciiWhitespace<'static>,
}

impl<R: io::BufRead> UnsafeScanner<R> {
    pub fn new(reader: R) -> Self {
        Self {
            reader,
            buf_str: vec![],
            buf_iter: "".split_ascii_whitespace(),
        }
    }

    /// This function should be marked unsafe, but noone has time for that in a
    /// programming contest. Use at your own risk!
    pub fn token<T: str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buf_iter.next() {
                return token.parse().ok().expect("Failed parse");
            }
            self.buf_str.clear();
            self.reader
                .read_until(b'\n', &mut self.buf_str)
                .expect("Failed read");
            self.buf_iter = unsafe {
                let slice = str::from_utf8_unchecked(&self.buf_str);
                std::mem::transmute(slice.split_ascii_whitespace())
            }
        }
    }

    pub fn pair<T: str::FromStr>(&mut self) -> (T, T) {
        (self.token(), self.token())
    }
}

fn next(lo: i32, hi: i32, target: i32, repeat: i32) -> i32 {
    (target / repeat).max(lo).min(hi)
}

fn solve(mut x: i32) -> Option<Vec<i32>> {
    let k = 31 - x.leading_zeros() as usize;

    let mut delta = vec![0_i32; k+1];
    delta[0] = 1;
    x -= 1;
    for i in 1..=k {
        delta[i] = next(delta[i-1], 2*delta[i-1], x, (k-i+1) as i32);
        x -= delta[i];
    }

    let splits: Vec<_> = (0..k).map(|i| delta[i+1] - delta[i]).collect();
    Some(splits)
}

fn main() {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let mut scan = UnsafeScanner::new(stdin.lock());
    let mut out = BufWriter::new(stdout.lock());

    let t: i32 = scan.token();
    for _ in 0..t {
        let n: i32 = scan.token();
        match solve(n) {
            None => { writeln!(out, "-1").ok(); },
            Some(v) => {
                writeln!(out, "{}", v.len()).ok();
                for x in v {
                    write!(out, "{} ", x).ok();
                }
                writeln!(out, "").ok();
            }
        }
    }
}


use std::io::{ self, Write, BufWriter };
use std::str::{ self, SplitAsciiWhitespace };

/// Copied from https://github.com/EbTech/rust-algorithms/blob/master/src/scanner.rs
/// Same API as Scanner but nearly twice as fast, using horribly unsafe dark arts
/// **REQUIRES** Rust 1.34 or higher
pub struct UnsafeScanner<R> {
    reader: R,
    buf_str: Vec<u8>,
    buf_iter: SplitAsciiWhitespace<'static>,
}

impl<R: io::BufRead> UnsafeScanner<R> {
    pub fn new(reader: R) -> Self {
        Self {
            reader,
            buf_str: vec![],
            buf_iter: "".split_ascii_whitespace(),
        }
    }

    /// This function should be marked unsafe, but noone has time for that in a
    /// programming contest. Use at your own risk!
    pub fn token<T: str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buf_iter.next() {
                return token.parse().ok().expect("Failed parse");
            }
            self.buf_str.clear();
            self.reader
                .read_until(b'\n', &mut self.buf_str)
                .expect("Failed read");
            self.buf_iter = unsafe {
                let slice = str::from_utf8_unchecked(&self.buf_str);
                std::mem::transmute(slice.split_ascii_whitespace())
            }
        }
    }

    pub fn pair<T: str::FromStr>(&mut self) -> (T, T) {
        (self.token(), self.token())
    }
}

fn next(lo: i32, hi: i32, target: i32, repeat: i32) -> i32 {
    let (mut l, mut r) = (lo, hi+1);
    while l < r {
        let x = (l + r) / 2;

        if (x as i64) * (repeat as i64) > (target as i64) {
            r = x;
        } else {
            l = x + 1;
        }
    }

    l - 1
}

fn solve(mut x: i32) -> Option<Vec<i32>> {
    let k = 31 - x.leading_zeros() as usize;

    let mut delta = vec![0_i32; k+1];
    delta[0] = 1;
    x -= 1;
    for i in 1..=k {
        delta[i] = next(delta[i-1], 2*delta[i-1], x, (k-i+1) as i32);
        x -= delta[i];
    }

    let splits: Vec<_> = (0..k).map(|i| delta[i+1] - delta[i]).collect();
    Some(splits)
}

fn main() {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let mut scan = UnsafeScanner::new(stdin.lock());
    let mut out = BufWriter::new(stdout.lock());

    let t: i32 = scan.token();
    for _ in 0..t {
        let n: i32 = scan.token();
        match solve(n) {
            None => { writeln!(out, "-1").ok(); },
            Some(v) => {
                writeln!(out, "{}", v.len()).ok();
                for x in v {
                    write!(out, "{} ", x).ok();
                }
                writeln!(out, "").ok();
            }
        }
    }
}


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

#ifndef DEBUG
#define endl '\n'
#define debug(...)
#else
#define debug(...) __VA_ARGS__
#endif
#define debugf(...) debug(printf(__VA_ARGS__);)

int (((((main)))))() <%
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int t; cin >> t;
    while (t--) {
        auto solve =
    }

    return 0;
%>


use std::io::stdin;
use std::cmp::min;
use std::cmp::max;
fn main() {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let test: u64 = str.trim().parse().unwrap();
    for _ in 0..test {
        str.clear();
        let _ = stdin().read_line(&mut str).unwrap();
        let mut n : i64 = str.trim().parse().unwrap();
        n = n - 1;
        let mut iter = 1;
        let mut count = 0;
        let mut ans = String::new();
        loop {
            if n > 6 * iter {
                ans += &format!("{} ", iter);
                n -= 2 * iter;
                count += 1;
                iter *= 2;
            } else {
                if n <= 2 * iter {
                    println!("{}", count + 1);
                    println!("{}{}", ans, n - iter);
                }
                else if n <= 4 * iter {
                    println!("{}", count + 2);
                    println!("{}{} {}", ans, (n - 2 * iter) / 2, (n - 2 * iter) % 2);
                }
                else {
                    println!("{}", count + 2);
                    println!("{}{} {}", ans, iter, n - 4 * iter);
                }
                break;
            }
        }
    }
}

/*

15
1 -> 2 -> 3
2 -> 4 -> 7
4 -> 8 -> 15

11
1 -> 2 ->3
2 -> 4 -> 7
4 -> 4 -> 11

n > 6x

n - 2x > 4x

69
32
32

100
1
1 -> 2 -> 3
2 -> 4 -> 7
4 -> 8 -> 15
8 -> 16 -> 31
16 -> 32 -> 63
5 -> 37 -> 100

32

8
1
1 -> 2 -> 3
2 -> 0 ->

n = 1
iter = 1

*/


use io::stdin;
use std::{fmt::Debug, io, str::FromStr};

fn solve(k: usize) -> Vec<usize> {
    let mut result = vec![];
    let mut sum = 1;
    let mut appender = 1;
    while sum < k {
        appender <<= 1;
        sum += appender;
        result.push(appender);
    }

    let mut substract = 0;
    for index in 0..result.len() {
        substract *= 2;
        let estimated_subtract = (1 << (result.len() - index)) - 1;
        let mut count = 0;
        while k + estimated_subtract * (count + 1) <= sum {
            count += 1;
        }
        sum -= estimated_subtract * count;
        substract += count;
        result[index] -= substract;
    }

    result.into_iter().scan(1, |acc, num| {
        let diff = num - *acc;
        *acc = num;
        Some(diff)
    }).collect()
}

fn main() {
    let test: usize = read_num();
    for _case in 1..=test {
        let n: usize = read_num();
        let result = solve(n);

        println!("{}", result.len());
        for num in result {
            print!("{} ", num);
        }
        println!();
    }
}

fn read_line() -> String {
    let stdin = stdin();
    let mut buffer = String::new();
    match stdin.read_line(&mut buffer) {
        Ok(_) => buffer.trim().to_owned(),
        Err(_) => panic!("Failed reading line"),
    }
}

fn read_num<T>() -> T
where
    T: Default + FromStr,
    <T as std::str::FromStr>::Err: Debug,
{
    read_line().parse().expect("Num is given")
}

fn read_result<T>() -> Vec<T>
where
    T: Default + FromStr,
    <T as std::str::FromStr>::Err: Debug,
{
    read_line()
        .split_whitespace()
        .map(|x| x.parse().expect("Num is given"))
        .collect()
}


#![allow(unused_imports)]
#![allow(dead_code)]

use std::cmp::{ min, max };
use std::io::{stdin, stdout, BufWriter, Write, Stdout};

#[derive(Default)]
struct Scanner {
    buffer: Vec<String>
}

impl Scanner {
    fn next<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop() {
                return token.parse().ok().unwrap();
            }
            let mut input = String::new();
            stdin().read_line(&mut input).unwrap();
            self.buffer = input.split_ascii_whitespace().rev().map(String::from).collect()
        }
    }
}

fn run_case<T: Write>(scanner: &mut Scanner, writer: &mut BufWriter<T>) {
    let mut n: usize = scanner.next();
    let mut ans: Vec<usize> = Vec::new();
    let mut i: usize = 1;
    while i < n {
        ans.push(i);
        n = n - i;
        i = i + i;
    }
    if n != 0 {
        ans.push(n);
    }
    ans.sort();
    writeln!(writer, "{}", ans.len() - 1).unwrap();
    for i in 1..ans.len() {
        write!(writer, "{} ", ans[i] - ans[i - 1]).unwrap();
    }
    writeln!(writer, "").unwrap();
}

fn run<T: Write>(scanner: &mut Scanner, writer: &mut BufWriter<T>) {
    for _case in 0..scanner.next() {
        run_case(scanner, writer);
    }
}

fn main() {
    let mut scanner = Scanner::default();
    let out = stdout();
    let mut writer = BufWriter::new(out.lock());
    run(&mut scanner, &mut writer);
}


//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// ここまで

use std::io::Write;

fn run() {
    input! {
        t: usize,
        ask: [u64; t],
    }
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    for n in ask {
        let mut ans = vec![];
        let mut now = 1;
        let mut cnt = 1;
        while now + 4 * cnt <= n {
            ans.push(cnt);
            cnt *= 2;
            now += cnt;
        }
        if now + 2 * cnt >= n {
            ans.push(n - now - cnt);
        } else if now + 3 * cnt < n {
            let x = std::cmp::min((n - (now + 2 * cnt)) / 2, cnt);
            ans.push(x);
            cnt += x;
            now += x;
            ans.push(n - now - cnt);
        } else {
            ans.push(0);
            now += cnt;
            if now < n {
                ans.push(n - now - cnt);
            }
        }
        let mut s = String::new();
        s.push_str(&format!("{}\n", ans.len()));
        for a in ans {
            s.push_str(&format!("{} ", a));
        }
        s.pop();
        writeln!(out, "{}", s).ok();
    }
}

fn main() {
    run();
}


//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// ここまで

use std::io::Write;

fn run() {
    input! {
        t: usize,
        ask: [u64; t],
    }
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    for n in ask {
        let mut ans = vec![];
        let mut now = 1;
        let mut cnt = 1;
        while now + 4 * cnt <= n {
            ans.push(cnt);
            cnt *= 2;
            now += cnt;
        }
        ans.push(0);
        now += cnt;
        if now < n {
            ans.push(n - now - cnt);
        }
        let mut s = String::new();
        s.push_str(&format!("{}\n", ans.len()));
        for a in ans {
            s.push_str(&format!("{} ", a));
        }
        s.pop();
        writeln!(out, "{}", s).ok();
    }
}

fn main() {
    run();
}


#include<bits/stdc++.h>
#define ll long long int
#define here cout<<"here\n"
#define pb push_back
#define mp make_pair
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define pf printf
#define pfi(x) printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
using namespace std;

const ll mod = 1e9+7;

const int MAX = 100005;

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

   ll t;
   cin>>t;
   //cout<<t<<endl;
   while(t--)
   {
     ll n,m;
    cin>>n>>m;
    ll v[n+1]={0};
    ll i,j,k,ui,vi;
    for(i=0;i<m;i++)
    {
        cin>>ui>>vi;
        v[ui]++;
        v[vi]++;
    }
    vector<pair<ll,ll > >a;
    //cout<<n/2<<endl;
    for(i=1;i<n+1;i++)
    {
         a.push_back(make_pair(v[i],i));
    }
    sort(a.begin(),a.end());

    cout<<n/2<<endl;
    j=n/2;
    for(i=0;i<j;i++)
       {
        if(i%2==0)
        {
             cout<<a[i].second<<" ";
        }
        else
             cout<<a[j+i].second<<" ";
       }
    cout<<endl;
   }

    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define here cout<<"here\n"
#define pb push_back
#define mp make_pair
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define pf printf
#define pfi(x) printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
using namespace std;

const ll mod = 1e9+7;

const int MAX = 100005;

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

   ll t;
   cin>>t;
   //cout<<t<<endl;
   while(t--)
   {
     ll n,m;
    cin>>n>>m;
    ll v[n+1]={0};
    ll i,j,k,ui,vi;
    for(i=0;i<m;i++)
    {
        cin>>ui>>vi;
        v[ui]++;
        v[vi]++;
    }
    vector<pair<ll,ll > >a;
    cout<<n/2<<endl;
    for(i=1;i<n+1;i++)
    {
         a.push_back(make_pair(v[i],i));
    }
    sort(a.begin(),a.end());

    cout<<(n%2==0?n/2:n/2+1)<<endl;
    j=n%2==0?n/2:n/2+1;
    for(i=0;i<j;i++)
        cout<<a[i].second<<" ";
    cout<<endl;
   }

    return 0;
}


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

vector<vector<int>> adj;
vector<int> choose;
vector<int> vis;

void dfs(int u){

	for(int v : adj[u]){
		if(choose[u] == 0 && choose[v] == -1) choose[v] = 1;
		else if(choose[u] == 1 && choose[v] == -1) choose[v] = 0;
	}

	for(int v : adj[u]){
		if(vis[v] == 0){
			vis[v] = 1;
			dfs(v);
		}
	}
}

void solve(){
	int n, m;
	cin >> n >> m;

	adj.clear();
	choose.clear();
	vis.clear();
	adj.resize(n + 1);
	choose.resize(n + 1, -1);
	vis.resize(n + 1);
	choose[0] = 0;

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

	int s = 0, sm = 1;
	for(int i = 1; i <= n; i++){
		if(adj[i].size() == 1){
			if(choose[i] == 0){
				choose[adj[i][0]] = 1;
				s = adj[i][0];
			}
			vis[i] = 1;
		}
		if(adj[i].size() > adj[sm].size()) sm = i;
	}

	// bfs
	if(s == 0) {
		s = sm;
		choose[s] = 1;
	}
	vis[s] = 1;
	dfs(s);
	cout << count(choose.begin(), choose.end(), 1) << '\n';
	for(int i = 1; i <= n; i++){
		if(choose[i] == 1) cout << i << ' ';
	}
	cout << '\n';
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int t;
	cin >> t;
	while(t--) solve();
}


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

vector<vector<int>> adj;
vector<int> choose;
vector<int> vis;

void dfs(int u){

	for(int v : adj[u]){
		if(choose[u] == 0 && choose[v] == -1) choose[v] = 1;
		else if(choose[u] == 1 && choose[v] == -1) choose[v] = 0;
	}

	for(int v : adj[u]){
		if(vis[v] == 0){
			vis[v] = 1;
			dfs(v);
		}
	}
}

void solve(){
	int n, m;
	cin >> n >> m;

	adj.clear();
	choose.clear();
	vis.clear();
	adj.resize(n + 1);
	choose.resize(n + 1, -1);
	vis.resize(n + 1);
	choose[0] = 0;

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

	int s = 0, sm = 1;
	for(int i = 1; i <= n; i++){
		if(adj[i].size() == 1){
			if(choose[i] == -1){
				choose[i] = 0;
				choose[adj[i][0]] = 1;
				s = adj[i][0];
			}
			vis[i] = 1;
		}
		if(adj[i].size() > adj[sm].size()) sm = i;
	}

	// bfs
	vis[sm] = 1;
	dfs(sm);
	cout << count(choose.begin(), choose.end(), 1) << '\n';
	for(int i = 1; i <= n; i++){
		if(choose[i] == 1) cout << i << ' ';
	}
	cout << '\n';
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int t;
	cin >> t;
	while(t--) solve();
}


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

vector<vector<int>> adj;
vector<int> choose;
vector<int> vis;

void dfs(int u){

	for(int v : adj[u]){
		if(choose[u] == 0 && choose[v] == -1) choose[v] = 1;
		else if(choose[u] == 1 && choose[v] == -1) choose[v] = 0;
	}

	for(int v : adj[u]){
		if(vis[v] == 0){
			vis[v] = 1;
			dfs(v);
		}
	}
}

void solve(){
	int n, m;
	cin >> n >> m;

	adj.clear();
	choose.clear();
	vis.clear();
	adj.resize(n + 1);
	choose.resize(n + 1, -1);
	vis.resize(n + 1);
	choose[0] = 0;

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

	int s = 0, sm = 1;
	for(int i = 1; i <= n; i++){
		if(adj[i].size() == 1){
			if(choose[i] == -1){
				choose[i] = 0;
				choose[adj[i][0]] = 1;
				s = adj[i][0];
			}
			vis[i] = 1;
		}
		if(adj[i].size() > adj[sm].size()) sm = i;
	}

	// bfs
	if(s == 0){
		s = sm;
	}
	vis[s] = 1;
	choose[s] = 1;
	dfs(sm);
	int x = (count(choose.begin(), choose.end(), 1) <= n / 2);
	cout << count(choose.begin(), choose.end(), x) - (x == 0) << '\n';
	for(int i = 1; i <= n; i++){
		if(choose[i] == x) cout << i << ' ';
	}
	cout << '\n';
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int t;
	cin >> t;
	while(t--) solve();
}


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

vector<vector<int>> adj;
vector<int> choose;
vector<int> vis;

void dfs(int u){

	for(int v : adj[u]){
		if(choose[u] == 0 && choose[v] == -1) choose[v] = 1;
		else if(choose[u] == 1 && choose[v] == -1) choose[v] = 0;
	}

	for(int v : adj[u]){
		if(vis[v] == 0){
			vis[v] = 1;
			dfs(v);
		}
	}
}

void solve(){
	int n, m;
	cin >> n >> m;

	adj.clear();
	choose.clear();
	vis.clear();
	adj.resize(n + 1);
	choose.resize(n + 1, -1);
	vis.resize(n + 1);
	choose[0] = 0;

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

	int s = 0, sm = 1;
	for(int i = 1; i <= n; i++){
		if(adj[i].size() == 1){
			if(choose[i] == 0){
				choose[adj[i][0]] = 1;
				s = adj[i][0];
			}
			vis[i] = 1;
		}
		if(adj[i].size() > adj[sm].size()) sm = i;
	}

	// bfs
	if(s == 0) {
		s = sm;
		choose[s] = 1;
	}
	vis[s] = 1;
	dfs(s);
	cout << accumulate(choose.begin(), choose.end(), 0) << '\n';
	for(int i = 1; i <= n; i++){
		if(choose[i] == 1) cout << i << ' ';
	}
	cout << '\n';
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int t;
	cin >> t;
	while(t--) solve();
}


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

vector<vector<int>> adj;
vector<int> choose;
vector<int> vis;

void dfs(int u){

	for(int v : adj[u]){
		if(choose[u] == 0 && choose[v] == -1) choose[v] = 1;
		else if(choose[u] == 1 && choose[v] == -1) choose[v] = 0;
	}

	for(int v : adj[u]){
		if(vis[v] == 0){
			vis[v] = 1;
			dfs(v);
		}
	}
}

void solve(){
	int n, m;
	cin >> n >> m;

	adj.clear();
	choose.clear();
	vis.clear();
	adj.resize(n + 1);
	choose.resize(n + 1, -1);
	vis.resize(n + 1);
	choose[0] = 0;

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

	int s = 0, sm = 1;
	for(int i = 1; i <= n; i++){
		if(adj[i].size() == 1){
			if(choose[i] == -1){
				choose[i] = 0;
				choose[adj[i][0]] = 1;
				s = adj[i][0];
			}
			vis[i] = 1;
		}
		if(adj[i].size() > adj[sm].size()) sm = i;
	}

	// bfs
	vis[sm] = 1;
	choose[sm] = 1;
	dfs(sm);
	cout << count(choose.begin(), choose.end(), 1) << '\n';
	for(int i = 1; i <= n; i++){
		if(choose[i] == 1) cout << i << ' ';
	}
	cout << '\n';
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int t;
	cin >> t;
	while(t--) solve();
}


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

vector<vector<int>> adj;
vector<int> choose;
vector<int> vis;

void dfs(int u){

	for(int v : adj[u]){
		if(choose[u] == 0) choose[v] = 1;
		else if(choose[u] == 1 && choose[v] == -1) choose[v] = 0;
	}

	for(int v : adj[u]){
		if(vis[v] == 0){
			vis[v] = 1;
			dfs(v);
		}
	}
}

void solve(){
	int n, m;
	cin >> n >> m;

	adj.clear();
	choose.clear();
	vis.clear();
	adj.resize(n + 1);
	choose.resize(n + 1, -1);
	vis.resize(n + 1);
	choose[0] = 0;

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

	int s = 0, sm = 1;
	for(int i = 1; i <= n; i++){
		if(adj[i].size() == 1){
			if(choose[i] == -1){
				choose[i] = 0;
				choose[adj[i][0]] = 1;
				s = adj[i][0];
			}
			vis[i] = 1;
		}
		if(adj[i].size() > adj[sm].size()) sm = i;
	}

	// bfs
	if(s == 0){
		s = sm;
	}
	vis[s] = 1;
	choose[s] = 1;
	dfs(sm);
	int x = (count(choose.begin(), choose.end(), 1) <= n / 2);
	cout << count(choose.begin(), choose.end(), x) - (x == 0) << '\n';
	for(int i = 1; i <= n; i++){
		if(choose[i] == x) cout << i << ' ';
	}
	cout << '\n';
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int t;
	cin >> t;
	while(t--) solve();
}


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

vector<vector<int>> adj;
vector<int> choose;
vector<int> vis;

void dfs(int u){

	for(int v : adj[u]){
		if(choose[u] == 0 && choose[v] == -1) choose[v] = 1;
		else if(choose[u] == 1 && choose[v] == -1) choose[v] = 0;
	}

	for(int v : adj[u]){
		if(vis[v] == 0){
			vis[v] = 1;
			dfs(v);
		}
	}
}

void solve(){
	int n, m;
	cin >> n >> m;

	adj.clear();
	choose.clear();
	vis.clear();
	adj.resize(n + 1);
	choose.resize(n + 1, -1);
	vis.resize(n + 1);
	choose[0] = 0;

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

	int s = 0, sm = 1;
	for(int i = 1; i <= n; i++){
		if(adj[i].size() == 1){
			if(choose[i] == -1){
				choose[i] = 0;
				choose[adj[i][0]] = 1;
				s = adj[i][0];
			}
			vis[i] = 1;
		}
		if(adj[i].size() > adj[sm].size()) sm = i;
	}

	// bfs
	vis[sm] = 1;
	choose[sm] = 1;
	dfs(sm);
	int x = (count(choose.begin(), choose.end(), 1) <= n / 2);
	cout << count(choose.begin(), choose.end(), x) - 1 << '\n';
	for(int i = 1; i <= n; i++){
		if(choose[i] == x) cout << i << ' ';
	}
	cout << '\n';
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int t;
	cin >> t;
	while(t--) solve();
}


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

vector<vector<int>> adj;
vector<int> choose;
vector<int> vis;

void dfs(int u){

	for(int v : adj[u]){
		if(choose[u] == 0 && choose[v] == -1) choose[v] = 1;
		else if(choose[u] == 1 && choose[v] == -1) choose[v] = 0;
	}

	for(int v : adj[u]){
		if(vis[v] == 0){
			vis[v] = 1;
			dfs(v);
		}
	}
}

void solve(){
	int n, m;
	cin >> n >> m;

	adj.clear();
	choose.clear();
	vis.clear();
	adj.resize(n + 1);
	choose.resize(n + 1, -1);
	vis.resize(n + 1);
	choose[0] = 0;

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

	int s = 0, sm = 1;
	for(int i = 1; i <= n; i++){
		if(adj[i].size() == 1){
			if(choose[i] == -1){
				choose[i] = 0;
				choose[adj[i][0]] = 1;
				s = adj[i][0];
			}
			vis[i] = 1;
		}
		if(adj[i].size() > adj[sm].size()) sm = i;
	}

	// bfs
	vis[sm] = 1;
	choose[sm] = 1;
	dfs(sm);
	int x = (count(choose.begin(), choose.end(), 1) <= n / 2);
	cout << count(choose.begin(), choose.end(), x) - (x == 0) << '\n';
	for(int i = 1; i <= n; i++){
		if(choose[i] == x) cout << i << ' ';
	}
	cout << '\n';
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int t;
	cin >> t;
	while(t--) solve();
}


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

vector<vector<int>> adj;
vector<int> choose;
vector<int> vis;

void dfs(int u){

	for(int v : adj[u]){
		if(choose[u] == 0) choose[v] = 1;
		else if(choose[u] == 1 && choose[v] == -1) choose[v] = 0;
	}

	for(int v : adj[u]){
		if(vis[v] == 0){
			vis[v] = 1;
			dfs(v);
		}
	}
}

void solve(){
	int n, m;
	cin >> n >> m;

	adj.clear();
	choose.clear();
	vis.clear();
	adj.resize(n + 1);
	choose.resize(n + 1, -1);
	vis.resize(n + 1);
	choose[0] = 0;

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

	int s = 1;
	for(int i = 1; i <= n; i++){
		if(adj[i].size() == 1){
			s = i;
			break;
		}
	}

	vis[s] = 1;
	choose[s] = 1;
	dfs(s);
	int x = (count(choose.begin(), choose.end(), 1) <= n / 2);
	cout << count(choose.begin(), choose.end(), x) - (x == 0) << '\n';
	for(int i = 1; i <= n; i++){
		if(choose[i] == x) cout << i << ' ';
	}
	cout << '\n';
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int t;
	cin >> t;
	while(t--) solve();
}


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

vector<vector<int>> adj;
vector<int> choose;
vector<int> vis;

void dfs(int u){

	for(int v : adj[u]){
		if(choose[u] == 0 && choose[v] == -1) choose[v] = 1;
		else if(choose[u] == 1 && choose[v] == -1) choose[v] = 0;
	}

	for(int v : adj[u]){
		if(vis[v] == 0){
			vis[v] = 1;
			dfs(v);
		}
	}
}

void solve(){
	int n, m;
	cin >> n >> m;

	adj.clear();
	choose.clear();
	vis.clear();
	adj.resize(n + 1);
	choose.resize(n + 1, -1);
	vis.resize(n + 1);
	choose[0] = 0;

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

	int s = 0, sm = 1;
	for(int i = 1; i <= n; i++){
		if(adj[i].size() == 1){
			if(choose[i] == -1){
				choose[i] = 0;
				choose[adj[i][0]] = 1;
				s = adj[i][0];
			}
			vis[i] = 1;
		}
		if(adj[i].size() > adj[sm].size()) sm = i;
	}

	// bfs
	if(s == 0) {
		s = sm;
		choose[s] = 1;
	}
	vis[s] = 1;
	dfs(s);
	cout << count(choose.begin(), choose.end(), 1) << '\n';
	for(int i = 1; i <= n; i++){
		if(choose[i] == 1) cout << i << ' ';
	}
	cout << '\n';
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int t;
	cin >> t;
	while(t--) solve();
}


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

vector<vector<int>> adj;
vector<int> choose;
vector<int> vis;

void dfs(int u){

	for(int v : adj[u]){
		if(choose[u] == 0 && choose[v] == -1) choose[v] = 1;
		else if(choose[u] == 1 && choose[v] == -1) choose[v] = 0;
	}

	for(int v : adj[u]){
		if(vis[v] == 0){
			vis[v] = 1;
			dfs(v);
		}
	}
}

void solve(){
	int n, m;
	cin >> n >> m;

	adj.clear();
	choose.clear();
	vis.clear();
	adj.resize(n + 1);
	choose.resize(n + 1, -1);
	vis.resize(n + 1);
	choose[0] = 0;

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

	int s = 0, sm = 1;
	for(int i = 1; i <= n; i++){
		if(adj[i].size() == 1){
			if(choose[i] == 0){
				choose[adj[i][0]] = 1;
				s = adj[i][0];
			}
			vis[i] = 1;
		}
		if(adj[i].size() > adj[sm].size()) sm = i;
	}

	// bfs
	if(s == 0) {
		s = sm;
		choose[s] = 1;
	}
	vis[s] = 1;
	dfs(s);
	cout << accumulate(choose.begin(), choose.end(), 0) << '\n';
	for(int i = 1; i <= n; i++){
		if(choose[i]) cout << i << ' ';
	}
	cout << '\n';
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int t;
	cin >> t;
	while(t--) solve();
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
const int maxn = 2e5 + 1;

vector<vector<int>>g;
vector<int>col(maxn);
vector<bool>vis(maxn);
int n,m;
void dfs(int x,int c){
    vis[x]=true;
    col[x]=c^1;
    for(auto y:g[x]){
        if(!vis[y]){
            dfs(y,c^1);
        }
    }
}
void solve(){
    cin>>n>>m;
    g=vector<vector<int>>(n);//,vis=vector<bool>(n);
    for(int i=0;i<n;i++)col[i]=0,vis[i]=false;
    while(m--){
        int u,v;
        cin>>u>>v;
        --u,--v;
        g[u].pb(v),g[v].pb(u);
    }
    dfs(0,1);
    int c0=0,c1=0;
    for(int i=0;i<n;i++){
        if(col[i]%2==0){
            ++c0;
        }else{
            ++c1;
        }
    }
    if(c0 <= c1){
        cout << c0 << endl;
        for(int i=0;i<n;i++){
            if(col[i]%2==0){
                cout << i + 1 <<' ';
            }
        }
    }else{
        cout << c1 << endl;
        for(int i=0;i<n;i++){
            if(col[i]%2==1){
                cout << i + 1 <<' ';
            }
        }
    }
    cout << endl;
}

int main(){
	int t;
    cin>>t;
    while(t--){
        solve();
    }
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do smth instead of nothing and stay organized
*/


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
// #include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back

vector<vector<int>>g;
vector<int>col;
vector<bool>vis;
void dfs(int node,int c){
    vis[node]=true;
    col[node]=c^1;
    for(auto child:g[node]){
        if(!vis[child]){
            dfs(child,c^1);
        }
    }
}
void solve(){
    int n,m;
    cin>>n>>m;
    g.resize(n),col.assign(n,0),vis.assign(n,false);
    while(m--){
        int u,v;
        cin>>u>>v;
        --u,--v;
        g[u].pb(v),g[v].pb(u);
    }
    dfs(0,1);
    int c0=0,c1=0;
    for(int i=0;i<n;i++){
        if(col[i]==0){
            ++c0;
        }else{
            ++c1;
        }
    }
    if(c0 >= c1){
        cout << c0 << endl;
        for(int i=0;i<n;i++){
            if(col[i]==0){
                cout << i + 1 <<' ';
            }
        }
    }else{
        cout << c1 << endl;
        for(int i=0;i<n;i++){
            if(col[i]==1){
                cout << i + 1 <<' ';
            }
        }
    }
    cout << endl;
}

int main(){
	int t;
    cin>>t;
    while(t--){
        solve();
    }
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do smth instead of nothing and stay organized
*/


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
const int maxn = 2e5 + 1;

vector<vector<int>>g;
vector<int>col(maxn);
vector<bool>vis;
int n,m;
void dfs(int x,int c){
    vis[x]=true;
    col[x]=c^1;
    for(auto y:g[x]){
        if(!vis[y]){
            dfs(y,c^1);
        }
    }
}
void solve(){
    cin>>n>>m;
    g=vector<vector<int>>(n),vis=vector<bool>(n);
    for(int i=0;i<n;i++)col[i]=0;
    while(m--){
        int u,v;
        cin>>u>>v;
        --u,--v;
        g[u].pb(v),g[v].pb(u);
    }
    dfs(0,1);
    int c0=0,c1=0;
    for(int i=0;i<n;i++){
        if(col[i]%2==0){
            ++c0;
        }else{
            ++c1;
        }
    }
    if(c0 <= c1){
        cout << c0 << endl;
        for(int i=0;i<n;i++){
            if(col[i]%2==0){
                cout << i + 1 <<' ';
            }
        }
    }else{
        cout << c1 << endl;
        for(int i=0;i<n;i++){
            if(col[i]%2==1){
                cout << i + 1 <<' ';
            }
        }
    }
    cout << endl;
}

int main(){
	int t;
    cin>>t;
    while(t--){
        solve();
    }
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do smth instead of nothing and stay organized
*/


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
const int maxn = 2e5 + 1;

vector<vector<int>>g(maxn);
vector<int>col(maxn);
vector<bool>vis(maxn);
void dfs(int x,int c){
    vis[x]=true;
    col[x]=c^1;
    for(auto y:g[x]){
        if(!vis[y]){
            dfs(y,c^1);
        }
    }
}
void solve(){
    int n,m;
    cin>>n>>m;
    //g=vector<vector<int>>(n);//,vis=vector<bool>(n);
    for(int i=0;i<n;i++)col[i]=0,vis[i]=false,g[i].clear();
    while(m--){
        int u,v;
        cin>>u>>v;
        --u,--v;
        g[u].pb(v),g[v].pb(u);
    }
    dfs(0,1);
    int c0=0,c1=0;
    for(int i=0;i<n;i++){
        if(col[i]%2==0){
            ++c0;
        }else{
            ++c1;
        }
    }
    if(c0 <= c1){
        cout << c0 << endl;
        for(int i=0;i<n;i++){
            if(col[i]%2==0){
                cout << i + 1 <<' ';
            }
        }
    }else{
        cout << c1 << endl;
        for(int i=0;i<n;i++){
            if(col[i]%2==1){
                cout << i + 1 <<' ';
            }
        }
    }
    cout << endl;
}

int main(){
	int t;
    cin>>t;
    while(t--){
        solve();
    }
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do smth instead of nothing and stay organized
*/


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
const int maxn = 2e5 + 1;

vector<vector<int>>g(maxn);
vector<int>col(maxn);
vector<bool>vis(maxn);
void dfs(int x,int c){
    vis[x]=true;
    col[x]=c^1;
    for(auto y:g[x]){
        if(!vis[y]){
            dfs(y,c^1);
        }
    }
}
void solve(){
    int n,m;
    cin>>n>>m;
    //g=vector<vector<int>>(n);//,vis=vector<bool>(n);
    for(int i=0;i<n;i++)col[i]=0,vis[i]=false,g[i].clear();
    while(m--){
        int u,v;
        cin>>u>>v;
        --u,--v;
        g[u].pb(v),g[v].pb(u);
    }
    dfs(0,1);
    int c0=0,c1=0;
    for(int i=0;i<n;i++){
        if(col[i]==0){
            ++c0;
        }else{
            ++c1;
        }
    }
    if(c0 <= c1){
        cout << c0 << endl;
        for(int i=0;i<n;i++){
            if(col[i]==0){
                cout << i + 1 <<' ';
            }
        }
    }else{
        cout << c1 << endl;
        for(int i=0;i<n;i++){
            if(col[i]==1){
                cout << i + 1 <<' ';
            }
        }
    }
    cout << endl;
}

int main(){
	int t;
    cin>>t;
    while(t--){
        solve();
    }
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do smth instead of nothing and stay organized
*/


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
// #include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
// #define INT_MAX 1000000000 this is wrong as INT_MAX is already included in header<climits> and  2147483647
// #define INT_MIN -1000000000
#define INF 1000000000
#define LL_MAX 1000000000000000000
#define LL_MIN -1000000000000000000
#define mod1 1000000007
#define mod2 998244353
#define ll int64_t
#define ld long double
#define vi vector <int>
#define vvi vector <vector<int>>
#define vll vector<ll>
#define vvl vector <vector<ll>>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpii vector<pair<int,int>>
#define pld pair<ld,ld>
#define vpll vector<pair<ll,ll>>
#define vpld vector<pair<ld,ld>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define FIO   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fs(x) fixed<<setprecision(x)
#define print(a) {for(auto x:a){cout << x << " ";}}
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

template<class T> bool ckmin(T& a, const T& b) {
	return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) {
	return a < b ? a = b, 1 : 0; }
constexpr int pct(int x) { return __builtin_popcount(x); }
constexpr int bits(int x) { return 31-__builtin_clz(x); } // floor(log2(x))

template<class T>
T binpow(T a, T b, T m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
template<class T>
T extended_gcd(T a, T b, T& x, T& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    T x1, y1;
    T d = gcd(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}
template<typename T,typename F>
T mod_inv(T a,F m){
	return binpow(a,m-2,m);
}
vector<vector<int>>g;
vector<int>col;
vector<bool>vis;
void dfs(int node,int c){
    vis[node]=true;
    col[node]=c^1;
    for(auto child:g[node]){
        if(!vis[child]){
            dfs(child,c^1);
        }
    }
}
void solve(){
    int n,m;
    cin>>n>>m;
    g=vector<vector<int>>(n),col=vector<int>(n),vis=vector<bool>(n,false);
    while(m--){
        int u,v;
        cin>>u>>v;
        --u,--v;
        g[u].pb(v),g[v].pb(u);
    }
    dfs(0,1);
    int c0=0,c1=0;
    for(int i=0;i<n;i++){
        if(col[i]==0){
            ++c0;
        }else{
            ++c1;
        }
    }
    if(c0 <= c1){
        cout << c0 << endl;
        for(int i=0;i<n;i++){
            if(col[i]==0){
                cout << i + 1 <<' ';
            }
        }
    }else{
        cout << c1 << endl;
        for(int i=0;i<n;i++){
            if(col[i]==1){
                cout << i + 1 <<' ';
            }
        }
    }
    cout << endl;
}

int main(){
	FIO
	int t;
    cin>>t;
    while(t--){
        solve();
    }
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do smth instead of nothing and stay organized
*/


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
const int maxn = 2e5 + 1;

vector<vector<int>>g(maxn);
vector<int>dis(maxn);
vector<bool>vis(maxn);

void bfs(int src){
    vis[src]=true;
    queue<int>q;
    q.push(src);
    dis[src]=0;
    while(!q.empty()){
        int u=q.front();
        q.pop();
        for(auto v:g[u]){
            if(!vis[v]){
                vis[v]=true;
                q.push(v);
                dis[v]=dis[u]+1;
            }
        }
    }
}
void solve(){
    int n,m;
    cin>>n>>m;
    while(m--){
        int u,v;
        cin>>u>>v;
        --u,--v;
        g[u].pb(v),g[v].pb(u);
    }
    bfs(0);
    int c0=0,c1=0;
    for(int i=0;i<n;i++){
        if(dis[i]%2==0){
            ++c0;
        }else{
            ++c1;
        }
    }
    if(c0 <= c1){
        cout << c0 << endl;
        for(int i=0;i<n;i++){
            if(dis[i]%2==0){
                cout << i + 1 <<' ';
            }
        }
    }else{
        cout << c1 << endl;
        for(int i=0;i<n;i++){
            if(dis[i]%2==1){
                cout << i + 1 <<' ';
            }
        }
    }
    cout << endl;
}

int main(){
	int t;
    cin>>t;
    while(t--){
        solve();
    }
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do smth instead of nothing and stay organized
*/


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
const int maxn = 2e5 + 1;

vector<vector<int>>g(maxn);
vector<int>col(maxn);
vector<bool>vis(maxn);
void dfs(int node,int c){
    vis[node]=true;
    col[node]=c^1;
    for(auto child:g[node]){
        if(!vis[child]){
            dfs(child,c^1);
        }
    }
}
void solve(){
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++)col[i]=0,vis[i]=false,g[i].clear();
    while(m--){
        int u,v;
        cin>>u>>v;
        --u,--v;
        g[u].pb(v),g[v].pb(u);
    }
    dfs(0,1);
    int c0=0,c1=0;
    for(int i=0;i<n;i++){
        if(col[i]==0){
            ++c0;
        }else{
            ++c1;
        }
    }
    if(c0 <= c1){
        cout << c0 << endl;
        for(int i=0;i<n;i++){
            if(col[i]==0){
                cout << i + 1 <<' ';
            }
        }
    }else{
        cout << c1 << endl;
        for(int i=0;i<n;i++){
            if(col[i]==1){
                cout << i + 1 <<' ';
            }
        }
    }
    cout << endl;
}

int main(){
	int t;
    cin>>t;
    while(t--){
        solve();
    }
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do smth instead of nothing and stay organized
*/


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
const int maxn = 2e5 + 1;

vector<vector<int>>g(maxn);
vector<int>col(maxn);
vector<bool>vis(maxn);
void dfs(int node,int c){
    vis[node]=true;
    col[node]=c^1;
    for(auto child:g[node]){
        if(!vis[child]){
            dfs(child,c^1);
        }
    }
}
void solve(){
    int n,m;
    cin>>n>>m;
    while(m--){
        int u,v;
        cin>>u>>v;
        --u,--v;
        g[u].pb(v),g[v].pb(u);
    }
    dfs(0,1);
    int c0=0,c1=0;
    for(int i=0;i<n;i++){
        if(col[i]==0){
            ++c0;
        }else{
            ++c1;
        }
    }
    if(c0 <= c1){
        cout << c0 << endl;
        for(int i=0;i<n;i++){
            if(col[i]==0){
                cout << i + 1 <<' ';
            }
        }
    }else{
        cout << c1 << endl;
        for(int i=0;i<n;i++){
            if(col[i]==1){
                cout << i + 1 <<' ';
            }
        }
    }
    cout << endl;
}

int main(){
	int t;
    cin>>t;
    while(t--){
        solve();
    }
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do smth instead of nothing and stay organized
*/


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
const int maxn = 2e5 + 1;

vector<vector<int>>g(maxn);
vector<int>col(maxn);
vector<bool>vis(maxn);
void dfs(int node,int c){
    vis[node]=true;
    col[node]=c^1;
    for(auto child:g[node]){
        if(!vis[child]){
            dfs(child,c^1);
        }
    }
}
void solve(){
    int n,m;
    cin>>n>>m;

    while(m--){
        int u,v;
        cin>>u>>v;
        --u,--v;
        g[u].pb(v),g[v].pb(u);
    }
    dfs(0,1);
    int c0=0,c1=0;
    for(int i=0;i<n;i++){
        if(col[i]==0){
            ++c0;
        }else{
            ++c1;
        }
    }
    if(c0 <= c1){
        cout << c0 << endl;
        for(int i=0;i<n;i++){
            if(col[i]==0){
                cout << i + 1 <<' ';
            }
        }
    }else{
        cout << c1 << endl;
        for(int i=0;i<n;i++){
            if(col[i]==1){
                cout << i + 1 <<' ';
            }
        }
    }
    cout << endl;
}

int main(){
	int t;
    cin>>t;
    while(t--){
        solve();
    }
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do smth instead of nothing and stay organized
*/


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
// #include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
// #define INT_MAX 1000000000 this is wrong as INT_MAX is already included in header<climits> and  2147483647
// #define INT_MIN -1000000000
#define INF 1000000000
#define LL_MAX 1000000000000000000
#define LL_MIN -1000000000000000000
#define mod1 1000000007
#define mod2 998244353
#define ll int64_t
#define ld long double
#define vi vector <int>
#define vvi vector <vector<int>>
#define vll vector<ll>
#define vvl vector <vector<ll>>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpii vector<pair<int,int>>
#define pld pair<ld,ld>
#define vpll vector<pair<ll,ll>>
#define vpld vector<pair<ld,ld>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define FIO   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fs(x) fixed<<setprecision(x)
#define print(a) {for(auto x:a){cout << x << " ";}}
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

template<class T> bool ckmin(T& a, const T& b) {
	return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) {
	return a < b ? a = b, 1 : 0; }
constexpr int pct(int x) { return __builtin_popcount(x); }
constexpr int bits(int x) { return 31-__builtin_clz(x); } // floor(log2(x))

template<class T>
T binpow(T a, T b, T m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
template<class T>
T extended_gcd(T a, T b, T& x, T& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    T x1, y1;
    T d = gcd(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}
template<typename T,typename F>
T mod_inv(T a,F m){
	return binpow(a,m-2,m);
}
vector<vector<int>>g;
vector<int>col,a;
vector<bool>vis;
void dfs(int node,int c){
    vis[node]=true;
    col[node]=c^1;
    for(auto child:g[node]){
        if(!vis[child]){
            dfs(child,c^1);
        }
    }
}
void solve(){
    int n,m;
    cin>>n>>m;
    g.resize(n),col.resize(n),a.resize(n),vis.assign(n,false);
    while(m--){
        int u,v;
        cin>>u>>v;
        --u,--v;
        g[u].pb(v),g[v].pb(u);
    }
    dfs(0,1);
    int c0=0,c1=0;
    for(int i=0;i<n;i++){
        if(col[i]==0){
            ++c0;
        }else{
            ++c1;
        }
    }
    if(c0 >= c1){
        cout << c0 << endl;
        for(int i=0;i<n;i++){
            if(col[i]==0){
                cout << i + 1 <<' ';
            }
        }
    }else{
        cout << c1 << endl;
        for(int i=0;i<n;i++){
            if(col[i]==1){
                cout << i + 1 <<' ';
            }
        }
    }
    cout << endl;
}

int main(){
	FIO
	int t;
    cin>>t;
    while(t--){
        solve();
    }
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do smth instead of nothing and stay organized
*/


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
const int maxn = 2e5 + 1;

vector<vector<int>>g;
vector<int>dis;
vector<bool>vis;
int n,m;
void bfs(int src){
    dis=vector<int>(n);
    vis[src]=true;
    queue<int>q;
    q.push(src);
    dis[src]=0;
    while(!q.empty()){
        int u=q.front();
        q.pop();
        for(auto v:g[u]){
            if(!vis[v]){
                vis[v]=true;
                q.push(v);
                dis[v]=dis[u]+1;
            }
        }
    }
}
void solve(){
    cin>>n>>m;
    g=vector<vector<int>>(n),vis=vector<bool>(n);
    //for(int i=0;i<n;i++)g[i].clear(),vis[i]=false;
    while(m--){
        int u,v;
        cin>>u>>v;
        --u,--v;
        g[u].pb(v),g[v].pb(u);
    }
    bfs(0);
    int c0=0,c1=0;
    for(int i=0;i<n;i++){
        if(dis[i]%2==0){
            ++c0;
        }else{
            ++c1;
        }
    }
    if(c0 <= c1){
        cout << c0 << endl;
        for(int i=0;i<n;i++){
            if(dis[i]%2==0){
                cout << i + 1 <<' ';
            }
        }
    }else{
        cout << c1 << endl;
        for(int i=0;i<n;i++){
            if(dis[i]%2==1){
                cout << i + 1 <<' ';
            }
        }
    }
    cout << endl;
}

int main(){
	int t;
    cin>>t;
    while(t--){
        solve();
    }
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do smth instead of nothing and stay organized
*/


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
const int maxn = 2e5 + 1;

vector<vector<int>>g(maxn);
vector<int>col(maxn);
vector<bool>vis(maxn);
int n,m;
void dfs(int x,int c){
    vis[x]=true;
    col[x]=c^1;
    for(auto y:g[x]){
        if(!vis[y]){
            dfs(y,c^1);
        }
    }
}
void solve(){
    cin>>n>>m;
    //g=vector<vector<int>>(n);//,vis=vector<bool>(n);
    for(int i=0;i<n;i++)col[i]=0,vis[i]=false,g[i].clear();
    while(m--){
        int u,v;
        cin>>u>>v;
        --u,--v;
        g[u].pb(v),g[v].pb(u);
    }
    dfs(0,1);
    int c0=0,c1=0;
    for(int i=0;i<n;i++){
        if(col[i]%2==0){
            ++c0;
        }else{
            ++c1;
        }
    }
    if(c0 <= c1){
        cout << c0 << endl;
        for(int i=0;i<n;i++){
            if(col[i]%2==0){
                cout << i + 1 <<' ';
            }
        }
    }else{
        cout << c1 << endl;
        for(int i=0;i<n;i++){
            if(col[i]%2==1){
                cout << i + 1 <<' ';
            }
        }
    }
    cout << endl;
}

int main(){
	int t;
    cin>>t;
    while(t--){
        solve();
    }
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do smth instead of nothing and stay organized
*/


#include <bits/stdc++.h>
    #include<ext/pb_ds/assoc_container.hpp>
    #include<ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    using namespace std;
    template <typename T>
    using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
    #define int long long
    typedef long double ld;
    #define pb push_back
    #define f(i,a,b) for(int i=a;i<b;i++)
    #define fd(i,a,b) for(int i=a-1;i>=b;i--)
    #define pf push_front
    #define fi first
    #define se second
     int mn=1e9+7;
    int cnt=0;
    int vis[200000+10]={0};
    int r=0;

    void dfs(int i,vector<vector<int >> &v,vector<int > &e,vector<int > &f)
    {
        vis[i]=1;
        if(r%2!=0)
        {
            cout<<i<<" ";
        }
        r++;
        for(auto j:v[i])
        {
            if(vis[j]==0)
            {
                dfs(j,v,e,f);
            }
        }
    }
    vector<pair<int ,int >> v1,v2;
    signed main() {
    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("INPUT.txt", "r", stdin);
    // for writing output to output.txt
    freopen("OUTPUT.txt", "w", stdout);
    #endif

    // -------------------------------------Code starts here---------------------------------------------------------------------
    int t=1;
    cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        vector<vector<int >> v;
        v.resize(n+1);
        vector<int > e,f;
        fill_n(vis,200000+10,0);
        r=0;
        while(m--)
        {
            int x,y;
            cin>>x>>y;
            v[x].pb(y);
            v[y].pb(x);
        }
        int cnt=0;
        cout<<n/2<<endl;
        dfs(1,v,e,f);
        cout<<endl;

        }
    }


#include <bits/stdc++.h>
    #include<ext/pb_ds/assoc_container.hpp>
    #include<ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    using namespace std;
    template <typename T>
    using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
    #define int long long
    typedef long double ld;
    #define pb push_back
    #define f(i,a,b) for(int i=a;i<b;i++)
    #define fd(i,a,b) for(int i=a-1;i>=b;i--)
    #define pf push_front
    #define fi first
    #define se second
     int mn=1e9+7;
    int cnt=0;
    int vis[200000+10]={0};
    int r=0;

    void dfs(int i,vector<vector<int >> &v,vector<int > &e,vector<int > &f)
    {
        vis[i]=1;
        if(r%2==0)
        {
            e.pb(i);
        }
        else
            f.pb(i);
        r++;
        for(auto j:v[i])
        {
            if(vis[j]==0)
            {
                dfs(j,v,e,f);
            }
        }
    }
    vector<pair<int ,int >> v1,v2;
    signed main() {
    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("INPUT.txt", "r", stdin);
    // for writing output to output.txt
    freopen("OUTPUT.txt", "w", stdout);
    #endif

    // -------------------------------------Code starts here---------------------------------------------------------------------
    int t=1;
    cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        vector<vector<int >> v;
        v.resize(n+1);
        vector<int > e,f;
        fill_n(vis,200000+10,0);
        r=0;
        while(m--)
        {
            int x,y;
            cin>>x>>y;
            v[x].pb(y);
            v[y].pb(x);
        }
        int cnt=0;
        dfs(1,v,e,f);
        if(e.size()>f.size())
        {
            cout<<f.size()<<endl;
            for(auto i:f)
            {
                cout<<i<<" ";
            }
            cout<<endl;
        }
        else
        {
            cout<<e.size()<<endl;
            for(auto i:e)
            {
                cout<<i<<" ";
            }
            cout<<endl;
        }

        }
    }


#include <bits/stdc++.h>
    #include<ext/pb_ds/assoc_container.hpp>
    #include<ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    using namespace std;
    template <typename T>
    using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  //  #define int long long
    typedef long double ld;
    #define pb push_back
    #define f(i,a,b) for(int i=a;i<b;i++)
    #define fd(i,a,b) for(int i=a-1;i>=b;i--)
    #define pf push_front
    #define fi first
    #define se second
     int mn=1e9+7;
    int cnt=0;
    int vis[200000+10]={0};
    int ans[200000+10]={0};
    vector<vector<int >> v;
    void dfs(int j,int x)
    {
        vis[j]=1;
        if(x%2==1)
        {
            cnt++;
            ans[j]=1;
        }
        for(auto i:v[j])
        {
            if(vis[i]==0)
            {
                dfs(i,x+1);
            }
        }
    }
    vector<pair<int ,int >> v1,v2;
    signed main() {
    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("INPUT.txt", "r", stdin);
    // for writing output to output.txt
    freopen("OUTPUT.txt", "w", stdout);
    #endif

    // -------------------------------------Code starts here---------------------------------------------------------------------
    int t=1;
    cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        v.clear();
        v.resize(n);
        cnt=0;
        for(int i=0;i<m;i++)
        {
            int x,y;
            cin>>x>>y;
            x--;
            y--;
            v[x].pb(y);
            v[y].pb(x);
        }

        f(i,0,n)
        {
            vis[i]=0;
            ans[i]=0;
        }
        dfs(0,0);
        if(cnt>n/2)
        {
            cout<<n-cnt<<endl;
            f(i,0,n)
            {
                if(ans[i]==0)
                {
                    cout<<i+1<<" ";
                }
            }
        }
        else
        {
            cout<<cnt<<endl;
            f(i,0,n)
            {
                if(ans[i]==1)
                    cout<<i+1<<" ";
            }
        }
        cout<<endl;

    }
}


#include <bits/stdc++.h>
    #include<ext/pb_ds/assoc_container.hpp>
    #include<ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    using namespace std;
    template <typename T>
    using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  //  #define int long long
    typedef long double ld;
    #define pb push_back
    #define f(i,a,b) for(int i=a;i<b;i++)
    #define fd(i,a,b) for(int i=a-1;i>=b;i--)
    #define pf push_front
    #define fi first
    #define se second
     int mn=1e9+7;
    int cnt=0;
    int vis[200000+10]={0};
    int vi[200000+10]={0};
    int r=0;
    void dfs(int i,vector<vector<int >> &v)
    {
        vis[i]=1;
        vi[i]=r%2;
        r++;
        for(auto j:v[i])
        {
            if(vis[j]==0)
            {
                dfs(j,v);
            }
        }
    }
    vector<pair<int ,int >> v1,v2;
    signed main() {
    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("INPUT.txt", "r", stdin);
    // for writing output to output.txt
    freopen("OUTPUT.txt", "w", stdout);
    #endif

    // -------------------------------------Code starts here---------------------------------------------------------------------
    int t=1;
    cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        vector<vector<int >> v;
        v.resize(n+1);
        vector<int > e;
        fill_n(vis,200000+10,0);
        fill_n(vi,200000+10,0);
        r=0;
        while(m--)
        {
            int x,y;
            cin>>x>>y;
            v[x].pb(y);
            v[y].pb(x);
        }
        int cnt=0;
        for(int i=1;i<=n;i++)
        {
            if(vis[i]==0)
            {
                dfs(i,v);
            }
        }
        f(i,1,n+1)
        {
            if(vi[i]==0)
            {
                cnt++;
            }
        }
        if(cnt<=n/2)
        {
        cout<<cnt<<endl;
        f(i,1,n+1)
        {
            if(vi[i]==0)
            cout<<i<<" ";
        }
        cout<<endl;
        }
        else
        {
            cout<<n-cnt<<endl;
        f(i,1,n+1)
        {
            if(vi[i]!=0)
            cout<<i<<" ";
        }
        cout<<endl;
        }
    }

}


#include <bits/stdc++.h>
    #include<ext/pb_ds/assoc_container.hpp>
    #include<ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    using namespace std;
    template <typename T>
    using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
    #define int long long
    typedef long double ld;
    #define pb push_back
    #define f(i,a,b) for(int i=a;i<b;i++)
    #define fd(i,a,b) for(int i=a-1;i>=b;i--)
    #define pf push_front
    #define fi first
    #define se second
     int mn=1e9+7;
    int cnt=0;
    int vis[200000+10]={0};
    int vi[200000+10]={0};
    int r=0;
    void dfs(int i,vector<vector<int >> &v)
    {
        vis[i]=1;
        vi[i]=r%2;
        r++;
        for(auto j:v[i])
        {
            if(vis[j]==0)
            {
                dfs(j,v);
            }
        }
    }
    vector<pair<int ,int >> v1,v2;
    signed main() {
    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("INPUT.txt", "r", stdin);
    // for writing output to output.txt
    freopen("OUTPUT.txt", "w", stdout);
    #endif

    // -------------------------------------Code starts here---------------------------------------------------------------------
    int t=1;
    cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        vector<vector<int >> v;
        v.resize(n+1);
        vector<int > e;
        fill_n(vis,200000+10,0);
        fill_n(vi,200000+10,0);
        r=0;
        while(m--)
        {
            int x,y;
            cin>>x>>y;
            v[x].pb(y);
            v[y].pb(x);
        }
        int cnt=0;
        for(int i=1;i<=n;i++)
        {
            if(vis[i]==0)
            {
                dfs(i,v);
            }
        }
        f(i,1,n+1)
        {
            if(vi[i]==0)
            {
                cnt++;
            }
        }
        if(cnt<=n/2)
        {
        cout<<cnt<<endl;
        f(i,1,n+1)
        {
            if(vi[i]==0)
            cout<<i<<" ";
        }
        cout<<endl;
        }
        else
        {
            cout<<n-cnt<<endl;
        f(i,1,n+1)
        {
            if(vi[i]!=0)
            cout<<i<<" ";
        }
        cout<<endl;
        }
    }

}


#include <bits/stdc++.h>
    #include<ext/pb_ds/assoc_container.hpp>
    #include<ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    using namespace std;
    template <typename T>
    using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  //  #define int long long
    typedef long double ld;
    #define pb push_back
    #define f(i,a,b) for(int i=a;i<b;i++)
    #define fd(i,a,b) for(int i=a-1;i>=b;i--)
    #define pf push_front
    #define fi first
    #define se second
     int mn=1e9+7;
    int cnt=0;
    int vis[200000+10]={0};
    int vi[200000+10]={0};
    int r=0;
    void dfs(int i,vector<vector<int >> &v)
    {
        vis[i]=1;
        vi[i]=r%2;
        r++;
        for(auto j:v[i])
        {
            if(vis[j]==0)
            {
                dfs(j,v);
            }
        }
    }
    vector<pair<int ,int >> v1,v2;
    signed main() {
    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("INPUT.txt", "r", stdin);
    // for writing output to output.txt
    freopen("OUTPUT.txt", "w", stdout);
    #endif

    // -------------------------------------Code starts here---------------------------------------------------------------------
    int t=1;
    cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        vector<vector<int >> v;
        v.resize(n+1);
        vector<int > e;
        fill_n(vis,n+1,0);
        fill_n(vi,n+1,0);
        r=0;
        while(m--)
        {
            int x,y;
            cin>>x>>y;
            v[x].pb(y);
            v[y].pb(x);
        }
        int cnt=0;
        for(int i=1;i<=n;i++)
        {
            if(vis[i]==0)
            {
                dfs(i,v);
            }
        }
        f(i,1,n+1)
        {
            if(vi[i]==0)
            {
                cnt++;
            }
        }
        if(cnt<=n/2)
        {
        cout<<cnt<<endl;
        f(i,1,n+1)
        {
            if(vi[i]==0)
            cout<<i<<" ";
        }
        cout<<endl;
        }
        else
        {
            cout<<n-cnt<<endl;
        f(i,1,n+1)
        {
            if(vi[i]!=0)
            cout<<i<<" ";
        }
        cout<<endl;
        }
    }

}


#include <bits/stdc++.h>
    #include<ext/pb_ds/assoc_container.hpp>
    #include<ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    using namespace std;
    template <typename T>
    using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
    #define int long long
    typedef long double ld;
    #define pb push_back
    #define f(i,a,b) for(int i=a;i<b;i++)
    #define fd(i,a,b) for(int i=a-1;i>=b;i--)
    #define pf push_front
    #define fi first
    #define se second
     int mn=1e9+7;
    int cnt=0;
    int vis[200000+10]={0};
    int r=0;

    void dfs(int i,vector<vector<int >> &v)
    {
        vis[i]=1;
        if(r%2!=0)
        {
            cout<<i<<" ";
        }
        r++;
        for(auto j:v[i])
        {
            if(vis[j]==0)
            {
                dfs(j,v);
            }
        }
    }
    vector<pair<int ,int >> v1,v2;
    signed main() {
    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("INPUT.txt", "r", stdin);
    // for writing output to output.txt
    freopen("OUTPUT.txt", "w", stdout);
    #endif

    // -------------------------------------Code starts here---------------------------------------------------------------------
    int t=1;
    cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        vector<vector<int >> v;
        v.resize(n+1);

        fill_n(vis,n+1,0);
        r=0;
        while(m--)
        {
            int x,y;
            cin>>x>>y;
            v[x].pb(y);
            v[y].pb(x);
        }
        int cnt=0;
        cout<<n/2<<endl;
        dfs(1,v);
        cout<<endl;

        }
    }


#include <bits/stdc++.h>
    #include<ext/pb_ds/assoc_container.hpp>
    #include<ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    using namespace std;
    template <typename T>
    using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
    #define int long long
    typedef long double ld;
    #define pb push_back
    #define f(i,a,b) for(int i=a;i<b;i++)
    #define fd(i,a,b) for(int i=a-1;i>=b;i--)
    #define pf push_front
    #define fi first
    #define se second
     int mn=1e9+7;
    int cnt=0;
    int vis[200000+10]={0};
    int r=0;

    void dfs(int i,vector<vector<int >> &v)
    {
        vis[i]=1;
        if(r%2!=0)
        {
            cout<<i<<" ";
        }
        r++;
        for(auto j:v[i])
        {
            if(vis[j]==0)
            {
                dfs(j,v);
            }
        }
    }

    signed main() {
    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("INPUT.txt", "r", stdin);
    // for writing output to output.txt
    freopen("OUTPUT.txt", "w", stdout);
    #endif

    // -------------------------------------Code starts here---------------------------------------------------------------------
    int t=1;
    cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        vector<vector<int >> v;
        v.resize(n+1);

        r=0;
        while(m--)
        {
            int x,y;
            cin>>x>>y;
            v[x].pb(y);
            v[y].pb(x);
        }
        int cnt=0;
        cout<<n/2<<endl;
        dfs(1,v);
        cout<<endl;
        fill_n(vis,n+1,0);
        }
    }