/+ dub.sdl:
    name "C"
    dependency "dunkelheit" version=">=0.9.0"
+/

import std.stdio, std.algorithm, std.range, std.conv;
// import dkh.foundation, dkh.scanner;

int main() {
    Scanner sc = new Scanner(stdin);
    int n;
    sc.read(n);
    int[][] g = new int[][n];
    foreach (i; 0..n-1) {
        int a, b;
        sc.read(a, b); a--; b--;
        g[a] ~= b; g[b] ~= a;
    }
    if (g.count!"a.length>=3" >= 2) {
        writeln("No");
        return 0;
    }
    int[] leafs;
    void dfs(int p, int b) {
        bool haveCh = false;
        foreach (d; g[p]) {
            if (d == b) continue;
            haveCh = true;
            dfs(d, p);
        }
        if (!haveCh) leafs ~= p;
    }
    foreach (i; 0..n) {
        if (i == n-1 || g[i].length >= 3) {
            dfs(i, -1);
            writeln("Yes");
            writeln(leafs.length);
            foreach (d; leafs) {
                writeln(i+1, " ", d+1);
            }
            break;
        }
    }
    return 0;
}
/* IMPORT /mnt/c/Users/yosupo/Programs/dunkelheit/source/dkh/container/stackpayload.d */
// module dkh.container.stackpayload;

struct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {
    import core.exception : RangeError;

    private T* _data;
    private uint len, cap;

    @property bool empty() const { return len == 0; }
    @property size_t length() const { return len; }
    alias opDollar = length;

    inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }

    ref inout(T) opIndex(size_t i) inout {
        version(assert) if (len <= i) throw new RangeError();
        return _data[i];
    }
    ref inout(T) front() inout { return this[0]; }
    ref inout(T) back() inout { return this[$-1]; }

    void reserve(size_t newCap) {
        import core.memory : GC;
        import core.stdc.string : memcpy;
        import std.conv : to;
        if (newCap <= cap) return;
        void* newData = GC.malloc(newCap * T.sizeof);
        cap = newCap.to!uint;
        if (len) memcpy(newData, _data, len * T.sizeof);
        _data = cast(T*)(newData);
    }
    void free() {
        import core.memory : GC;
        GC.free(_data);
    }

    void clear() {
        len = 0;
    }

    void insertBack(T item) {
        import std.algorithm : max;
        if (len == cap) reserve(max(cap * 2, MINCAP));
        _data[len++] = item;
    }
    alias opOpAssign(string op : "~") = insertBack;
    void removeBack() {
        assert(!empty, "StackPayload.removeBack: Stack is empty");
        len--;
    }
}

/* IMPORT /mnt/c/Users/yosupo/Programs/dunkelheit/source/dkh/scanner.d */
// module dkh.scanner;

// import dkh.container.stackpayload;

class Scanner {
    import std.stdio : File;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeChar, isStaticArray, isArray;
    import std.algorithm : map;
    File f;
    this(File f) {
        this.f = f;
    }
    char[512] lineBuf;
    char[] line;
    private bool succW() {
        import std.range.primitives : empty, front, popFront;
        import std.ascii : isWhite;
        while (!line.empty && line.front.isWhite) {
            line.popFront;
        }
        return !line.empty;
    }
    private bool succ() {
        import std.range.primitives : empty, front, popFront;
        import std.ascii : isWhite;
        while (true) {
            while (!line.empty && line.front.isWhite) {
                line.popFront;
            }
            if (!line.empty) break;
            line = lineBuf[];
            f.readln(line);
            if (!line.length) return false;
        }
        return true;
    }

    private bool readSingle(T)(ref T x) {
        import std.algorithm : findSplitBefore;
        import std.string : strip;
        import std.conv : parse;
        if (!succ()) return false;
        static if (isArray!T) {
            alias E = ElementType!T;
            static if (isSomeChar!E) {

                auto r = line.findSplitBefore(" ");
                x = r[0].strip.dup;
                line = r[1];
            } else static if (isStaticArray!T) {
                foreach (i; 0..T.length) {
                    bool f = succW();
                    assert(f);
                    x[i] = line.parse!E;
                }
            } else {
                StackPayload!E buf;
                while (succW()) {
                    buf ~= line.parse!E;
                }
                x = buf.data;
            }
        } else {
            x = line.parse!T;
        }
        return true;
    }

    int unsafeRead(T, Args...)(ref T x, auto ref Args args) {
        if (!readSingle(x)) return 0;
        static if (args.length == 0) {
            return 1;
        } else {
            return 1 + read(args);
        }
    }
    void read(Args...)(auto ref Args args) {
        import std.exception;
        static if (args.length != 0) {
            enforce(readSingle(args[0]));
            read(args[1..$]);
        }
    }
    bool hasNext() {
        return succ();
    }
}

/* IMPORT /mnt/c/Users/yosupo/Programs/dunkelheit/source/dkh/foundation.d */

// module dkh.foundation;

static if (__VERSION__ <= 2070) {
    /*
    Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d
    Copyright: Andrei Alexandrescu 2008-.
    License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).
    */
    template fold(fun...) if (fun.length >= 1) {
        auto fold(R, S...)(R r, S seed) {
            import std.algorithm : reduce;
            static if (S.length < 2) {
                return reduce!fun(seed, r);
            } else {
                import std.typecons : tuple;
                return reduce!fun(tuple(seed), r);
            }
        }
    }

}

/*
This source code generated by dunkelheit and include dunkelheit's source code.
dunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit)
dunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt)
*/

import std.algorithm;
import std.array;
import std.conv;
import std.range;
import std.stdio;
import std.string;

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		auto d = new int [n];
		auto a = new int [] [n];
		foreach (i; 0..n - 1)
		{
			int u, v;
			readf (" %s %s", &u, &v);
			u -= 1;
			v -= 1;
			a[u] ~= v;
			a[v] ~= u;
			d[u] += 1;
			d[v] += 1;
		}
		auto p = n.iota.array;
		makeIndex (d, p);
		if (d[p[$ - 2]] > 2)
		{
			writeln ("No");
			continue;
		}
		writeln ("Yes");
		auto r = p[$ - 1];
		writeln (n.iota.count !(x => x != r && d[x] == 1));
		foreach (v; 0..n)
		{
			if (v != r && d[v] == 1)
			{
				writeln (v + 1, " ", r + 1);
			}
		}
	}
}

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip, std.datetime;

void main() {
    auto N = readln.chomp.to!int;
    auto G = new int[][](N);
    foreach (_; 0..N-1) {
        auto s = readln.split.map!(to!int);
        G[s[0]-1] ~= s[1]-1;
        G[s[1]-1] ~= s[0]-1;
    }

    if (G.map!(g => g.length >= 3).sum >= 2) {
        writeln("No");
        return;
    }

    writeln("Yes");

    int[] root1;
    int root3 = -1;
    foreach (i; 0..N) if (G[i].length == 1) root1 ~= i;
    foreach (i; 0..N) if (G[i].length >= 3) root3 = i;

    if (root3 == -1) {
        writeln(1);
        writeln(root1[0]+1, " ", root1[1]+1);
    } else {
        writeln(root1.length);
        foreach (r; root1)
            writeln(r+1, " ", root3+1);
    }
}

import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
    int n;
    readf( "%s", &n );
    readln;

    auto g = new int [][] ( n+1 );
    foreach ( _; 0..n-1 ) {
        auto t = readln.splitter.map!( to!int ).array;
        (2).iota.each!( i => g[ t[ i ] ] ~= t[ 1-i ] );
    }

    debug { writeln( g ); }

    bool ok = g.count!(adj => adj.length > 2) <= 1;

    if ( !ok ) {
        writeln( "No" );
        return;
    }

    int v = cast(int) g.maxIndex!( q{ a.length < b.length });

    int[] ans;
    foreach ( u; g[v] ) {
        int lst = v;
        int cur = u;
        while ( true ) {
            if ( g[ cur ].length == 1 ) break;

            auto nxt = g[ cur ][ 0 ] != lst ? g[ cur ][ 0 ] : g[ cur ][ 1 ];
            lst = cur;
            cur = nxt;
        }
        ans ~= cur;
    }

    writeln( "Yes" );
    writeln( ans.length );
    ans.each!( lst => writeln( v, ' ', lst ) );
}


import std.stdio;
import std.string: chomp, split;
import std.conv: to;

void main()
{
	int n; readf("%s\n", &n);
	auto ar = readln.chomp.split.to!(int[]);
	//writeln(ar);

	int state = -1, sol = 0;

	foreach (a; ar) {
		//writefln("%d %d", a, state);
		if (a == 0) {
			if (state != -1) {
				state = 1;
			}
			continue;
		}
		if (state == -1) {
			state = 0;
		}
		sol++;
		if (state == 1) {
			sol++;
			state = 0;
		}
	}

	writeln(sol);
}

import std.stdio;

void main() {

	int n, ni, num, flag;

	scanf("%d", &n);

	foreach (i; 0 .. n) {
		scanf("%d", &ni);
		if (!ni && flag) {
			flag = 0;
			num++;
		}
		else
			if (ni == 1) {
				num++;
				flag = 1;
			}
	}

	if (num > 0 && !ni)
		num--;

	printf("%d\n", num);
}

import std.stdio;
import std.math;
import std.array;
import std.algorithm;
import std.conv;
import std.functional;
import std.traits;
import std.string;
import std.container;

unittest{
  assert(solve([1,1,0,0,1]) == 4, "Teste 1");
  assert(solve([0,1,0,1,0]) == 3, "Teste 2");
  assert(solve([0,0]) == 0, "Teste 3");
  assert(solve([0,0,1,0,0,0,0,0]) == 1, "Teste 4");
  assert(solve([0,0,0,0,0,0,0,1]) == 1, "Teste 5");
  assert(solve([1,0,0,0,0,0,0,0]) == 1, "Teste 6");
  assert(solve([1,0,1,0,0,1,1,0]) == 6, "Teste 7");
}

long solve(long[] ls){
  long c = 0;
  int state = 0;
  foreach(i,l;ls){
    if(state == 0 && l == 1){
      c++;
      state = 1;
      //writefln("%s open",i);
    } else if(state == 1){
      if(l == 0){
        if(ls[i-1] == 0){
          state = 0;
          //writefln("%s back",i-1);
        } else {
          c++;
          //writefln("%s next",i);
        }
      } else {
        //writefln("%s next",i);
        c++;
      }
    }
  }
  if(ls[$-1] == 0 && c != 0){
    c--;
  }
  //writeln(c);
  return c;
}

void main(){
  size_t n;
  readf("%s\n",&n);

  long[] l = new long[n];
  for(size_t i = 0; i < n; i++){
    readf("%s ",l.ptr+i);
  }
  writeln(solve(l));
}

import core.thread;
import std.conv, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;

//	Input
class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }
int readInt() { return to!int(readToken); }
long readLong() { return to!long(readToken); }
real readReal() { return to!real(readToken); }

//	chmin/chmax
void chmin(T)(ref T t, in T f) { if (t > f) t = f; }
void chmax(T)(ref T t, in T f) { if (t < f) t = f; }

//	Pair
struct Pair(S, T) {
	S x; T y;
	int opCmp(    const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }
	int opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }
	string toString() const { return "(" ~ to!string(x) ~ ", " ~ to!string(y) ~ ")"; }
}
auto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }

//	Array
int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }
int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <  val); }); }
int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }
T[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }

int N;
int[] A;

void main(string[] args) {
	try {
	for (; ; ) {
		N = readInt;
		A = new int[N];
		foreach (i; 0 .. N) {
			A[i] = readInt;
		}

		int ans;
		for (int i = 0, j; i < N; i = j) {
			for (; j < N && A[i] == A[j]; ++j) {}
			if (A[i] == 1) {
				ans += (j - i + 1);
			}
		}
		if (ans > 0) {
			--ans;
		}
		writeln(ans);
	}
	} catch (EOFException) {}
}


// Vicfred
// https://codeforces.com/contest/1430/problem/C
// math, greedy
import std.stdio;

void main() {
    int t;
    readf("%s\n", &t);

    int n;
    while(t--) {
        readf("%s\n", &n);

        "2".writeln;

        int x = n - 2;
        int y = n;
        writefln("%s %s", n - 1, n);

        for(int i = 0; i < n - 2; ++i) {
            writefln("%s %s", x, y);
            x -= 1;
            y -= 1;
        }
    }
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto t = RD!int;
	auto ans = new int[][][](t);
	auto ans2 = new int[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;

		BinaryHeap!(Array!int, "a < b") heap;
		foreach (i; 1..n+1)
		{
			heap.insert(i);
		}

		while (heap.length > 1)
		{
			auto x = heap.front; heap.removeFront;
			auto y = heap.front; heap.removeFront;
			ans[ti] ~= [x, y];
			heap.insert((x+y+1)/2);
		}
		ans2[ti] = heap.front;
	}

	foreach (ti; 0..t)
	{
		writeln(ans2[ti]);
		foreach (e; ans[ti])
		{
			writeln(e[0], " ", e[1]);
		}
	}
	stdout.flush;
	debug readln;
}


import std.algorithm, std.conv, std.stdio, std.string;
void main () {
	readln;
	stdin.byLine.each !(x => writeln ((x.strip.to!int + 1) / 2));
}

import std.container: DList;
import std.algorithm: all, map, count, filter;
import std.range: iota;
import std.array: array;
import std.stdio;
import std.utf;

DList!string _words;
void read(T)(out T t)
{
  import std.stdio: readln;
  while(_words.empty)
    {
      import std.array: split;
      foreach(word; readln.split)
        {
          _words.insertBack(word);
        }
    }
  import std.conv: to;
  string word = _words.front;
  _words.removeFront;
  t = to!T(word);
}

void main()
{
  int t;
  read(t);
  while(t--)
    {
      long n;
      read(n);
      writeln((n + n % 2)/2);
    }
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto t = RD!int;
	auto ans = new long[](t);
	foreach (ti; 0..t)
	{
		auto n = RD;
		ans[ti] = (n-1) / 2 + 1;
	}

	foreach (e; ans)
		writeln(e);

	stdout.flush;
	debug readln;
}


import std.algorithm;
import std.conv;
import std.numeric;
import std.range;
import std.stdio;
import std.string;

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		bool [int] b;

		void go (int v)
		{
			auto d = gcd (v, n);
			b[d] = true;
		}

		for (int d = 1; d * d <= n; d++)
		{
			go (d);
			go (n / d);
		}

		auto p = b.keys;
		bool [long] c;

		foreach (int q; p)
		{
			long res = n / q;
			res *= n - q;
			res /= 2;
			res += n / q;
			c[res] = true;
		}

		auto ans = c.keys;
		sort (ans);
		writefln ("%(%s %)", ans);
	}
}

import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

void main() {
    long n;
    scan(n);

    long[] ans;

    for (int d = 1; d*d <= n; d++) {
        if (n % d != 0) {
            continue;
        }
        ans ~= 1L * n * (n / d - 1) / 2 + n / d;
        auto c = n / d;
        ans ~= 1L * n * (n / c - 1) / 2 + n / c;
    }

    auto anss = ans.sort().uniq();

    writefln("%(%s %)", anss);
}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

void main() {
  import std.stdio, std.string, std.conv, std.algorithm;
  import std.range;

  // for (int n = 2; n <= 20; n++) {
  // auto ids = iota(n);
  // int[] ans;
  // for (int k = 1; k <= n; k++) {
  // int cur = k, s = 1;
  // while (cur % n) {
  // s += (cur + 1);
  // cur += k;
  // cur %= n;
  // }
  // ans ~= s;
  // }
  // ans = ans.sort.uniq.array;
  // writeln(n, " ", ans);
  // }

  long n;
  rd(n);
  long[] ans;
  for (long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      auto j = n / i;
      ans ~= i * (2 + (i - 1) * j) / 2;
      ans ~= j * (2 + (j - 1) * i) / 2;
    }
  }
  ans = ans.sort.uniq.array;
  writefln("%(%s %)", ans);
}

// 16
// 1 10 28 64 136
// 1  2  4  8  16
// 1 = 1
// 10 = 1 + 9
// 28 = 1 + 5 + 9 + 13
// 64 = 1 + 3 + 5 + 7 + 9 + 11 + 13 + 15

void rd(T...)(ref T x) {
  import std.stdio : readln;
  import std.string : split;
  import std.conv : to;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}


import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

void main ()
{
	int rows, cols;
	while (readf !(" %s %s") (rows, cols) > 0)
	{
		int [] [] board;
		readln;
		foreach (row; 0..rows)
		{
			board ~= readln.splitter.map !(to !(int)).array;
		}
		auto answer = new int [] [] (rows, cols);
		foreach (row; 0..rows)
		{
			foreach (col; 0..cols)
			{
				int value = 720_720;
				if ((row ^ col) & 1)
				{
					value -= board[row][col] ^^ 4;
				}
				answer[row][col] = value;
			}
		}
		writefln !("%(%(%s %)\n%)") (answer);
	}
}

// Cheese-Cracker: cheese-cracker.github.io

void main(){
    int n = scan!int;
    int m = scan!int;
    int[][] mat;
    for(int i = 0; i < n; ++i){
        mat ~= scanArray!int;
    }

    for(int i = 0; i < n; ++i){
        for(int j = 0; j < m; ++j){
            int colr = (i & 1) ^ (j & 1);
            if(!colr){
                mat[i][j] = 720720;
            }else{
                mat[i][j] *= mat[i][j];
                mat[i][j] *= mat[i][j];
                mat[i][j] += 720720;
            }
        }
    }
    foreach(row; mat){
        row.each!(cell => write(cell, " "));
        writeln;
    }
}

/**************    *****    That's All Folks!    *****    **************/
import std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;
string[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}
T[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }
void show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, "| ");} stderr.writeln; } }
alias ll = long, tup = Tuple!(long, "x",  long, "y");

import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

void get(Args...)(ref Args args)
{
    import std.traits, std.meta, std.typecons;

    static if (Args.length == 1) {
        alias Arg = Args[0];

        static if (isArray!Arg) {
          static if (isSomeChar!(ElementType!Arg)) {
            args[0] = readln.chomp.to!Arg;
          } else {
            args[0] = readln.split.to!Arg;
          }
        } else static if (isTuple!Arg) {
            auto input = readln.split;
            static foreach (i; 0..Fields!Arg.length) {
                args[0][i] = input[i].to!(Fields!Arg[i]);
            }
        } else {
            args[0] = readln.chomp.to!Arg;
        }
    } else {
        auto input = readln.split;
        assert(input.length == Args.length);

        static foreach (i; 0..Args.length) {
            args[i] = input[i].to!(Args[i]);
        }
    }
}

void get_lines(Args...)(size_t N, ref Args args)
{
    import std.traits, std.range;

    static foreach (i; 0..Args.length) {
        static assert(isArray!(Args[i]));
        args[i].length = N;
    }

    foreach (i; 0..N) {
        static if (Args.length == 1) {
            get(args[0][i]);
        } else {
            auto input = readln.split;
            static foreach (j; 0..Args.length) {
                args[j][i] = input[j].to!(ElementType!(Args[j]));
            }
        }
    }
}

enum X = 720720;
enum PP = [0, 13439, 106064, 189279, 106064, 330095, 388944, 106064, 106064, 189279, 560720, 486464, 388944, 263744, 106064, 670095, 106064];

void main()
{
    int N, M; get(N, M);
    int[][] aa; get_lines(N, aa);

    auto bb = new int[][](N, M);
    foreach (i; 0..N) foreach (j; 0..M) {
        if ((i + j) % 2 == 0) {
            bb[i][j] = X;
        } else {
            bb[i][j] = PP[aa[i][j]];
        }
    }
    writefln!"%(%(%d %)\n%)"(bb);
}


import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }

void main()
{
	auto t = RD!int;
	auto ans = new int[][](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;

		if (n <= 3) continue;
		if (n % 2)
		{
			foreach (i; 0..n/2-2)
			{
				ans[ti] ~= (i+1)*2;
			}
			ans[ti] ~= [n-1, n-3];
			while (n > 0)
			{
				ans[ti] ~= n;
				n -= 2;
			}
		}
		else
		{
			foreach (i; 0..n/2-2)
			{
				ans[ti] ~= i*2+1;
			}
			ans[ti] ~= [n-1, n-3];
			while (n > 0)
			{
				ans[ti] ~= n;
				n -= 2;
			}
		}
	}

	foreach (e; ans)
	{
		if (e.empty)
			writeln(-1);
		else
			e.map!(to!string).join(" ").writeln;
	}
	stdout.flush;
	debug readln;
}

import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto T = readln.chomp.to!int;
    foreach (_t; 0..T) {
        auto N = readln.chomp.to!int;
        if (N <= 3) {
            writeln(-1);
            continue;
        }

        auto rs = new int[](N);
        auto i = (N-1)/2;
        rs[i] = N;
        rs[i-1] = N-2;
        rs[i+1] = N-3;
        rs[i+2] = N-1;
        size_t l = i-2, r = i+3;
        auto n = N-4;
        for (;;) {
            if (n <= 0) break;
            rs[l--] = n--;
            if (n <= 0) break;
            rs[r++] = n--;
        }
        writeln(rs.to!(string[]).join(" "));
    }
}

// Author: Ivan Kazmenko (gassa@mail.ru)
import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

void main ()
{
	int [] [int] loops;
	loops[4] = [2, 4, 1, 3];
	loops[5] = [2, 5, 3, 1, 4];
	loops[6] = [2, 6, 4, 1, 3, 5];
	loops[7] = [2, 5, 7, 3, 1, 4, 6];

	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		if (n < 4)
		{
			writeln (-1);
		}
		else
		{
			int [] res;
			while (n > 0)
			{
				int k = (n >= 8) ? 4 : n;
				auto cur = loops[k].dup;
				cur[] += res.length.to !(int);
				res ~= cur;
				n -= k;
			}
			writefln !("%(%s %)") (res);
		}
	}
}

// Author: Ivan Kazmenko (gassa@mail.ru)
// permute at the center
import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;

void main ()
{
	auto tests = readln.strip.to !(int);
multitest_loop:
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto p = iota (1, n + 1).array;
		p = p.stride (2).array ~ p.drop (1).stride (2).retro.array;
		int lo = max (0, n / 2 - 2);
		int hi = min (n, n / 2 + 2);
		sort (p[lo..hi]);
		do
		{
			if (iota (1, n).all !(i =>
			    abs (p[i] - p[i - 1]) >= 2 &&
			    abs (p[i] - p[i - 1]) <= 4))
			{
				writefln !("%(%s %)") (p);
				continue multitest_loop;
			}
		}
		while (nextPermutation (p[lo..hi]));
		writeln (-1);
	}
}

import std.stdio;
import std.algorithm;
import std.range;
import std.conv;
import std.string;
import std.array;
import std.meta;
import std.random;

void main() {
	int t = readln.chomp.to!int;
	foreach (tt; 0 .. t) {
		int n = readln.chomp.to!int;
		if (n <= 3) {
			writeln(-1);
			continue;
		}
		int[] res;
		res.assumeSafeAppend ~= iota((n + 1) / 2 + 1)[1 .. $]
			.map!(x => x * 2 - n % 2).array;
		res.assumeSafeAppend ~= [n - 3, n - 1];
		res.assumeSafeAppend ~= iota((n + 1) / 2 - 2, -1, -1)[1 .. $]
			.map!(x => x * 2 - n % 2 + 1).array;
		if (res[$ - 1] == 0) {
			res = res[0 .. $ - 1];
		}
		writeln(res.map!(to!string).join(" "));
	}
}

import std.container;
import std.algorithm;
import std.range;
import std.array;
import std.stdio;
import std.utf;
import std.math;
import std.typecons;

alias type = multi;
struct TestCase
{
  mixin prettyPrinting;

  long n;

  void solve(long tc = -1)
  {
    if (n <= 3)
      return writeln(-1);
    long k = n % 2 == 1? 1 : 2;
    while(k <= n)
      {
        write(k, " ");
        k += 2;
      }
    k = n - 3;
    auto walk = chain([long(+2), long(-4)], repeat(long(-2)));
    while(k >= 1)
      {
        write(k, " ");
        k += walk.front;
        walk.popFront;
      }
    writeln;
  }
}

struct Interval
{
  long l, h;

  bool empty()
  {
    return l > h;
  }
}

Interval intersect(Interval a, Interval b)
{
  return Interval(max(a.l, b.l), min(a.h, b.h));
}

struct If
{
  string condition;
}
enum ignore = If("false");
struct Dim
{
  string dimensions;
  int levels;
  this(string dimensions)
  {
    this.dimensions = dimensions;
    levels = cast(int)dimensions.count(",") + 1;
  }
}

template getArrayLevel(W)
{
  static if (isDynamicArray!W && !is(W == string))
    enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));
  else
    enum getArrayLevel = 0;
}

static foreach(fieldName; 'a' .. cast(char)('z' + 1))
  {
    static if (fieldName != 'o')
      mixin("enum d", fieldName, " = Dim(\"", fieldName, "\");");
  }

mixin template prettyPrinting()
{
  string toString()
  {
    alias structType = typeof(this);
    auto res = appender!(string)();
    res.put(structType.stringof);
    res.put("(");
    static foreach(fieldName; FieldNameTuple!structType)
      {
        res.put(text(" ", fieldName, ": ", mixin(fieldName)));
      }
    res.put(" )");
    res.put("\n");
    return res[];
  }
}

struct Graph(N)
{
  size_t size;
  this(S)(S size)
  {
    adjacencyList.length = cast(size_t) size;
    this.size = cast(size_t) size;
    this.visited = makeSlice!bool(size);
  }
  N[][] adjacencyList;
  alias ne = neighbours;
  N[] neighbours(N n)
  {
    return adjacencyList.at(n);
  }
  alias bcon = biconnect;
  void biconnect(N a, N b)
  {
    adjacencyList.at(a) ~= b;
    adjacencyList.at(b) ~= a;
  }
  alias con = connect;
  void connect(N a, N b)
  {
    adjacencyList.at(a) ~= b;
  }
  void connect(R)(R edges)
  {
    foreach(ref edge; edges)
      {
        connect(edge[0], edge[1]);
      }
  }
  void biconnect(R)(R edges)
  {
    foreach(ref edge; edges)
      {
        biconnect(edge[0], edge[1]);
      }
  }
  alias deg = degree!long;
  auto degree(T)(N a)
  {
    return cast(T) adjacencyList.at(a).length;
  }

  auto visited = new bool[0];
  void dfs(Visitor)(long startNode)
  {
    auto visitor = Visitor.init;
    void internalDfs(long node)
    {
      visited.set(node, true);
      static if (is(typeof({visitor.n = node;})))
        visitor.n = node;
      static if (is(typeof({visitor.pre;})))
        visitor.pre;
      foreach(w; ne(node))
        if (!visited.at(w))
          {
            static if (is(typeof({visitor.w = w;})))
              visitor.w = w;
            static if (is(typeof(visitor.pren)))
              visitor.pren;
            internalDfs(w);
            static if (is(typeof(visitor.postn)))
              visitor.postn;
          }
      static if (is(typeof(visitor.post)))
        visitor.post;
    }
    internalDfs(startNode);
  }
  void dfs(long startNode)
  {
    struct DefVisitor {}
    dfs!DefVisitor(startNode);
  }
}

DList!string _words;

template removeArray(W, int times)
{
  static if (times == 0)
    alias removeArray = W;
  else static if (times == 1)
    alias removeArray = typeof(function(){W w; return w[0];}());
  else
    {
      static assert(isDynamicArray!W);
      alias removeArray = removeArray!(removeArray!(W, 1), times - 1);
    }
}

template baseType(W)
{
  static if (isDynamicArray!W && !is(W == string))
    alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));
  else
    alias baseType = W;
}

auto makeSlice(E, W, T...)(W size, T otherSizes)
{
  static if (T.length == 0)
    {
      E[] res;
      res.length = cast(size_t) size;
      return res;
    }
  else
    {
      typeof(makeSlice!E(otherSizes))[] res;
      res.length = cast(size_t) size;
      foreach(ref row; res)
        row = makeSlice!E(otherSizes);
      return res;
    }
}

void read(T...)(ref T t)
{
  void basicTypeRead(W)(ref W w)
  {
    import std.stdio: readln;
    while(_words.empty)
      {
        import std.array: split;
        foreach(word; readln.split)
          {
            _words.insertBack(word);
          }
      }
    import std.conv: to;
    string word = _words.front;
    _words.removeFront;
    w = to!W(word);
  }
  void iterableRead(W)(ref W w)
  {
    foreach(ref element; w)
      read(element);
  }
  void tupleRead(W)(ref W w)
  {
    static foreach(j; 0 .. W.length)
      read(w[j]);
  }
  void structRead(W)(ref W readStruct)
  {
    static foreach(fieldName; FieldNameTuple!W)
      {
        with(readStruct)
          {
            alias fieldSymbol = mixin(W.stringof, ".", fieldName);
            alias typeOfField = typeof(mixin(fieldName));
            static if (hasUDA!(fieldSymbol, If))
              enum condition = getUDAs!(fieldSymbol, If)[0].condition;
            else
              enum condition = "true";

            if (mixin(condition))
              {
                static if (hasUDA!(fieldSymbol, Dim))
                  {
                    static assert(isDynamicArray!(typeOfField)
                                  , text(W.stringof, ".", fieldName, " has Dim UDA but isn't a Dynamic Array."));
                    enum uda = getUDAs!(fieldSymbol, Dim)[0];
                    static assert(getArrayLevel!(typeOfField) == uda.levels,
                                  text(W.stringof, ".", fieldName, " has a Dim UDA with different number of dimensions than it's type."));
                    mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});
                  }
                else static if (isDynamicArray!typeOfField && !is(typeOfField == string))
                  {
                    pragma(msg, "Warning: You probably want to add dimension to input ", W.stringof, ".", fieldName);
                  }
                read(mixin(fieldName));
              }
          }
      }
  }
  static foreach(i; 0 .. T.length)
    {
      static if (isBasicType!(T[i]) || is(T[i] == string))
        basicTypeRead(t[i]);
      else static if (is(typeof({foreach(ref e; t[i]){}})))
        iterableRead(t[i]);
      else static if (isTuple!(T[i]))
        tupleRead(t[i]);
      else static if (isAggregateType!(T[i]))
        structRead(t[i]);
    }
}

auto next(T)()
{
  T t;
  read(t);
  return t;
}

size_t ind(T)(T t)
{
  return cast(size_t)t;
}

ref auto at(R, I)(ref R r, I i)
{
  return r[cast(size_t)i];
}

void set(R, I, V)(ref R r, I i, V v)
{
  r[cast(size_t)i] = v;
}

import std.conv;
import std.traits;
import std.meta;
int _loglevel = -1;
void _log(string functionName, argSeq...)()
{
  foreach(i; 0 .. _loglevel * 4)
    write(' ');
  write(functionName);
  static foreach(arg; argSeq)
    {
      write(" ", arg.stringof, " = ", arg);
    }
  writeln;
}
enum logCall =
  q{
    debug
    {
     {
     _loglevel++;
     alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, ".").back));
     static if (_parameterTuple.length > 0)
       mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(", ").array, `);`);
     else
       _log!(__FUNCTION__);
      }
     foreach(i; 0 .. _loglevel * 4) write(' ');
     writeln('{');
     scope(exit)
       {
         foreach(i; 0 .. _loglevel * 4) write(' ');
         writeln('}');
         _loglevel--;
       }
    }
};

void logSym(S...)(int line = __LINE__, string file = __FUNCTION__)
{
  debug
    {
      foreach(i; 0 .. _loglevel * 4) write(' ');
      write(file, "(", line, "):");
      static foreach(s; S)
        write(" ", s.stringof, " = ", s);
      writeln;

    }
}

Array!E makeArray(E, S)(S size, lazy E value)
{
  auto a = Array!E();
  a.length = cast(size_t) size;
  foreach(ref ai; a)
    ai = value();
  return a;
}
Array!E makeArray(E, S)(S size)
{
  auto a = Array!E();
  a.length = cast(size_t) size;
  return a;
}

template mem(alias F)
{
  ReturnType!F[Tuple!(Parameters!F)] table;
  ReturnType!F mem(Parameters!F args)
  {
    return table.require(tuple(args), F(args));
  }
}

string input(string names, string type = "long")
{
  return text(type, " ", names, "; read(", names, ");");
}

auto pmod(T, W)(T t, W w)
{
  return (t%w + w) % w;
}

void rep(S, F)(F f, S times)
{
  static if (is(typeof(f(i))))
    foreach(i; 0 .. times)
      f(i);
  else
    foreach(i; 0 .. times)
      f();
}

void multi()
{
  foreach(tc; 0 .. next!long)
    next!TestCase.solve(tc);
}

void single()
{
  auto tc = next!TestCase;
  tc.solve;
}

void main()
{
  type;
}


import core.bitop;
import core.checkedint;
import core.simd;
import core.stdc.stdlib;
import core.stdc.string;
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.bitmanip;
import std.complex;
import std.container;
import std.conv;
import std.datetime;
import std.format;
import std.functional;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.regex;
import std.stdio;
import std.string;
import std.typecons;
import std.variant;

__gshared:

bool read(T...)(T ptrs) if (ptrs.length > 0) {
    return readf(' ' ~ replicate("%s ", ptrs.length), ptrs) == ptrs.length;
}

auto pairwise(R)(R range) if (isForwardRange!R) {
    return lockstep(range, dropOne(range));
}

int n, shipCount, shipLen, k;
char[200_003] _s;

void main() {
    while (read(&n, &shipCount, &shipLen, &k)) {
        auto s = _s[ ];
        readln(s);
        s = s[0 .. $ - 1];
        int possible = 0;
        int cur = 0;
        foreach (c; s)
            if (c == '0') {
                if (++cur == shipLen) {
                    possible++;
                    cur = 0;
                }
            } else
                cur = 0;
        assert(possible >= shipCount);
        int need = possible - shipCount + 1;
        writeln(need);
        cur = 0;
        foreach (i, c; s)
            if (c == '0') {
                if (++cur == shipLen) {
                    write(i + 1, ' ');
                    cur = 0;
                    if (!--need)
                        break;
                }
            } else
                cur = 0;
        writeln();
    }
}

// Cheese-Cracker: cheese-cracker.github.io
import std.stdio, std.conv, std.functional, std.string, std.algorithm;
import std.container, std.range, std.typecons, std.bigint, std.numeric, std.math, std.random;

alias ll = long;
alias to!int isz;
alias rbt = redBlackTree;
static string[] inp;
T rd(T = long)(){ while(!inp.length) inp = readln.chomp.split; string res = inp[0]; inp.popFront; return res.to!T; }
T[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
alias pair = Tuple!(int, int);
/*******************************It's a Me, Mario!**********************************************/

void play(){
    int n, a, b, k;
    n = rd!int; a = rd!int; b = rd!int; k = rd!int;
    dchar[] shots = rd!(dchar[]);
    int cnt = 0;
    int boatmax = 0;
    foreach(i; 0..n){
        if(shots[i] == '1'){
            boatmax += (cnt/b);
            cnt = 0;
        }else{
            ++cnt;
        }
    }
    boatmax += cnt/b;
    debug writeln("boatmax: ", boatmax);
    auto meep = rbt!(true, pair);

    int[] shoot;
    int[int] breaks;
    foreach(i; 0..b-1){
        meep.insert(pair(shots[i]-'0', i));
    }
    foreach(i; b-1..n){
        meep.insert(pair(shots[i]-'0', i));

        if(meep.back[0] != 1){
            meep.removeKey(pair(0, i));
            meep.insert(pair(1, i));
            shots[i] = '1';
            shoot ~= i;
            /* ++breaks[shoot.back]; */
        }else if(shoot.length && meep.back[1] == shoot.back){
            /* breaks[shoot.back] = breaks.get(shoot.back, 0) + 1; */
            /* ++breaks[shoot.back]; */
        }
        meep.removeKey(pair(shots[i-b+1]-'0', i-b+1));
        if(boatmax - shoot.length < a) break;
    }
    writeln(shoot.length);
    foreach(cr; shoot){
        write(cr+1, " ");
    }
    writeln;
}

int main(){
    ll t = 1;
    /* t = rd;        // Toggle! */
    while(t--) play();  // Let's play!
    stdout.flush;
    return 0;
}

// Cheese-Cracker: cheese-cracker.github.io
import std.stdio, std.conv, std.functional, std.string, std.algorithm;
import std.container, std.range, std.typecons, std.bigint, std.numeric, std.math, std.random;

alias ll = long;
alias to!int isz;
alias rbt = redBlackTree;
static string[] inp;
T rd(T = long)(){ while(!inp.length) inp = readln.chomp.split; string res = inp[0]; inp.popFront; return res.to!T; }
T[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
/*******************************It's a Me, Mario!**********************************************/

void play(){
    int n, a, b, k;
    n = rd!int; a = rd!int; b = rd!int; k = rd!int;
    dchar[] shots = rd!(dchar[]);
    auto meep = rbt!(true, Tuple!(int, int, int));
    int cnt = 0, firsti = 1, lasti = 1;
    int boatmax = 0;
    foreach(i; 0..n){
        if(shots[i] == '1'){
            if(cnt/b) meep.insert(tuple(cnt, firsti, lasti));
            boatmax += cnt/b;
            firsti = i+2;
            cnt = 0;
        }else{
            ++cnt;
            lasti = i+1;
        }
    }
    if(cnt/b) meep.insert(tuple(cnt, firsti, lasti));
    boatmax += cnt/b;
    int part1, part2;
    int[] shoot;
    while(boatmax >= a && shoot.length < 20){
        // Select Max Broken
        int maxbreak = 0;
        Tuple!(int, int, int) shootout;
        foreach(tup; meep){
            part1 = tup[0]/2;
            part2 = tup[0] - part1 - 1;
            int breaks = (tup[0]/b) - (part1/b) - (part2/b);
            /* debug writeln("Parts: ", part1, " ", part2, " ", breaks); */
            if(breaks >= maxbreak){
                maxbreak = breaks;
                shootout = tup;
            }
        }

        // Break Interval
        meep.removeKey(shootout);
        part1 = shootout[0]/2;
        part2 = shootout[0] - part1 - 1;
        if(part1 >= b) meep.insert(tuple(part1, shootout[1], shootout[1] + part1 - 1));
        if(part2 >= b) meep.insert(tuple(part2, shootout[2] - part2 + 1, shootout[2]));
        // Take the shot
        shoot ~= shootout[2] - part2;
        // Update boatmax
        boatmax -= maxbreak;
        debug writeln(meep);
    }
    writeln(shoot.length);
    foreach(cr; shoot){
        write(cr, " ");
    }
    writeln;
}

int main(){
    ll t = 1;
    /* t = rd;        // Toggle! */
    while(t--) play();  // Let's play!
    stdout.flush;
    return 0;
}


import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto t = RD!int;
	auto ans = new bool[](t);
	foreach (ti; 0..t)
	{
		auto a = RD;
		auto b = RD;
		auto n = RD;
		auto m = RD;

		if (a+b < n+m) continue;
		if (min(a, b) >= m)
			ans[ti] = true;
	}

	foreach (e; ans)
		writeln(e ? "Yes" : "No");

	stdout.flush;
	debug readln;
}

import std.algorithm, std.stdio, std.string;
void main () {
	readln;
	long a, b, n, m;
	while (readf !(" %s %s %s %s") (a, b, n, m) > 0) {
		writeln (min (a, b) >= m && a + b >= n + m ? "Yes" : "No");
	}
}

import std.container;
import std.algorithm;
import std.range;
import std.array;
import std.stdio;
import std.utf;

DList!string _words;
void read(T)(out T t)
{
  import std.stdio: readln;
  while(_words.empty)
    {
      import std.array: split;
      foreach(word; readln.split)
        {
          _words.insertBack(word);
        }
    }
  import std.conv: to;
  string word = _words.front;
  _words.removeFront;
  t = to!T(word);
}

void main()
{
  int t;
  read(t);
 testCase:while(t--)
    {
      long[2] a;
      long n, m;
      read(a[0]), read(a[1]), read(n), read(m);
      sort(a[]);
      if (a[0] >= m)
        {
          long rem = a[0] - m + a[1];
          if (rem >= n)
            {
              writeln("Yes");
              continue testCase;
            }
        }
      writeln("No");
    }
}


import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto t = RD!int;
	auto ans = new long[](t);
	foreach (ti; 0..t)
	{
		auto p = RD;
		auto a = RD;
		auto b = RD;
		auto c = RD;

		auto ap = (a - (p % a)) % a;
		auto bp = (b - (p % b)) % b;
		auto cp = (c - (p % c)) % c;
		ans[ti] = min(ap, bp, cp);
	}

	foreach (e; ans)
		writeln(e);
	stdout.flush;
	debug readln;
}

import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

void get(Args...)(ref Args args)
{
    import std.traits, std.meta, std.typecons;

    static if (Args.length == 1) {
        alias Arg = Args[0];

        static if (isArray!Arg) {
          static if (isSomeChar!(ElementType!Arg)) {
            args[0] = readln.chomp.to!Arg;
          } else {
            args[0] = readln.split.to!Arg;
          }
        } else static if (isTuple!Arg) {
            auto input = readln.split;
            static foreach (i; 0..Fields!Arg.length) {
                args[0][i] = input[i].to!(Fields!Arg[i]);
            }
        } else {
            args[0] = readln.chomp.to!Arg;
        }
    } else {
        auto input = readln.split;
        assert(input.length == Args.length);

        static foreach (i; 0..Args.length) {
            args[i] = input[i].to!(Args[i]);
        }
    }
}

void get_lines(Args...)(size_t N, ref Args args)
{
    import std.traits, std.range;

    static foreach (i; 0..Args.length) {
        static assert(isArray!(Args[i]));
        args[i].length = N;
    }

    foreach (i; 0..N) {
        static if (Args.length == 1) {
            get(args[0][i]);
        } else {
            auto input = readln.split;
            static foreach (j; 0..Args.length) {
                args[j][i] = input[j].to!(ElementType!(Args[j]));
            }
        }
    }
}

void main()
{
    int T; get(T); while (T--) {
        long P, A, B, C; get(P, A, B, C);
        writeln([A, B, C].map!(x => P <= x ? x - P : P % x == 0 ? 0 : x - P % x).minElement());
    }
}

import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

void get(Args...)(ref Args args)
{
    import std.traits, std.meta, std.typecons;

    static if (Args.length == 1) {
        alias Arg = Args[0];

        static if (isArray!Arg) {
          static if (isSomeChar!(ElementType!Arg)) {
            args[0] = readln.chomp.to!Arg;
          } else {
            args[0] = readln.split.to!Arg;
          }
        } else static if (isTuple!Arg) {
            auto input = readln.split;
            static foreach (i; 0..Fields!Arg.length) {
                args[0][i] = input[i].to!(Fields!Arg[i]);
            }
        } else {
            args[0] = readln.chomp.to!Arg;
        }
    } else {
        auto input = readln.split;
        assert(input.length == Args.length);

        static foreach (i; 0..Args.length) {
            args[i] = input[i].to!(Args[i]);
        }
    }
}

void get_lines(Args...)(size_t N, ref Args args)
{
    import std.traits, std.range;

    static foreach (i; 0..Args.length) {
        static assert(isArray!(Args[i]));
        args[i].length = N;
    }

    foreach (i; 0..N) {
        static if (Args.length == 1) {
            get(args[0][i]);
        } else {
            auto input = readln.split;
            static foreach (j; 0..Args.length) {
                args[j][i] = input[j].to!(ElementType!(Args[j]));
            }
        }
    }
}

void main()
{
    int T; get(T); while (T--) {
        long P, A, B, C; get(P, A, B, C);
        writeln([A, B, C].map!(x => P <= x ? x - P : x - P % x).minElement());
    }
}


import std.algorithm;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(long)).array;

		long [] b;
		foreach (i; 1..n)
		{
			b ~= abs (a[i] - a[i - 1]);
		}

		int res = 1;
		int lo = 0;
		long cur = 0;
		for (int hi = 0; hi < n - 1; hi++)
		{
			long next = gcd (cur, b[hi]);
			if (next == 1)
			{
				next = 0;
				lo = hi + 1;
				while (lo > 0)
				{
					long temp = gcd (next, b[lo - 1]);
					if (temp == 1)
					{
						break;
					}
					lo -= 1;
					next = temp;
				}
			}
			cur = next;
			res = max (res, hi - lo + 2);
		}
		writeln (res);
	}
}

import std.stdio;
import std.numeric;
import std.math;
import std.ascii;
import std.algorithm;
import std.range;
import core.stdc.stdio;

void main()
{
	int t = readInt!int;
	while (t--) solve;
}
void solve()
{
	int n = readInt!int;
	auto a = new long[](n);
	foreach(ref ai; a) ai = readInt!long;
	auto da = new long[](n - 1);
	foreach(i; 0 .. n - 1)
	{
		da[i] = abs(a[i + 1] - a[i]);
	}
	int mxp2 = cast(int)log2(n);
	auto gcdTable = new long[][](mxp2 + 1, n - 1);
	gcdTable[0][] = da[];
	foreach(p; 1 .. mxp2 + 1)
	{
		foreach(i; 0 .. n - 1)
		{
			if (i + (1 << p) <= n - 1)
				gcdTable[p][i] = gcd(gcdTable[p-1][i], gcdTable[p-1][i+(1<<(p-1))]);
		}
	}
	long getGcd(int s, int e)
	{
		if (s > e) return 0;
		int len = e - s + 1;
		int mxp = cast(int)log2(len);
		int mxpn = (1 << mxp);
		long p1 = gcdTable[mxp][s];
		long p2 = gcdTable[mxp][e + 1 - mxpn];
		return gcd(p1, p2);
	}
	debug
	{
		foreach(i; 0 .. n - 1)
		{
			foreach(j; i .. n - 1)
			{
				assert(getGcd(i, j) == da[i .. j + 1].fold!gcd(0L));
			}
		}
	}
	int j = 0;
	int maxlen = 1;
	foreach(i; 0 .. n - 1)
	{
		while (j <= i && getGcd(j, i) == 1) j++;
		maxlen = max(maxlen, i - j + 2);
	}
	maxlen.writeln;
}

/* INPUT ROUTINES */
int currChar;
static this()
{
	currChar = getchar();
}

char topChar()
{
	return cast(char) currChar;
}

void popChar()
{
	currChar = getchar();
}

auto readInt(T)()
{
	T num = 0;
	int sgn = 0;
	while (topChar.isWhite)
		popChar;
	while (topChar == '-' || topChar == '+')
	{
		sgn ^= (topChar == '-');
		popChar;
	}
	while (topChar.isDigit)
	{
		num *= 10;
		num += (topChar - '0');
		popChar;
	}
	if (sgn)
		return -num;
	return num;
}

string readString()
{
	string res = "";
	while (topChar.isWhite)
		popChar;
	while (!topChar.isWhite)
	{
		res ~= topChar;
		popChar;
	}
	return res;
}
/**MODULAR SYSTEM*/
struct Z(immutable long m)
{
	long rep;
	this(long num)
	{
		rep = num;
	}

	Z!m opBinary(string operator)(Z!m rhs)
	{
		static if (operator == "+")
		{
			long result = rhs.rep + this.rep;
			if (result >= m)
				result -= m;
			return Z!m(result);
		}
		else static if (operator == "-")
		{
			long result = this.rep - rhs.rep;
			if (result < 0)
				result += m;
			return Z!m(result);
		}
		else static if (operator == "*")
		{
			long result = this.rep * rhs.rep;
			if (result >= m)
				result %= m;
			return Z!m(result);
		}
		else
			static assert(text("Operator ", operator, " not supported"));
	}

	Z!m opBinary(string operator)(long exponent) if (operator == "^^")
	{
		assert(exponent >= 0);
		Z!m base = this;
		Z!m result = 1;
		while (exponent)
		{
			if (exponent & 1)
				result = result * base;
			base = base * base;
			exponent >>= 1;
		}
		return result;
	}

	invariant
	{
		assert(rep >= 0 && rep < m);
	}
}

import std.stdio;
import std.numeric;
import std.math;
import std.ascii;
import std.algorithm;
import std.range;
import core.stdc.stdio;

void main()
{
	int t = readInt!int;
	while (t--) solve;
}
void solve()
{
	int n = readInt!int;
	auto a = new long[](n);
	foreach(ref ai; a) ai = readInt!long;
	auto da = new long[](n - 1);
	foreach(i; 0 .. n - 1)
	{
		da[i] = abs(a[i + 1] - a[i]);
	}
	int mxp2 = cast(int)log2(n);
	auto gcdTable = new long[][](mxp2 + 1, n - 1);
	gcdTable[0][] = da[];
	foreach(p; 1 .. mxp2 + 1)
	{
		foreach(i; 0 .. n - 1)
		{
			if (i + (1 << p) <= n - 1)
				gcdTable[p][i] = gcd(gcdTable[p-1][i], gcdTable[p-1][i+(1<<(p-1))]);
		}
	}
	long getGcd(int s, int e)
	{
		if (s > e) return 0;
		int len = e - s + 1;
		int mxp = cast(int)log2(len);
		int mxpn = (1 << mxp);
		long p1 = gcdTable[mxp][s];
		long p2 = gcdTable[mxp][e + 1 - mxpn];
		return gcd(p1, p2);
	}
	int j = 0;
	int maxlen = int.min;
	foreach(i; 0 .. n - 1)
	{
		while (j <= i && getGcd(j, i) == 1) j++;
		maxlen = max(maxlen, i - j + 1);
	}
	(maxlen + 1).writeln;
}

/* INPUT ROUTINES */
int currChar;
static this()
{
	currChar = getchar();
}

char topChar()
{
	return cast(char) currChar;
}

void popChar()
{
	currChar = getchar();
}

auto readInt(T)()
{
	T num = 0;
	int sgn = 0;
	while (topChar.isWhite)
		popChar;
	while (topChar == '-' || topChar == '+')
	{
		sgn ^= (topChar == '-');
		popChar;
	}
	while (topChar.isDigit)
	{
		num *= 10;
		num += (topChar - '0');
		popChar;
	}
	if (sgn)
		return -num;
	return num;
}

string readString()
{
	string res = "";
	while (topChar.isWhite)
		popChar;
	while (!topChar.isWhite)
	{
		res ~= topChar;
		popChar;
	}
	return res;
}
/**MODULAR SYSTEM*/
struct Z(immutable long m)
{
	long rep;
	this(long num)
	{
		rep = num;
	}

	Z!m opBinary(string operator)(Z!m rhs)
	{
		static if (operator == "+")
		{
			long result = rhs.rep + this.rep;
			if (result >= m)
				result -= m;
			return Z!m(result);
		}
		else static if (operator == "-")
		{
			long result = this.rep - rhs.rep;
			if (result < 0)
				result += m;
			return Z!m(result);
		}
		else static if (operator == "*")
		{
			long result = this.rep * rhs.rep;
			if (result >= m)
				result %= m;
			return Z!m(result);
		}
		else
			static assert(text("Operator ", operator, " not supported"));
	}

	Z!m opBinary(string operator)(long exponent) if (operator == "^^")
	{
		assert(exponent >= 0);
		Z!m base = this;
		Z!m result = 1;
		while (exponent)
		{
			if (exponent & 1)
				result = result * base;
			base = base * base;
			exponent >>= 1;
		}
		return result;
	}

	invariant
	{
		assert(rep >= 0 && rep < m);
	}
}


import std.stdio, std.getopt, std.random, std.range, std.string, std.conv;
import std.algorithm, std.container, std.datetime, std.typecons;

const MD = 10^^9+7;

alias Tl = Tuple!(long, long);

long powMod(long x, long n, long md) {
    long r = 1;
    while (n) {
        if (n & 1) r *= x; r %= md;
        x *= x; x %= md;
        n >>= 1;
    }
    return r;
}

//-------------------------------------------------------//

int n;
int[] d;
string[] t;

Tl[][] dp;
bool[][] used;
Tl calc(int ad, int c) {
	if (ad == n) return Tl(c, 1);
	if (d[ad] != c) return calc(ad+1, c);
	if (used[ad][c]) return dp[ad][c];
	used[ad][c] = true;
	Tl res = [0,0];
	foreach_reverse (u; t[ad]) {
		auto r = calc(ad+1, u-'0');
		res[0] += r[0]*powMod(10, res[1], MD) % MD;
		res[1] += r[1];
		res[0] %= MD;
		res[1] %= MD-1;
	}
	dp[ad][c] = res;
	return res;
}

long solve() {
	auto s = readln().strip();
	readf("%d\n", &n); n++;
	d = new int[n]; t = new string[n];
	d[0] = 0; t[0] = s;
	foreach (i; 1..n) {
//		readf("%d", &d[i]);
		readf("%d->%s\n", &d[i], &t[i]);
	}

	dp = new Tl[][](n, 10);
	used = new bool[][](n, 10);
	return calc(0, 0)[0]%MD;
}

int main() {
    writeln(solve());
    return 0;
}

import core.thread;
import std.conv, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;

//	Input
class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }
int readInt() { return to!int(readToken); }
long readLong() { return to!long(readToken); }
real readReal() { return to!real(readToken); }

//	chmin/chmax
void chmin(T)(ref T t, in T f) { if (t > f) t = f; }
void chmax(T)(ref T t, in T f) { if (t < f) t = f; }

//	Pair
struct Pair(S, T) {
	S x; T y;
	int opCmp(    const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }
	int opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }
	string toString() const { return "(" ~ to!string(x) ~ ", " ~ to!string(y) ~ ")"; }
}
auto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }

//	Array
int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }
int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <  val); }); }
int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }
T[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }

immutable long MO = 1000000007;
immutable L = 10;

string S;
int N;
string[] A;

void main(string[] args) {
	try {
	for (; ; ) {
		S = readToken;
		N = readInt;
		A = new string[N];
		foreach (i; 0 .. N) {
			A[i] = readToken;
		}

		long[][] vals = new long[][](N + 1, L);
		long[][] muls = new long[][](N + 1, L);
		foreach (x; 0 .. L) {
			vals[N][x] = x;
			muls[N][x] = L;
		}

		foreach_reverse (i; 0 .. N) {
			foreach (x; 0 .. L) {
				if (x == A[i][0] - '0') {
					vals[i][x] = 0;
					muls[i][x] = 1;
					foreach (c; A[i][3 .. $]) {
						const int y = c - '0';
						vals[i][x] = (vals[i][x] * muls[i + 1][y] + vals[i + 1][y]) % MO;
						muls[i][x] = (muls[i][x] * muls[i + 1][y]) % MO;
					}
				} else {
					vals[i][x] = vals[i + 1][x];
					muls[i][x] = muls[i + 1][x];
				}
			}
		}

		long ans;
		foreach (c; S) {
			const int y = c - '0';
			ans = (ans * muls[0][y] + vals[0][y]) % MO;
		}
		writeln(ans);
	}
	} catch (EOFException) {}
}

import std.stdio, std.getopt, std.random, std.range, std.string, std.conv;
import std.algorithm, std.container, std.datetime, std.typecons;

const MD = 10^^9+7;

alias Tl = Tuple!(long, long);

long powMod(long x, long n, long md) {
    long r = 1;
    while (n) {
        if (n & 1) r *= x; r %= md;
        x *= x; x %= md;
        n >>= 1;
    }
    return r;
}

void powModTable(long[] d, long b, long md) {
	assert(d.length > 0);
	d[0] = 1;
	foreach (i; 1..d.length) {
		d[i] = (d[i-1]*b)%md;
	}
}
//-------------------------------------------------------//

int n;
int[] d;
string[] t;

Tl[][] dp;
bool[][] used;
Tl calc(int ad, int c) {
	if (ad == n) return Tl(c, 1);
	if (d[ad] != c) return calc(ad+1, c);
	if (used[ad][c]) return dp[ad][c];
	Tl res = [0,0];
	foreach_reverse (u; t[ad]) {
		auto r = calc(ad+1, u-'0');
		res[0] += r[0]*powMod(10, res[1], MD);
		res[1] += r[1];
	}
	dp[ad][c] = res;
	return res;
}

long solve() {
	auto s = readln().strip();
	readf("%d\n", &n); n++;
	d = new int[n]; t = new string[n];
	d[0] = 0; t[0] = s;
	foreach (i; 1..n) {
//		readf("%d", &d[i]);
		readf("%d->%s\n", &d[i], &t[i]);
	}

	dp = new Tl[][](n, 10);
	used = new bool[][](n, 10);
	return calc(0, 0)[0]%MD;
}

int main() {
    writeln(solve());
    return 0;
}

import std.stdio, std.getopt, std.random, std.range, std.string, std.conv;
import std.algorithm, std.container, std.datetime, std.typecons;

const MD = 10^^9+7;

alias Tl = Tuple!(long, long);

long powMod(long x, long n, long md) {
    long r = 1;
    while (n) {
        if (n & 1) r *= x; r %= md;
        x *= x; x %= md;
        n >>= 1;
    }
    return r;
}

//-------------------------------------------------------//

int n;
int[] d;
string[] t;

Tl[][] dp;
bool[][] used;
Tl calc(int ad, int c) {
	if (ad == n) return Tl(c, 1);
	if (d[ad] != c) return calc(ad+1, c);
	if (used[ad][c]) return dp[ad][c];
	used[ad][c] = true;
	Tl res = [0,0];
	foreach_reverse (u; t[ad]) {
		auto r = calc(ad+1, u-'0');
		res[0] += r[0]*powMod(10, res[1], MD) % MD;
		res[1] += r[1];
		res[0] %= MD;
		res[1] %= MD;
	}
	dp[ad][c] = res;
	return res;
}

long solve() {
	auto s = readln().strip();
	readf("%d\n", &n); n++;
	d = new int[n]; t = new string[n];
	d[0] = 0; t[0] = s;
	foreach (i; 1..n) {
//		readf("%d", &d[i]);
		readf("%d->%s\n", &d[i], &t[i]);
	}

	dp = new Tl[][](n, 10);
	used = new bool[][](n, 10);
	return calc(0, 0)[0]%MD;
}

int main() {
    writeln(solve());
    return 0;
}


// Vicfred
// https://codeforces.com/contest/1516/problem/B
//
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

void main() {
    int t = readln.chomp.to!int;

while(t--) {
    int n = readln.chomp.to!int;
    int[] a = readln.split.map!(to!int).array;
    a = 0 ~ a;

    int[] cum = new int[n + 1];
    for(int i = 1; i <= n; ++i) {
        cum[i] = cum[i - 1] ^ a[i];
    }

    bool found = !cum[n];
    for(int i = 1; i <= n; ++i) {
        for(int j = i + 1; j < n; ++j) {
            found |= (cum[i] == (cum[j]^cum[i]) &&
                      cum[i] == (cum[n]^cum[j]));
        }
    }
    if(found)
        "YES".writeln;
    else
        "NO".writeln;
}
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto t = RD!int;
	auto ans = new bool[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto a = RDA;

		long tot;
		foreach (i; 0..n)
			tot ^= a[i];
		if (tot == 0)
		{
			ans[ti] = true;
			continue;
		}
		foreach (i; 1..n)
		{
			long x, y;
			long cx, cy;
			foreach (j; 0..i)
			{
				x ^= a[j];
				if (x == tot)
				{
					++cx;
					x = 0;
				}
			}
			foreach (j; i..n)
			{
				y ^= a[j];
				if (y == tot)
				{
					++cy;
					y = 0;
				}
			}
			if (x == 0 && y == 0 && (cx != 0 && cy != 0))
			{
				ans[ti] = true;
				break;
			}
		}
	}

	foreach (e; ans)
		writeln(e ? "YES" : "NO");
	stdout.flush;
	debug readln;
}

import std.stdio, std.string;
import std.math, std.algorithm;
import std.numeric, std.bigint;
import std.container, std.array;
import std.typecons, std.range;
import std.conv, std.random;

string solve(int[] a)
{
    auto n = to!int(a.length);
    int tmask;
    foreach (i; 0 .. n - 1)
    {
        tmask ^= a[i];
        int mask;
        bool matched, occured;
        foreach (j; i + 1 .. n)
        {
            mask ^= a[j];
            if (mask != tmask) matched = false;
            else mask = 0, matched = occured = true;
        }
        if (matched || occured && mask == 0) return "YES";
    }
    return "NO";
}

int main(string[] args)
{
    auto t = to!int(readln.strip);
    foreach (_; 0 .. t)
    {
        readln;
        auto a = map!(to!int)(readln.strip.split(" ")).array;
        auto ret = solve(a);
        writeln(ret);
    }
    return 0;
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto t = RD!int;
	auto ans = new bool[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto a = RDA;

		long tot;
		foreach (i; 0..n)
			tot ^= a[i];
		if (tot == 0)
		{
			ans[ti] = true;
			continue;
		}
		foreach (i; 1..n)
		{
			long x, y;
			foreach (j; 0..i)
				x ^= a[j];
			foreach (j; i..n)
				y ^= a[j];
			if (x == y)
			{
				ans[ti] = true;
				break;
			}
		}
	}

	foreach (e; ans)
		writeln(e ? "YES" : "NO");
	stdout.flush;
	debug readln;
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto t = RD!int;
	auto ans = new bool[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto a = RDA;

		foreach (i; 1..n)
		{
			long x, y;
			foreach (j; 0..i)
				x ^= a[j];
			foreach (j; i..n)
				y ^= a[j];
			if (x == y)
			{
				ans[ti] = true;
				break;
			}
		}
	}

	foreach (e; ans)
		writeln(e ? "YES" : "NO");
	stdout.flush;
	debug readln;
}

import std.stdio, std.string;
import std.math, std.algorithm;
import std.numeric, std.bigint;
import std.container, std.array;
import std.typecons, std.range;
import std.conv, std.random;

string solve(int[] a)
{
    auto n = to!int(a.length);
    int tmask;
    foreach (i; 0 .. n - 1)
    {
        tmask ^= a[i];
        int mask;
        bool f;
        foreach (j; i + 1 .. n)
        {
            mask ^= a[j];
            if (mask != tmask) f = false;
            else mask = 0, f = true;
        }
        if (f) return "YES";
    }
    return "NO";
}

int main(string[] args)
{
    auto t = to!int(readln.strip);
    foreach (_; 0 .. t)
    {
        readln;
        auto a = map!(to!int)(readln.strip.split(" ")).array;
        auto ret = solve(a);
        writeln(ret);
    }
    return 0;
}


import std.algorithm;
import std.conv;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

immutable int q1 = 987_654_319;
immutable int q2 = 987_654_299;
immutable int maxN = 1_000_007;

void main ()
{
	int p1 = uniform (123_456_789, 444_333_222) * 2 + 1;
	int p2 = uniform (123_456_789, 444_333_222) * 2 + 1;
	int [] p1pow = [1];
	p1pow.reserve (maxN + 1);
	int [] p2pow = [1];
	p2pow.reserve (maxN + 1);
	foreach (i; 0..maxN)
	{
		p1pow ~= (p1pow.back * 1L * p1) % q1;
		p2pow ~= (p2pow.back * 1L * p2) % q2;
	}

	int tests;
	readf !(" %s") (tests);
	readln;
	foreach (test; 0..tests)
	{
		auto s = readln.strip;

		string lo = "";
		while (s.length >= 2 && s[0] == s[$ - 1])
		{
			lo ~= s[0];
			s = s[1..$ - 1];
		}
		string hi = lo.retro.text;

		auto n = s.length.to !(int);

		void calc (ref int [] h1, ref int [] h2, const ref string r)
		{
			h1[0] = 0;
			h2[0] = 0;
			foreach (i; 0..n)
			{
				h1[i + 1] = (h1[i] * 1L * p1 + r[i]) % q1;
				h2[i + 1] = (h2[i] * 1L * p2 + r[i]) % q2;
			}
		}

		auto h1lo = new int [n + 1];
		auto h2lo = new int [n + 1];
		calc (h1lo, h2lo, s);

		auto t = s.retro.text;
		auto h1hi = new int [n + 1];
		auto h2hi = new int [n + 1];
		calc (h1hi, h2hi, t);
		reverse (h1hi);
		reverse (h2hi);

		int bestLo = 0;
		foreach (i; 1..n + 1)
		{
			if ((h1hi[0] - h1hi[i] * 1L * p1pow[i] -
			    h1lo[i]) % q1 == 0 &&
			    (h2hi[0] - h2hi[i] * 1L * p2pow[i] -
			    h2lo[i]) % q2 == 0)
			{
				bestLo = i;
			}
		}

		reverse (h1lo);
		reverse (h2lo);
		reverse (h1hi);
		reverse (h2hi);
		swap (h1lo, h1hi);
		swap (h2lo, h2hi);
		int bestHi = 0;
		foreach (i; 1..n + 1)
		{
			if ((h1hi[0] - h1hi[i] * 1L * p1pow[i] -
			    h1lo[i]) % q1 == 0 &&
			    (h2hi[0] - h2hi[i] * 1L * p2pow[i] -
			    h2lo[i]) % q2 == 0)
			{
				bestHi = i;
			}
		}

		if (bestLo > bestHi)
		{
			lo ~= s[0..bestLo];
		}
		else
		{
			hi = s[$ - bestHi..$] ~ hi;
		}
		writeln (lo, hi);
	}
}

// Code By H~$~C

module main;

import std.stdio, std.array, std.string, std.math, std.uni, std.format, std.bigint;
import std.algorithm, std.conv, std.container, std.range, std.functional;
import std.random, std.typecons;

// FIXME
int[] buildZ(in string s) {
  int n = cast(int)(s.length);
  int[] z; z.length = n;
  for (int i = 1, l = 0, r = 0; i < n; ++i) {
    if (i <= r) z[i] = (z[i - l] < r - i + 1 ? z[i - l] : r - i + 1);
    while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i];
    if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
  }
  return z;
}

void solve(in int testcase) {
  string s, t;
  s.read;
  int n = cast(int)(s.length), m;
  for (int i = 0; i < n; ++i)
    t ~= s[n - i - 1];
  if (s == t) {
    s.writeln;
    return ;
  }
  int[] z = buildZ(s ~ '$' ~ t);
  int x = z[n + 1];
  string ans1 = s[0 .. x];
  string ans2 = "";
  int mx = 0;
  string p = s[x .. n - x];
  string o;
  {
    n = cast(int)(p.length), m = n * 2 + 1;
    t = "";
    for (int i = 0; i < n; ++i)
      t ~= p[n - i - 1];
    o = p ~ '$' ~ t;
    z = buildZ(o);
    for (int i = m - 1; i >= 0; --i) {
      if (z[i] == m - i && mx < m - i) {
        mx = m - i;
        ans2 = o[i .. $];
      }
    }
  }
  p = t;
  {
    n = cast(int)(p.length), m = n * 2 + 1;
    t = "";
    for (int i = 0; i < n; ++i)
      t ~= p[n - i - 1];
    o = p ~ '$' ~ t;
    z = buildZ(o);
    for (int i = m - 1; i >= 0; --i) {
      if (z[i] == m - i && mx < m - i) {
        mx = m - i;
        ans2 = o[i .. $];
      }
    }
  }
  string ans3;
  for (int i = 0; i < x; ++i)
    ans3 ~= ans1[x - i - 1];
  (ans1 ~ ans2 ~ ans3).writeln;
}

// ************************************************************

T reader(T)() { return readToken().to!T; }
void read(T)(ref T t) { t = reader!T; }
T[] readarray(T)() { return readln.splitter.map!(to!T).array; }
void chmax(T)(ref T a, T b) { a = max(a, b); }
void chmin(T)(ref T a, T b) { a = min(a, b); }
alias less = (a, b) => a < b;
alias greater = (a, b) => a > b;
T min_element(T)(in T[] a) { return a.element!less; }
T max_element(T)(in T[] a) { return a.element!greater; }
alias unique = uniq;

// constant or some variables
immutable int inf = 0x3f3f3f3f;
immutable long lnf = 0x3f3f3f3f3f3f3f3f;
immutable typeof(null) NULL = null;
string[] _tokens;

// functions
T element(alias pred, T)(in T[] a) {
  int pos = 0;
  for (int i = 1; i < cast(int)(a.length); ++i)
    if (binaryFun!pred(a[i], a[pos])) pos = i;
  return a[pos];
}
string readToken() {
  for (; _tokens.empty; ) {
    if (stdin.eof) return "";
    _tokens = readln.split;
  }
  auto token = _tokens.front;
  _tokens.popFront;
  return token;
}
int binary_bearch(alias pred, T)(in T[] as) {
  int l = -1, h = cast(int)(as.length), mid;
  for (; l + 1 < h; ) {
    mid = (l + h) >> 1;
    (unaryFun!pred(as[mid]) ? h : l) = mid;
  }
  return h;
}
int lower_bound(alias pred = less, T)(in T[] as, T val) {
  return as.binary_bearch!(a => a == val || pred(val, a));
}
int upper_bound(alias pred = less, T)(in T[] as, T val) {
  return as.binary_bearch!(a => pred(val, a));
}

void main(string[] args) {
  int tests = 1;
  tests.read();
  foreach(test; 1 .. tests + 1) solve(test);
}

import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0;
void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
    A: foreach(_; 0 .. scan!int){
        string s = scan;
        int n = s.length.to!int;

        int a = 0, b = n - 1;
        while(a < b){
            log("a:", a, "b:", b, "s[a]:", s[a], "s[b]:", s[b]);
            if(s[a] != s[b]) break;
            a ++, b --;
        }
        if(a >= b){
            s.writeln;
            continue A;
        }
        log("a:", a, "b:", b);

        bool isPalin(int u, int v){ // s[u .. v] is palin.
            log("u:", u, "v:", v, "s[u..v]:", s[u .. v]);
            int i = u, j = v - 1;
            while(i < j){
                if(s[i] != s[j]) return 0;
                i ++, j --;
            }
            return 1;
        }

        foreach_reverse(i; 0 .. b - a + 1){
            if(isPalin(a, a + i)){
                (s[0 .. a + i] ~ s[b + 1 .. $]).writeln;
                continue A;
            }
            if(isPalin(b - i + 1, b + 1)){
                (s[0 .. a] ~ s[b - i + 1 .. $]).writeln;
                continue A;
            }
        }
    }
}

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }

int[] manacher(T)(T a) {
  const n = cast(int)(a.length);
  auto r = new int[n * 2];
  for (int i = 0, j = 0, k; i < n * 2; i += k, j = max(j - k, 0)) {
    for (; 0 <= i - j && i + j + 1 < n * 2 && a[(i - j) / 2] == a[(i + j + 1) / 2]; ++j) {}
    r[i] = j;
    for (k = 1; 0 <= i - k && 0 <= j - k && r[i - k] != j - k; ++k) {
      r[i + k] = min(r[i - k], j - k);
    }
  }
  return r;
}

void main() {
  try {
    for (; ; ) {
      const numCases = readInt();
      foreach (caseId; 0 .. numCases) {
        const S = readToken();
        const L = cast(int)(S.length);

        const rads = manacher(S);
        debug {
          writeln("rads = ", rads);
        }

        auto ls = new int[L + 1];
        ls[] = -1;
        foreach (x; 0 .. L) {
          // x - rads[x] <= 2 k
          chmax(ls[(x - rads[x] + 1) / 2], x);
        }
        foreach (k; 1 .. L + 1) {
          chmax(ls[k], ls[k - 1]);
        }
        auto rs = new int[L + 1];
        rs[] = 2 * L;
        foreach (x; L - 1 .. 2 * L - 1) {
          // 2 (L - 1 - k) <= x + rads[x]
          chmin(rs[(2 * (L - 1) - x - rads[x] + 1) / 2], x);
        }
        foreach (k; 1 .. L + 1) {
          chmin(rs[k], rs[k - 1]);
        }
        debug {
          writeln("ls = ", ls);
          writeln("rs = ", rs);
        }

        int ansA, ansB;
        void check(int a, int b) {
          if (ansA + ansB < a + b) {
            ansA = a;
            ansB = b;
          }
        }
        foreach (k; 0 .. L + 1) {
          check(k, k);
          if (ls[k] != -1) {
            const i = k;
            const j = ls[k] - i;
            check(k + (j - i + 1), k);
          }
          if (rs[k] != 2 * L) {
            const i = L - 1 - k;
            const j = rs[k] - i;
            check(k, (i - j + 1) + k);
          }
          if ((k + 1) + (k + 1) > L) {
            break;
          }
          if (S[k] != S[L - 1 - k]) {
            break;
          }
        }
        writeln(S[0 .. ansA] ~ S[L - ansB .. L]);
      }
    }
  } catch (EOFException e) {
  }
}


module _template;
import std.stdio;
import std.string;
import std.algorithm;
import std.container;
import std.range;
import std.math;
import std.numeric;
import std.conv;
import std.typecons;
import std.format;

struct IO {
        string read_string() {
                while (tokens.empty) {
                tokens = readln.split;
        }
        auto token = tokens.front;
                tokens.popFront;
                return token;
        }

        int read_int() {
                return read_string.to!int;
        }

        double read_double() {
                return read_string.to!double;
        }

        string[] tokens;
}

void main() {
        IO cin;
        int t = 1;
        // t = cin.read_int;
        while (t--) {
                int n = cin.read_int;
                int[] arr = new int[n];
                for (int i = 0; i < n; i++) {
                        arr[i] = cin.read_int;
                }
                int[] alice = new int[n];
                int[] bob = new int[n];

                alice[0] = arr[0];
                for (int i = 1; i < n; i++) {
                        alice[i] = alice[i - 1] + arr[i];
                }

                reverse(arr);

                bob[0] = arr[0];
                for (int i = 1; i < n; i++) {
                        bob[i] = bob[i - 1] + arr[i];
                }

                reverse(arr);

                int total_time = sum(arr[0..$]);
                bool[] eaten = new bool[n];

                int alice_a = 0;
                int bob_a = 0;
                int curr_a = 0;
                int curr_b = 0;

                for (int i = 0; i <= total_time; i++) {
                        if (i == alice[curr_a] && eaten[curr_a] == false) {
                                eaten[curr_a] = true;
                                alice_a++;
                                curr_a++;
                        }
                        if (i == bob[curr_b] && eaten[n - 1 - curr_b] == false) {
                                eaten[n - 1 - curr_b] = true;
                                bob_a++;
                                curr_b++;
                        }
                }
                writeln(alice_a, " ", bob_a);
        }
}

import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.conv;

int main() {
    debug stdin = File("in.txt", "r");

    int n;
    readf(" %s\n", &n);
    int[] bar = new int[n + 2];
    int[] cumbar = new int[n + 2];
    foreach (i ; 1 .. n + 1) {
        readf(" %s", &bar[i]);
        cumbar[i] = bar[i] + cumbar[i - 1];
    }
    int cumrev;
    int alice, bob;
    foreach_reverse (i ; 2 .. n + 2) {
        cumrev += bar[i];
        if (cumbar[i - 2] - cumrev <= bar[i - 1]) {
            if (cumrev < cumbar[i - 2]) alice = i - 2;
            else alice = i - 1;
            bob = n - alice;
            break;
        }
    }
    writeln(alice, " ", bob);

    return 0;
}

import std.stdio;
import std.string;
import std.array;

void main(char[][] args)
{
    version(MY_SUPER_PUPER_ONLINE_JUDGE)
    {
        stdin.open("src/input.txt", "rt");
        stdout.open("src/output.txt","wt");
    }
    int n;
    readf("%d\n", &n);
    int[] a = new int[n], sum = new int[n + 1];
    sum[0] = 0;
    for(int i = 0; i < n; ++i)
    {
        readf("%d ", &a[i]);
    }
    int sum1 = 0, sum2 = 0, x = 0, y = n - 1;
    while(y >= x)
    {
        if(sum1 < sum2)
        {
            sum1 += a[x];
            x++;
        }
        else
        if(sum1 > sum2)
        {
            sum2 += a[y];
            y--;
        }
        else
        {
            sum1 += a[x];
            x++;
            if(y >= x)
            {
                sum2 += a[y];
                y--;
            }
        }
    }
    write(x, " ", n - y - 1);
}


import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main () {
	auto n = readln.strip.to!int;
	string [] [string] d, e;
	foreach (i; 0..n)
	{
		auto t = readln.strip.split ('/');
		d[t[2]] ~= t[3..$].map !(x => "/" ~ x).join;
	}
	foreach (k, v; d)
		e[v.sort ().uniq.join (' ')] ~= k;
	auto r = e.byValue.filter !(x => x.length > 1);
	writefln ("%s\n%(%-(http://%s %)\n%)", r.walkLength, r);
}

import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		string [] [string] d;
		foreach (i; 0..n)
		{
			auto s = readln.strip;
			auto t = s.split ('/');
			d[t[2]] ~= t.drop (3).map !(x => "/" ~ x).join ();
		}

		string [] [string] e;
		foreach (k, v; d)
		{
			e[v.sort ().uniq ().join (' ')] ~= k;
		}
		writeln (e.byKeyValue.count !(x => x.value.length > 1));
		foreach (k, v; e)
		{
			if (v.length > 1)
			{
				v.map !(x => "http://" ~ x).join (' ').writeln;
			}
		}
	}
}


import core.bitop, std.bitmanip;
import std.algorithm, std.functional;
import std.array, std.container;
import std.conv;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

immutable int INF = 10L ^^ 9 + 23;

void main()
{
    int n;
    readf("%s", &n);
    readln;

    auto s = readln.chomp;

    int x, y;
    readf("%s %s", &x, &y);
    readln;

    if (abs(x) + abs(y) > n || (abs(x) + abs(y)) % 2 != n % 2) {
        writeln(-1);
        return;
    }

    auto p = new int[][] (n+1, 2);
    p[] = [0, 0];
    foreach (i, e; s) {
        int xstep = 0, ystep = 0;
        if (e == 'U') { ystep = 1; }
        if (e == 'R') { xstep = 1; }
        if (e == 'D') { ystep = -1; }
        if (e == 'L') { xstep = -1; }

        p[i+1] = [p[i][0] + xstep, p[i][1] + ystep];
    }

    int chk(ref string s, int x, int y) {
        if (abs(x) + abs(y) > s.length) { return -1; }

        bool reachable(int m) {
            int cx = p[m][0], cy = p[m][1];
            int len = s.length.to!int - m;
            return abs(x - cx) + abs(y - cy) <= len;
        }

        int le = 0, r = s.length.to!int;
        while (le < r) {
            int m = (le + r) / 2 + 1;
            if (reachable(m)) { le = m; }
            else { r = m-1; }
        }

        return s.length.to!int - r;
    }

    auto ans = chk(s, x, y);
    while (! s.empty()) {
        auto e = s.back;
        s.popBack();

        if (e == 'U') { y -= 1; }
        if (e == 'R') { x -= 1; }
        if (e == 'D') { y += 1; }
        if (e == 'L') { x += 1; }

        auto cur = chk(s, x, y);

        if (cur == -1) { continue; }
        if (cur < ans) { ans = cur; }
    }

    ans.writeln;
}

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

void main() {
    auto N = readln.chomp.to!int;
    auto S = readln.chomp;
    auto s = readln.split.map!(to!long);
    auto X = s[0];
    auto Y = s[1];

    bool check(int len, long x, long y) {
        return (len >= abs(x) + abs(y)) && (len % 2 == (abs(x) + abs(y)) % 2);
    }

    if (!check(N, X, Y)) {
        writeln(-1);
        return;
    }

    auto A = new long[](N+1);
    auto B = new long[](N+1);

    foreach (i; 0..N) {
        A[i+1] = A[i];
        B[i+1] = B[i];
        if      (S[i] == 'R') A[i+1] += 1;
        else if (S[i] == 'L') A[i+1] -= 1;
        else if (S[i] == 'U') B[i+1] += 1;
        else if (S[i] == 'D') B[i+1] -= 1;
    }

    if (A[N] == X && B[N] == Y) {
        writeln(0);
        return;
    }

    int hi = N;
    int lo = -1;
    while (hi - lo > 1) {
        int mid = (hi + lo) / 2;
        bool ok = false;
        foreach (l; 0..N-mid+1) {
            int r = l + mid - 1;
            long x1 = A[r+1] - A[l];
            long y1 = B[r+1] - B[l];
            long x2 = A[N] - x1;
            long y2 = B[N] - y1;
            long x = X - x2;
            long y = Y - y2;
            if (check(mid, x, y)) {
                ok = true;
                break;
            }
        }
        (ok ? hi : lo) = mid;
    }

    hi.writeln;
}

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

void main() {
    auto N = readln.chomp.to!int;
    auto S = readln.chomp;
    auto s = readln.split.map!(to!long);
    auto X = s[0];
    auto Y = s[1];

    bool check(int len, long x, long y) {
        return (len >= abs(x) + abs(y)) && (len % 2 == (abs(x) + abs(y)) % 2);
    }

    if (check(0, X, Y)) {
        writeln(0);
        return;
    }

    if (!check(N, X, Y)) {
        writeln(-1);
        return;
    }

    auto A = new long[](N+1);
    auto B = new long[](N+1);

    foreach (i; 0..N) {
        A[i+1] = A[i];
        B[i+1] = B[i];
        if      (S[i] == 'R') A[i+1] += 1;
        else if (S[i] == 'L') A[i+1] -= 1;
        else if (S[i] == 'U') B[i+1] += 1;
        else if (S[i] == 'D') B[i+1] -= 1;
    }

    int hi = N;
    int lo = -1;
    while (hi - lo > 1) {
        int mid = (hi + lo) / 2;
        bool ok = false;
        foreach (l; 0..N-mid+1) {
            int r = l + mid - 1;
            long x1 = A[r+1] - A[l];
            long y1 = B[r+1] - B[l];
            long x2 = A[N] - x1;
            long y2 = B[N] - y1;
            long x = X - x2;
            long y = Y - y2;
            if (check(mid, x, y)) {
                ok = true;
                break;
            }
        }
        (ok ? hi : lo) = mid;
    }

    hi.writeln;
}