import std.stdio;
import std.c.stdio;
import std.math;
import std.algorithm;
import std.conv;
import std.string;
import std.array;
import std.typecons;

int n, q;

struct SqrtDecomposition {
  alias Entry = Tuple!(long, "val", int, "idx");
  alias MinMax = Tuple!(int, "min", int, "max");
  struct Bucket {
    long added;
    Entry[] vs;
    void add(int l, int r, long x) {
      long prevAdded = added;
      added = 0;
      foreach(ref e; vs) {
        e.val += prevAdded;
        if (l <= e.idx && e.idx < r) e.val += x;
      }
      vs.sort();
    }

    int min(long x) {
      int lb = -1, ub = cast(int)vs.length;
      while (ub - lb > 1) {
        int mid = (ub + lb) / 2;
        if (vs[mid].val < x) {
          lb = mid;
        } else {
          ub = mid;
        }
      }
      if (ub == vs.length || vs[ub].val != x) {
        return -1;
      } else {
        return vs[ub].idx;
      }
    }

    int max(long x) {
      int lb = -1, ub = cast(int)vs.length;
      while (ub - lb > 1) {
        int mid = (ub + lb) / 2;
        if (vs[mid].val > x) {
          ub = mid;
        } else {
          lb = mid;
        }
      }
      if (lb == -1 || vs[lb].val != x) {
        return -1;
      } else {
        return vs[lb].idx;
      }
    }
  }

  int n, m, bsize;
  Bucket[] bs;
  this(int[] a) {
    n = cast(int)a.length;
    bsize = cast(int)(sqrt(real(n)) + 1);
    m = (n - 1) / bsize + 1;
    bs = new Bucket[m];
    foreach (i; 0..m) {
      int l = i * bsize;
      int r = min(n, (i + 1) * bsize);
      bs[i].added = 0;
      foreach(j; l..r) {
        bs[i].vs ~= Entry(a[j], j);
      }
      bs[i].vs.sort();
    }
  }

  void add(int l, int r, long x) {
    int lb = l / bsize;
    int rb = (r - 1) / bsize;
    if (lb == rb) {
      bs[lb].add(l, r, x);
    } else {
      bs[lb].add(l, r, x);
      foreach(i; lb+1..rb) {
        bs[i].added += x;
      }
      bs[rb].add(l, r, x);
    }
  }

  MinMax query(long x) {
    MinMax ans = MinMax(n, -1);
    foreach(b; bs) {
      int minIdx = b.min(x - b.added);
      int maxIdx = b.max(x - b.added);
      if (minIdx != -1) {
        assert(maxIdx != -1);
        ans.min = min(minIdx, ans.min);
        ans.max = max(maxIdx, ans.max);
      } else {
        assert(maxIdx == -1);
      }
    }
    return ans;
  }
}

void main() {
  scanf("%d%d", &n, &q);
  int[] a = new int[n];
  foreach (i; 0..n) {
    scanf("%d", &a[i]);
  }
  auto sq = SqrtDecomposition(a);
  while (q--) {
    int t;
    scanf("%d", &t);
    if (t == 1) {
      int l, r, x;
      scanf("%d%d%d", &l, &r, &x);
      l--;
      sq.add(l, r, x);
    } else if (t == 2) {
      int y;
      scanf("%d", &y);
      auto ans = sq.query(y);
      if (ans.max == -1) {
        writeln(-1);
      } else {
        writeln(ans.max - ans.min);
      }
    } else {
      assert(false);
    }
  }
}

import std.stdio;
import std.c.stdio;
import std.math;
import std.algorithm;
import std.conv;
import std.string;
import std.array;
import std.typecons;

int n, q;

struct SqrtDecomposition {
  alias Entry = Tuple!(long, "val", int, "idx");
  alias MinMax = Tuple!(int, "min", int, "max");
  struct Bucket {
    long added;
    Entry[] vs;
    void add(int l, int r, long x) {
      long prevAdded = added;
      added = 0;
      Entry[] newvs = new Entry[vs.length];
      foreach(i,e; vs) {
        e.val += prevAdded;
        if (l <= e.idx && e.idx < r) e.val += x;
        newvs[i] = e;
      }
      newvs.sort();
      vs = newvs;
    }

    int min(long x) {
      int lb = -1, ub = cast(int)vs.length;
      while (ub - lb > 1) {
        int mid = (ub + lb) / 2;
        if (vs[mid].val < x) {
          lb = mid;
        } else {
          ub = mid;
        }
      }
      if (ub == vs.length || vs[ub].val != x) {
        return -1;
      } else {
        return vs[ub].idx;
      }
    }

    int max(long x) {
      int lb = -1, ub = cast(int)vs.length;
      while (ub - lb > 1) {
        int mid = (ub + lb) / 2;
        if (vs[mid].val > x) {
          ub = mid;
        } else {
          lb = mid;
        }
      }
      if (lb == -1 || vs[lb].val != x) {
        return -1;
      } else {
        return vs[lb].idx;
      }
    }
  }

  int n, m, bsize;
  Bucket[] bs;
  this(int[] a) {
    n = cast(int)a.length;
    bsize = cast(int)(sqrt(real(n)) + 1);
    m = (n - 1) / bsize + 1;
    bs = new Bucket[m];
    foreach (i; 0..m) {
      int l = i * bsize;
      int r = min(n, (i + 1) * bsize);
      bs[i].added = 0;
      foreach(j; l..r) {
        bs[i].vs ~= Entry(a[j], j);
      }
      bs[i].vs.sort();
    }
  }

  void add(int l, int r, long x) {
    int lb = l / bsize;
    int rb = (r - 1) / bsize;
    if (lb == rb) {
      bs[lb].add(l, r, x);
    } else {
      bs[lb].add(l, r, x);
      foreach(i; lb+1..rb) {
        bs[i].added += x;
      }
      bs[rb].add(l, r, x);
    }
  }

  MinMax query(long x) {
    MinMax ans = MinMax(n, -1);
    foreach(b; bs) {
      int minIdx = b.min(x - b.added);
      int maxIdx = b.max(x - b.added);
      if (minIdx != -1) {
        assert(maxIdx != -1);
        ans.min = min(minIdx, ans.min);
        ans.max = max(maxIdx, ans.max);
      } else {
        assert(maxIdx == -1);
      }
    }
    return ans;
  }
}

void main() {
  scanf("%d%d", &n, &q);
  int[] a = new int[n];
  foreach (i; 0..n) {
    scanf("%d", &a[i]);
  }
  auto sq = SqrtDecomposition(a);
  while (q--) {
    int t;
    scanf("%d", &t);
    if (t == 1) {
      int l, r, x;
      scanf("%d%d%d", &l, &r, &x);
      l--;
      sq.add(l, r, x);
    } else if (t == 2) {
      int y;
      scanf("%d", &y);
      auto ans = sq.query(y);
      if (ans.max == -1) {
        writeln(-1);
      } else {
        writeln(ans.max - ans.min);
      }
    } else {
      assert(false);
    }
  }
}

import std.stdio;
import std.c.stdio;
import std.math;
import std.algorithm;
import std.conv;
import std.string;
import std.array;
import std.typecons;

int n, q;

struct SqrtDecomposition {
  alias Entry = Tuple!(long, "val", int, "idx");
  alias MinMax = Tuple!(int, "min", int, "max");
  struct Bucket {
    long added;
    Entry[] vs;
    void add(int l, int r, long x) {
      long prevAdded = added;
      added = 0;
      Entry[] newvs = new Entry[vs.length];
      foreach(i,e; vs) {
        e.val += prevAdded;
        if (l <= e.idx && e.idx < r) e.val += x;
        newvs[i] = e;
      }
      newvs.sort();
      vs = newvs;
    }

    int min(long x) {
      int lb = -1, ub = cast(int)vs.length;
      while (ub - lb > 1) {
        int mid = (ub + lb) / 2;
        if (vs[mid].val < x) {
          lb = mid;
        } else {
          ub = mid;
        }
      }
      if (ub == vs.length || vs[ub].val != x) {
        return -1;
      } else {
        return vs[ub].idx;
      }
    }

    int max(long x) {
      int lb = -1, ub = cast(int)vs.length;
      while (ub - lb > 1) {
        int mid = (ub + lb) / 2;
        if (vs[mid].val > x) {
          ub = mid;
        } else {
          lb = mid;
        }
      }
      if (lb == -1 || vs[lb].val != x) {
        return -1;
      } else {
        return vs[lb].idx;
      }
    }
  }

  int n, m, bsize;
  Bucket[] bs;
  this(int[] a) {
    n = cast(int)a.length;
    bsize = cast(int)(sqrt(real(n)) + 1);
    m = (n - 1) / bsize + 1;
    bs = new Bucket[m];
    foreach (i; 0..m) {
      int l = i * bsize;
      int r = min(n, (i + 1) * bsize);
      bs[i].added = 0;
      foreach(j; l..r) {
        bs[i].vs ~= Entry(a[j], j);
      }
      bs[i].vs.sort();
    }
  }

  void add(int l, int r, long x) {
    int lb = l / bsize;
    int rb = (r - 1) / bsize;
    if (lb == rb) {
      bs[lb].add(l, r, x);
    } else {
      bs[lb].add(l, r, x);
      foreach(i; lb+1..rb) {
        bs[i].added += 1;
      }
      bs[rb].add(l, r, x);
    }
  }

  MinMax query(long x) {
    MinMax ans = MinMax(n, -1);
    foreach(b; bs) {
      int minIdx = b.min(x - b.added);
      int maxIdx = b.max(x - b.added);
      if (minIdx != -1) {
        assert(maxIdx != -1);
        ans.min = min(minIdx, ans.min);
        ans.max = max(maxIdx, ans.max);
      } else {
        assert(maxIdx == -1);
      }
    }
    return ans;
  }
}

void main() {
  scanf("%d%d", &n, &q);
  int[] a = new int[n];
  foreach (i; 0..n) {
    scanf("%d", &a[i]);
  }
  auto sq = SqrtDecomposition(a);
  while (q--) {
    int t;
    scanf("%d", &t);
    if (t == 1) {
      int l, r, x;
      scanf("%d%d%d", &l, &r, &x);
      l--;
      sq.add(l, r, x);
    } else if (t == 2) {
      int y;
      scanf("%d", &y);
      auto ans = sq.query(y);
      if (ans.max == -1) {
        writeln(-1);
      } else {
        writeln(ans.max - ans.min);
      }
    } else {
      assert(false);
    }
  }
}


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

int[] a, b, c;

void main() {

	int n;

	readf(" %s", &n);

	int k;
	foreach (i; 0 .. n) {
		scanf("%d", &k);
		a ~= k;
	}

	foreach (i; 0 .. n - 1) {
		scanf("%d", &k);
		b ~= k;
	}

	foreach (i; 0 .. n - 2) {
		scanf("%d", &k);
		c ~= k;
	}

	sort(a);
	sort(b);
	sort(c);

	bool flag = 1;
	foreach (i; 0 .. n - 1)
		if (a[i] != b[i]) {
			writeln(a[i]);
			flag = 0;
			break;
		}

	if (flag)
		writeln(a[n - 1]);

	flag = 1;
	foreach (i; 0 .. n - 2)
		if (b[i] != c[i]) {
			writeln(b[i]);
			flag = 0;
			break;
		}

	if (flag)
		writeln(b[n - 2]);
}

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

void main()
{
	readln;
	auto f=()=>readln.split.map!(to!int).reduce!"a^b";
	auto x=f(),y=f(),z=f();
	writeln(x^y,'\n',y^z);
}

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

int a, b, c;

void main() {

	int n;

	readf(" %s", &n);

	int k;
	foreach (i; 0 .. n) {
		readf(" %s", &k);
		a ^= k;
	}

	foreach (i; 0 .. n - 1) {
		readf(" %s", &k);
		b ^= k;
	}

	foreach (i; 0 .. n - 2) {
		readf(" %s", &k);
		c ^= k;
	}

	writeln(a ^ b, '\n', b ^ c);
}

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

long a, b, c;

void main() {

	int n;

	readf(" %s", &n);

	int k;
	foreach (i; 0 .. n) {
		scanf("%d", &k);
		a += k;
	}

	foreach (i; 0 .. n - 1) {
		scanf("%d", &k);
		b += k;
	}

	foreach (i; 0 .. n - 2) {
		scanf("%d", &k);
		c += k;
	}

	writeln(a - b, '\n', b - c);
}

import std.stdio;
import core.stdc.stdio;
import std.algorithm;
import std.math;
import std.array;

int main(string[] argv)
{
	int n;
	scanf("%d", &n);
	int[int] ce1;
	foreach (int i; 0..n)
	{
		int error;
		scanf("%d", &error);
		ce1[error]++;
	}
	int[int] ce2;
	foreach (int i; 0..(n-1))
	{
		int error;
		scanf("%d", &error);
		ce2[error]++;
	}
	foreach (int key; ce1.byKey)
	{
		if (!(key in ce2) || ce1[key] != ce2[key])
		{
			printf("%d\n", key);
			break;
		}
	}
	int[int] ce3;
	foreach (int i; 0..(n-2))
	{
		int error;
		scanf("%d", &error);
		ce3[error]++;
	}

	foreach (int key; ce2.byKey)
	{
		if (!(key in ce3) || ce2[key] != ce3[key])
		{
			printf("%d", key);
			break;
		}
	}
	return 0;
}

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

int a, b, c;

void main() {

	int n;

	readf(" %s", &n);

	int k;
	foreach (i; 0 .. n) {
		readf(" %s", &k);
		a ^= k;
	}

	foreach (i; 0 .. n) {
		readf(" %s", &k);
		b ^= k;
	}

	foreach (i; 0 .. n) {
		readf(" %s", &k);
		c ^= k;
	}

	writeln(a ^ b, '\n', b ^ c);
}

import std.stdio;
import core.stdc.stdio;
import std.algorithm;
import std.math;
import std.array;

int main(string[] argv)
{
	int n;
	scanf("%d", &n);
	int[int] ce;
	foreach (int i; 0..(3*n - 3))
	{
		int error;
		scanf("%d", &error);
		ce[error]++;
	}
	int ak;
	int bk;
	foreach (int key; ce.byKey)
	{
		if (ce[key] < 3)
		{
			ak = (ak == 0 && ce[key] == 1) ? key : ak;
			bk = (bk == 0 && ce[key] == 2) ? key : bk;
		}
	}
	printf("%d\n%d", ak, bk);
	return 0;
}

import std.stdio;
import core.stdc.stdio;
import std.algorithm;
import std.math;
import std.array;

int main(string[] argv)
{
	int n;
	scanf("%d", &n);
	int[int] ce;
	foreach (int i; 0..(3*n - 3))
	{
		int error;
		scanf("%d", &error);
		ce[error]++;
	}
	int ak;
	int bk;
	foreach (int key; ce.byKey)
	{
		if (ce[key] % 3 != 0)
		{
			ak = (ak == 0 && ce[key] % 3 == 1) ? key : ak;
			bk = (bk == 0 && ce[key] % 3 == 2) ? key : bk;
		}
	}
	printf("%d\n%d", ak, bk);
	return 0;
}


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 = single;
struct TestCase
{
  mixin prettyPrinting;

  long n, m, k;
  @Dim("n") string[] maze;

  void solve(long tc = -1)
  {
    char[][] mmaze = maze.map!(row => row.dup).array;
    enum long[2][] deltas = [[+1, 0],
                             [-1, 0],
                             [0, +1],
                             [0, -1]];
    const initialPosition = delegate long[2]() {
      foreach(i; 0 .. n)
        foreach(j; 0 .. m)
          if (maze.at(i).at(j) == '.')
            return [i, j];
      assert(0);
    } ();
    auto dist = makeSlice!long(n, m);
    auto visited = makeSlice!bool(n, m);
    long[2][][long] withdist;
    auto maxdist = long(0);
    DList!(long[2]) queue;
    queue.insertFront(initialPosition);
    dist.at(initialPosition[0]).at(initialPosition[1]) = 0;
    visited.at(initialPosition[0]).at(initialPosition[1]) = true;
    withdist.require(0, null);
    withdist.at(0) = [initialPosition];
    while(!queue.empty)
      {
        auto node = queue.front;
        queue.removeFront;
        foreach(delta; deltas)
          {
            long[2] neighbour;
            neighbour[] = node[] + delta[];
            if (neighbour[0] >= 0 && neighbour[0] < n
                && neighbour[1] >= 0 && neighbour[1] < m
                && maze.at(neighbour[0]).at(neighbour[1]) == '.'
                && !visited.at(neighbour[0]).at(neighbour[1]))
              {
                dist.at(neighbour[0]).at(neighbour[1]) = dist.at(node[0]).at(node[1]) + 1;
                require(withdist, dist.at(neighbour[0]).at(neighbour[1]), null);
                withdist.at(dist.at(neighbour[0]).at(neighbour[1])) ~= neighbour;
                visited.at(neighbour[0]).at(neighbour[1]) = true;
                maxdist = max(maxdist, dist.at(neighbour[0]).at(neighbour[1]));
                queue.insertBack(neighbour);
              }
          }
      }
    auto inserted = long(0);
    auto disttoinsert = maxdist;
    while(inserted < k)
      {
        if (withdist.at(disttoinsert).empty)
          {
            disttoinsert--;
          }
        auto toinsert = withdist.at(disttoinsert)[$ - 1];
        mmaze.at(toinsert[0]).at(toinsert[1]) = 'X';
        withdist.at(disttoinsert).length--;
        inserted++;
      }
    foreach(row; mmaze)
      {
        writeln(row);
      }
  }
}

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 std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.exception;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
import core.bitop;

immutable int INF = int.max / 4;
immutable int DIRS = 4;
immutable int [DIRS] DR = [-1,  0, +1,  0];
immutable int [DIRS] DC = [ 0, -1,  0, +1];

void main ()
{
	int n, m, k;
	while (readf (" %s %s %s ", &n, &m, &k) > 0)
	{
		char [] [] a;
		char [] t1;
		foreach (j; 0..m + 2)
		{
			t1 ~= '#';
		}
		a ~= t1;
		foreach (i; 0..n)
		{
			char [] t2 = cast (char []) readln.strip;
			a ~= ('#' ~ t2 ~ '#');
		}
		a ~= t1;

		alias Tuple !(int, "r", int, "c") coord;
		auto s = coord (-1, -1);
iloop:		foreach (i; 0..n + 2)
		{
			foreach (j; 0..m + 2)
			{
				if (a[i][j] == '.')
				{
					s = coord (i, j);
					break iloop;
				}
			}
		}
		enforce (s != coord (-1, -1));

		auto d = new int [] [] (n + 2, m + 2);
		foreach (ref e; d)
		{
			e[] = INF;
		}
		d[s.r][s.c] = 0;
		coord [] q;
		q.reserve ((n + 2) * (m + 2));
		coord [] r = q;
		q.assumeSafeAppend;
		q ~= s;
		int p = 0;
		while (p < q.length)
		{
			auto cur = q[p];
			p++;
			foreach (dir; 0..DIRS)
			{
				auto next = coord (cur.r + DR[dir],
				                   cur.c + DC[dir]);
				if (a[next.r][next.c] != '.')
				{
					continue;
				}
				if (d[next.r][next.c] == INF)
				{
					d[next.r][next.c] =
					    d[cur.r][cur.c] + 1;
					q.assumeSafeAppend;
					q ~= next;
				}
			}
		}

		q = q[$ - k..$];
		foreach (cur; q)
		{
			a[cur.r][cur.c] = 'X';
		}

		foreach (b; a[1..n + 1])
		{
			writeln (b[1..m + 1]);
		}
	}
}


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

void main ()
{
	int n, d;
	while (readf !(" %s %s") (n, d) > 0)
	{
		auto p = n.iota.array;
		auto s = 1.repeat (n).array;

		int root (int v)
		{
			if (p[v] != v)
			{
				p[v] = root (p[v]);
			}
			return p[v];
		}

		bool unite (int u, int v)
		{
			u = root (u);
			v = root (v);
			if (u == v)
			{
				return false;
			}
			if (s[u] > s[v])
			{
				swap (u, v);
			}
			p[u] = v;
			s[v] += s[u];
			return true;
		}

		int add = 0;
		foreach (j; 0..d)
		{
			int u, v;
			readf !(" %s %s") (u, v);
			u -= 1;
			v -= 1;
			auto cur = unite (u, v);
			add += !cur;

			auto t = n.iota.filter !(v => p[v] == v)
			    .map !(v => s[v]).array;
			sort (t);
			foreach (k; 0..add)
			{
				t[$ - 2] += t.back;
				t.popBack ();
			}
			writeln (t.back - 1);
		}
	}
}

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

void main()
{
  int n, d, saved = 0;
  readf(" %d %d ", &n, &d);

  auto uf = Dsu(n);

  while (d--) {
    int u, v;
    readf(" %d %d ", &u, &v);
    u--;
    v--;
    if (!uf.same(u, v)) {
      uf.merge(u, v);
    } else {
      saved++;
    }
    writeln(uf.groups.map!(x => x.length).array.sort!"a>b".take(saved + 1).sum - 1);
  }
}

// Code from: https://github.com/kotet/atcoder-library-d

struct Dsu
{
public:
    this(long n) @safe nothrow
    {
        _n = cast(int) n, parent_or_size = new int[](cast(int)n);
        parent_or_size[] = -1;
    }

    int merge(long a, long b) @safe nothrow @nogc
    {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        int x = leader(a), y = leader(b);
        if (x == y)
            return x;
        if (-parent_or_size[x] < -parent_or_size[y])
        {
            auto tmp = x;
            x = y;
            y = tmp;
        }
        parent_or_size[x] += parent_or_size[y];
        parent_or_size[y] = x;
        return x;
    }

    bool same(long a, long b) @safe nothrow @nogc
    {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        return leader(a) == leader(b);
    }

    int leader(long a) @safe nothrow @nogc
    {
        assert(0 <= a && a < _n);
        if (parent_or_size[cast(int)a] < 0)
            return cast(int) a;
        return parent_or_size[cast(int)a] = leader(parent_or_size[cast(int)a]);
    }

    int size(long a) @safe nothrow @nogc
    {
        assert(0 <= a && a < _n);
        return -parent_or_size[leader(a)];
    }

    int[][] groups() @safe nothrow
    {
        auto leader_buf = new int[](_n), group_size = new int[](_n);
        foreach (i; 0 .. _n)
        {
            leader_buf[i] = leader(i);
            group_size[leader_buf[i]]++;
        }
        auto result = new int[][](_n);
        foreach (i; 0 .. _n)
            result[i].reserve(group_size[i]);
        foreach (i; 0 .. _n)
            result[leader_buf[i]] ~= i;
        int[][] filtered;
        foreach (r; result)
            if (r.length != 0)
                filtered ~= r;
        return filtered;
    }

private:
    int _n;
    int[] parent_or_size;
}

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

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

    auto largest = redBlackTree!("a > b", true, int)();
    auto remaining = redBlackTree!("a > b", true, int)();

    Dsu uf;
    uf = Dsu(n);

    long ans;
    long saved;
    while (d--) {
      int u, v;
      readf(" %d %d ", &u, &v);
      u--;
      v--;
      if (!uf.same(u, v)) {
        if (largest.removeKey(uf.size(u)) == 0)
          remaining.removeKey(uf.size(u));
        else
          ans -= uf.size(u);
        if (largest.removeKey(uf.size(v)) == 0)
          remaining.removeKey(uf.size(v));
        else
          ans -= uf.size(v);
        uf.merge(u, v);
        remaining.insert(uf.size(v));
      } else {
        saved++;
      }
      while (largest.length > 0 && remaining.length > 0 && largest.back < remaining.front) {
        auto tmp = largest.back;
        largest.removeBack;
        ans -= tmp;
        remaining.insert(tmp);
      }
      while (largest.length < saved + 1 && remaining.length > 0) {
        auto tmp = remaining.front;
        remaining.removeFront;
        largest.insert(tmp);
        ans += tmp;
      }
      writeln(ans - 1 + saved - (largest.length - 1));
    }
}

// Code from: https://github.com/kotet/atcoder-library-d

struct Dsu
{
public:
    this(long n) @safe nothrow
    {
        _n = cast(int) n, parent_or_size = new int[](cast(int)n);
        parent_or_size[] = -1;
    }

    int merge(long a, long b) @safe nothrow @nogc
    {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        int x = leader(a), y = leader(b);
        if (x == y)
            return x;
        if (-parent_or_size[x] < -parent_or_size[y])
        {
            auto tmp = x;
            x = y;
            y = tmp;
        }
        parent_or_size[x] += parent_or_size[y];
        parent_or_size[y] = x;
        return x;
    }

    bool same(long a, long b) @safe nothrow @nogc
    {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        return leader(a) == leader(b);
    }

    int leader(long a) @safe nothrow @nogc
    {
        assert(0 <= a && a < _n);
        if (parent_or_size[cast(int)a] < 0)
            return cast(int) a;
        return parent_or_size[cast(int)a] = leader(parent_or_size[cast(int)a]);
    }

    int size(long a) @safe nothrow @nogc
    {
        assert(0 <= a && a < _n);
        return -parent_or_size[leader(a)];
    }

    int[][] groups() @safe nothrow
    {
        auto leader_buf = new int[](_n), group_size = new int[](_n);
        foreach (i; 0 .. _n)
        {
            leader_buf[i] = leader(i);
            group_size[leader_buf[i]]++;
        }
        auto result = new int[][](_n);
        foreach (i; 0 .. _n)
            result[i].reserve(group_size[i]);
        foreach (i; 0 .. _n)
            result[leader_buf[i]] ~= i;
        int[][] filtered;
        foreach (r; result)
            if (r.length != 0)
                filtered ~= r;
        return filtered;
    }

private:
    int _n;
    int[] parent_or_size;
}

immutable multi = false;

void solve(int tc)
{
  auto n = readInt!int;
  auto d = readInt!int;
  auto parent = iota(n).array;
  auto size = ma(n, 1);
  int getParent(int i)
  {
    if (parent[i] == i) return i;
    return parent[i] = getParent(parent[i]);
  }
  bool unite(int i, int j)
  {
    i = getParent(i);
    j = getParent(j);
    if (i == j) return false;
    if (size[i] > size[j]) swap(i, j);
    parent[i] = j;
    size[j] += size[i];
    return true;
  }
  int redundant = 0;
  foreach(i; 0 .. d)
    {
      redundant += int(!unite(readInt!int - 1, readInt!int - 1));
      (iota(n).filter!(j => parent[j] == j)
       .map!(j => size[j])
       .array
       .sort!((a, b) => a > b)
       .take(redundant + 1)
       .sum - 1).writeln;
    }
}

// main {{{
void main()
{
	auto t = multi? readInt!int : 1;
	foreach(tc; 0 .. t) solve(tc);
}
// }}}
// input {{{
int currChar;
static this()
{
	currChar = ' ';
}

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

void popChar()
{
	import core.stdc.stdio;
	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;
}
void writes(T...)(T t)
{
	static foreach(i, ti; t)
	{
		static if (isIterable!(T[i]))
		{
			foreach(e; ti)
			{
				write(e, " ");
			}
		}
	}
}
auto ra(V)()
{
	int n = readInt!int;
	return ma(n, readInt!V);
}
auto rt(V)()
{
	int n = readInt!int;
	int m = readInt!int;
	return ma(n, ma(m, readInt!V));
}
auto rbg()
{
	int n = readInt!int;
	int m = readInt!int;
	auto adj = new int[][](n);
	foreach(i; 0 .. m)
	{
		auto u = readInt!int - 1;
		auto v = readInt!int - 1;
		adj[u] ~= v;
		adj[v] ~= u;
	}
	return adj;
}
auto ma(V)(size_t n, lazy V v)
{
	auto arr = new V[](n);
	foreach(ref ai; arr) ai = v;
	return arr;
}
// }}}
// imports {{{
import std.stdio;
import std.algorithm;
import std.typecons;
import std.math;
import std.numeric;
import std.container;
import std.range;
import std.array;
import std.ascii;
// }}}

immutable multi = false;

void solve(int tc)
{
  auto n = readInt!int;
  auto d = readInt!int;
  auto parent = iota(n).array;
  auto size = ma(n, 1);
  foreach(i; 0 .. n) { parent[i] = i; size[i] = 1; }
  int getParent(int i)
  {
    if (parent[i] == i) return i;
    return parent[i] = getParent(parent[i]);
  }
  bool unite(int i, int j)
  {
    i = getParent(i);
    j = getParent(j);
    if (i == j) return false;
    if (size[i] > size[j]) swap(i, j);
    parent[i] = j;
    size[j] += size[i];
    return true;
  }
  int redundant = 0;
  foreach(i; 0 .. d)
    {
      redundant += int(!unite(readInt!int - 1, readInt!int - 1));
      (iota(n).filter!(j => parent[j] == j)
       .map!(j => size[j])
       .array
       .sort!((a, b) => a > b)
       .take(redundant + 1)
       .sum - 1).writeln;
    }
}

// main {{{
void main()
{
	auto t = multi? readInt!int : 1;
	foreach(tc; 0 .. t) solve(tc);
}
// }}}
// input {{{
int currChar;
static this()
{
	currChar = ' ';
}

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

void popChar()
{
	import core.stdc.stdio;
	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;
}
void writes(T...)(T t)
{
	static foreach(i, ti; t)
	{
		static if (isIterable!(T[i]))
		{
			foreach(e; ti)
			{
				write(e, " ");
			}
		}
	}
}
auto ra(V)()
{
	int n = readInt!int;
	return ma(n, readInt!V);
}
auto rt(V)()
{
	int n = readInt!int;
	int m = readInt!int;
	return ma(n, ma(m, readInt!V));
}
auto rbg()
{
	int n = readInt!int;
	int m = readInt!int;
	auto adj = new int[][](n);
	foreach(i; 0 .. m)
	{
		auto u = readInt!int - 1;
		auto v = readInt!int - 1;
		adj[u] ~= v;
		adj[v] ~= u;
	}
	return adj;
}
auto ma(V)(size_t n, lazy V v)
{
	auto arr = new V[](n);
	foreach(ref ai; arr) ai = v;
	return arr;
}
// }}}
// imports {{{
import std.stdio;
import std.algorithm;
import std.typecons;
import std.math;
import std.numeric;
import std.container;
import std.range;
import std.array;
import std.ascii;
// }}}

immutable multi = false;

void solve(int tc)
{
  auto n = readInt!int;
  auto d = readInt!int;
  auto parent = new int[](n);
  auto size = new int[](n);
  foreach(i; 0 .. n) { parent[i] = i; size[i] = 1; }
  int getParent(int i)
  {
    if (parent[i] == i) return i;
    return parent[i] = getParent(parent[i]);
  }
  bool unite(int i, int j)
  {
    i = getParent(i);
    j = getParent(j);
    if (i == j) return false;
    if (size[i] > size[j]) swap(i, j);
    parent[i] = j;
    size[j] += size[i];
    return true;
  }
  int redundant = 0;
  foreach(i; 0 .. d)
    {
      redundant += int(!unite(readInt!int - 1, readInt!int - 1));
      (iota(n).filter!(j => parent[j] == j)
       .map!(j => size[j])
       .array
       .sort!((a, b) => a > b)
       .take(redundant + 1)
       .sum - 1).writeln;
    }
}

// main {{{
void main()
{
	auto t = multi? readInt!int : 1;
	foreach(tc; 0 .. t) solve(tc);
}
// }}}
// input {{{
int currChar;
static this()
{
	currChar = ' ';
}

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

void popChar()
{
	import core.stdc.stdio;
	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;
}
void writes(T...)(T t)
{
	static foreach(i, ti; t)
	{
		static if (isIterable!(T[i]))
		{
			foreach(e; ti)
			{
				write(e, " ");
			}
		}
	}
}
auto ra(V)()
{
	int n = readInt!int;
	return ma(n, readInt!V);
}
auto rt(V)()
{
	int n = readInt!int;
	int m = readInt!int;
	return ma(n, ma(m, readInt!V));
}
auto rbg()
{
	int n = readInt!int;
	int m = readInt!int;
	auto adj = new int[][](n);
	foreach(i; 0 .. m)
	{
		auto u = readInt!int - 1;
		auto v = readInt!int - 1;
		adj[u] ~= v;
		adj[v] ~= u;
	}
	return adj;
}
auto ma(V)(size_t n, lazy V v)
{
	auto arr = new V[](n);
	foreach(ref ai; arr) ai = v;
	return arr;
}
// }}}
// imports {{{
import std.stdio;
import std.algorithm;
import std.typecons;
import std.math;
import std.numeric;
import std.container;
import std.range;
import std.array;
import std.ascii;
// }}}

immutable multi = false;

void solve(int tc)
{
  auto n = readInt!int;
  auto d = readInt!int;
  auto parent = new int[](n);
  auto size = new int[](n);
  foreach(i; 0 .. n) { parent[i] = i; size[i] = 1; }
  int getParent(int i)
  {
    if (parent[i] == i) return i;
    return parent[i] = getParent(parent[i]);
  }
  bool unite(int i, int j)
  {
    i = getParent(i);
    j = getParent(j);
    if (i == j) return false;
    if (size[i] > size[j]) swap(i, j);
    parent[i] = j;
    size[j] += size[i];
    return true;
  }
  int redundant = 0;
  foreach(i; 0 .. d)
    {
      auto x = readInt!int - 1;
      auto y = readInt!int - 1;
      auto newE = unite(x, y);
      redundant += int(!newE);
      int[] sizes;
      foreach(j; 0 .. n)
	{
	  if (parent[j] == j)
	    sizes ~= size[j];
	}
      sort(sizes);
      int ans = 0;
      foreach(k; 0 .. redundant + 1)
	{
	  ans += sizes[$ - 1 - k];
	}
      (ans-1).writeln;
    }
}

// main {{{
void main()
{
	auto t = multi? readInt!int : 1;
	foreach(tc; 0 .. t) solve(tc);
}
// }}}
// input {{{
int currChar;
static this()
{
	currChar = ' ';
}

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

void popChar()
{
	import core.stdc.stdio;
	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;
}
void writes(T...)(T t)
{
	static foreach(i, ti; t)
	{
		static if (isIterable!(T[i]))
		{
			foreach(e; ti)
			{
				write(e, " ");
			}
		}
	}
}
auto ra(V)()
{
	int n = readInt!int;
	return ma(n, readInt!V);
}
auto rt(V)()
{
	int n = readInt!int;
	int m = readInt!int;
	return ma(n, ma(m, readInt!V));
}
auto rbg()
{
	int n = readInt!int;
	int m = readInt!int;
	auto adj = new int[][](n);
	foreach(i; 0 .. m)
	{
		auto u = readInt!int - 1;
		auto v = readInt!int - 1;
		adj[u] ~= v;
		adj[v] ~= u;
	}
	return adj;
}
auto ma(V)(size_t n, lazy V v)
{
	auto arr = new V[](n);
	foreach(ref ai; arr) ai = v;
	return arr;
}
// }}}
// imports {{{
import std.stdio;
import std.algorithm;
import std.typecons;
import std.math;
import std.numeric;
import std.container;
import std.range;
import std.array;
import std.ascii;
// }}}

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

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

    auto largest = redBlackTree!("a > b", true, int)();
    auto remaining = redBlackTree!("a > b", true, int)();

    Dsu uf;
    uf = Dsu(n);

    long ans;
    long saved;
    long req = 0;
    while (d--) {
      req++;
      int u, v;
      readf(" %d %d ", &u, &v);
      u--;
      v--;
      if (!uf.same(u, v)) {
        if (largest.removeKey(uf.size(u)) == 0)
          remaining.removeKey(uf.size(u));
        else
          ans -= uf.size(u);
        if (largest.removeKey(uf.size(v)) == 0)
          remaining.removeKey(uf.size(v));
        else
          ans -= uf.size(v);
        uf.merge(u, v);
        remaining.insert(uf.size(v));
      } else {
        saved++;
      }
      while (largest.length < saved + 1 && remaining.length > 0) {
        auto tmp = remaining.front;
        remaining.removeFront;
        largest.insert(tmp);
        ans += tmp;
      }
      writeln(min(req, ans + (saved + 1 - largest.length) - 1));
    }
}

// Code from: https://github.com/kotet/atcoder-library-d

struct Dsu
{
public:
    this(long n) @safe nothrow
    {
        _n = cast(int) n, parent_or_size = new int[](cast(int)n);
        parent_or_size[] = -1;
    }

    int merge(long a, long b) @safe nothrow @nogc
    {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        int x = leader(a), y = leader(b);
        if (x == y)
            return x;
        if (-parent_or_size[x] < -parent_or_size[y])
        {
            auto tmp = x;
            x = y;
            y = tmp;
        }
        parent_or_size[x] += parent_or_size[y];
        parent_or_size[y] = x;
        return x;
    }

    bool same(long a, long b) @safe nothrow @nogc
    {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        return leader(a) == leader(b);
    }

    int leader(long a) @safe nothrow @nogc
    {
        assert(0 <= a && a < _n);
        if (parent_or_size[cast(int)a] < 0)
            return cast(int) a;
        return parent_or_size[cast(int)a] = leader(parent_or_size[cast(int)a]);
    }

    int size(long a) @safe nothrow @nogc
    {
        assert(0 <= a && a < _n);
        return -parent_or_size[leader(a)];
    }

    int[][] groups() @safe nothrow
    {
        auto leader_buf = new int[](_n), group_size = new int[](_n);
        foreach (i; 0 .. _n)
        {
            leader_buf[i] = leader(i);
            group_size[leader_buf[i]]++;
        }
        auto result = new int[][](_n);
        foreach (i; 0 .. _n)
            result[i].reserve(group_size[i]);
        foreach (i; 0 .. _n)
            result[leader_buf[i]] ~= i;
        int[][] filtered;
        foreach (r; result)
            if (r.length != 0)
                filtered ~= r;
        return filtered;
    }

private:
    int _n;
    int[] parent_or_size;
}

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

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

    auto largest = redBlackTree!("a > b", true, int)();
    auto remaining = redBlackTree!("a > b", true, int)();

    Dsu uf;
    uf = Dsu(n);

    long ans;
    long saved;
    while (d--) {
      int u, v;
      readf(" %d %d ", &u, &v);
      u--;
      v--;
      if (!uf.same(u, v)) {
        if (largest.removeKey(uf.size(u)) == 0)
          remaining.removeKey(uf.size(u));
        else
          ans -= uf.size(u);
        if (largest.removeKey(uf.size(v)) == 0)
          remaining.removeKey(uf.size(v));
        else
          ans -= uf.size(v);
        uf.merge(u, v);
        remaining.insert(uf.size(v));
      } else {
        saved++;
      }
      while (largest.length < saved + 1 && remaining.length > 0) {
        auto tmp = remaining.front;
        remaining.removeFront;
        largest.insert(tmp);
        ans += tmp;
      }
      writeln(min(n - 1, ans + (saved + 1 - largest.length) - 1));
    }
}

// Code from: https://github.com/kotet/atcoder-library-d

struct Dsu
{
public:
    this(long n) @safe nothrow
    {
        _n = cast(int) n, parent_or_size = new int[](cast(int)n);
        parent_or_size[] = -1;
    }

    int merge(long a, long b) @safe nothrow @nogc
    {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        int x = leader(a), y = leader(b);
        if (x == y)
            return x;
        if (-parent_or_size[x] < -parent_or_size[y])
        {
            auto tmp = x;
            x = y;
            y = tmp;
        }
        parent_or_size[x] += parent_or_size[y];
        parent_or_size[y] = x;
        return x;
    }

    bool same(long a, long b) @safe nothrow @nogc
    {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        return leader(a) == leader(b);
    }

    int leader(long a) @safe nothrow @nogc
    {
        assert(0 <= a && a < _n);
        if (parent_or_size[cast(int)a] < 0)
            return cast(int) a;
        return parent_or_size[cast(int)a] = leader(parent_or_size[cast(int)a]);
    }

    int size(long a) @safe nothrow @nogc
    {
        assert(0 <= a && a < _n);
        return -parent_or_size[leader(a)];
    }

    int[][] groups() @safe nothrow
    {
        auto leader_buf = new int[](_n), group_size = new int[](_n);
        foreach (i; 0 .. _n)
        {
            leader_buf[i] = leader(i);
            group_size[leader_buf[i]]++;
        }
        auto result = new int[][](_n);
        foreach (i; 0 .. _n)
            result[i].reserve(group_size[i]);
        foreach (i; 0 .. _n)
            result[leader_buf[i]] ~= i;
        int[][] filtered;
        foreach (r; result)
            if (r.length != 0)
                filtered ~= r;
        return filtered;
    }

private:
    int _n;
    int[] parent_or_size;
}

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

struct edge { int u, v; };

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

    auto largest = redBlackTree!("a > b", true, int)();
    auto remaining = redBlackTree!("a > b", true, int)();

    int[][] adj = new int[][](n, 0);
    Dsu uf;
    uf = Dsu(n);

    long ans;
    long saved;
    while (d--) {
      int u, v;
      readf(" %d %d ", &u, &v);
      u--;
      v--;
      if (!uf.same(u, v)) {
        if (largest.removeKey(uf.size(u)) == 0)
          remaining.removeKey(uf.size(u));
        else
          ans -= uf.size(u);
        if (largest.removeKey(uf.size(v)) == 0)
          remaining.removeKey(uf.size(v));
        else
          ans -= uf.size(v);
        uf.merge(u, v);
        adj[u] ~= v;
        adj[v] ~= u;
        remaining.insert(uf.size(v));
      } else {
        saved++;
      }
      while (largest.length < saved + 1 && remaining.length > 0) {
        auto tmp = remaining.front;
        remaining.removeFront;
        largest.insert(tmp);
        ans += tmp;
      }
      writeln(ans - 1 + saved - (largest.length - 1));
    }
}

// Code from: https://github.com/kotet/atcoder-library-d

struct Dsu
{
public:
    this(long n) @safe nothrow
    {
        _n = cast(int) n, parent_or_size = new int[](cast(int)n);
        parent_or_size[] = -1;
    }

    int merge(long a, long b) @safe nothrow @nogc
    {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        int x = leader(a), y = leader(b);
        if (x == y)
            return x;
        if (-parent_or_size[x] < -parent_or_size[y])
        {
            auto tmp = x;
            x = y;
            y = tmp;
        }
        parent_or_size[x] += parent_or_size[y];
        parent_or_size[y] = x;
        return x;
    }

    bool same(long a, long b) @safe nothrow @nogc
    {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        return leader(a) == leader(b);
    }

    int leader(long a) @safe nothrow @nogc
    {
        assert(0 <= a && a < _n);
        if (parent_or_size[cast(int)a] < 0)
            return cast(int) a;
        return parent_or_size[cast(int)a] = leader(parent_or_size[cast(int)a]);
    }

    int size(long a) @safe nothrow @nogc
    {
        assert(0 <= a && a < _n);
        return -parent_or_size[leader(a)];
    }

    int[][] groups() @safe nothrow
    {
        auto leader_buf = new int[](_n), group_size = new int[](_n);
        foreach (i; 0 .. _n)
        {
            leader_buf[i] = leader(i);
            group_size[leader_buf[i]]++;
        }
        auto result = new int[][](_n);
        foreach (i; 0 .. _n)
            result[i].reserve(group_size[i]);
        foreach (i; 0 .. _n)
            result[leader_buf[i]] ~= i;
        int[][] filtered;
        foreach (r; result)
            if (r.length != 0)
                filtered ~= r;
        return filtered;
    }

private:
    int _n;
    int[] parent_or_size;
}


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

long solve (int [] a, int n)
{
	if (a[1..$ - 1].all !(q{a == 0}))
	{
		return 0;
	}
	if (a[1..$ - 1].all !(q{a <= 1}))
	{
		return -1;
	}
	if (n == 3 && a[1] % 2 == 1)
	{
		return -1;
	}
	long res = 0;
	foreach (i; 1..n - 1)
	{
		res += a[i] / 2 + (a[i] & 1);
	}
	return res;
}

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

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)); }
double euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }
double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }
double norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }
double dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }

//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 n = RD!int;
		auto a = RDA;

		bool ok;
		foreach (i; 1..n-1)
		{
			if (a[i] >= 2)
				ok = true;
		}
		if (n == 3 && a[1] % 2)
			ok = false;
		if (!ok)
			ans[ti] = -1;
		else
		{
			foreach (i; 1..n-1)
				ans[ti] += (a[i]+1) / 2;
		}
	}

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

// cheese-cracker [2022-02-12]

void solve(){
    int n = scan!int;
    auto arr = scanArray;
    long summ = 0;
    bool f = 0;
    for(int i = 1; i < n-1; ++i){
        if(arr[i] >= 2){
            f = 1;
        }
        summ += arr[i]/2 + (arr[i] % 2 != 0);
    }
    if(f && !(n == 3 && arr[1] % 2 != 0) ){
        writeln(summ);
    }else{
        writeln(-1);
    }
}

void main(){
    long tests = scan;        // Toggle!
    while(tests--) solve;
}

/*_________________________*That's All Folks!*__________________________*/
import std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;
string[] tk; alias tup = Tuple!(long, long);
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; } }

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)); }

void main() {
  try {
    for (; ; ) {
      const numCases = readInt;
      foreach (caseId; 0 .. numCases) {
        const N = readInt;
        auto A = new long[N];
        foreach (i; 0 .. N) {
          A[i] = readLong;
        }

        bool good;
        if (N == 3) {
          good = (A[1] % 2 == 0);
        } else {
          foreach (i; 1 .. N - 1) {
            good = good || (A[i] >= 2);
          }
        }

        long ans;
        if (good) {
          foreach (i; 1 .. N - 1) {
            ans += (A[i] + 1) / 2;
          }
        } else {
          ans = -1;
        }
        writeln(ans);
      }
    }
  } catch (EOFException e) {
  }
}

// cheese-cracker [2022-02-12]

void solve(){
    int n = scan!int;
    auto arr = scanArray;
    long summ = 0;
    bool f = 0;
    for(int i = 1; i < n-1; ++i){
        if(arr[i] >= 2){
            f = 1;
        }
        summ += arr[i];
    }
    if(f && !(n == 3 && arr[1] % 2 != 0) ){
        writeln(summ/2 + (summ % 2 != 0));
    }else{
        writeln(-1);
    }
}

void main(){
    long tests = scan;        // Toggle!
    while(tests--) solve;
}

/*_________________________*That's All Folks!*__________________________*/
import std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;
string[] tk; alias tup = Tuple!(long, long);
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; } }

// cheese-cracker [2022-02-12]

void solve(){
    int n = scan!int;
    auto arr = scanArray;
    long summ = 0;
    bool f = 0;
    for(int i = 1; i < n-1; ++i){
        if(arr[i] % 2 == 0){
            f = 1;
        }
        summ += arr[i];
    }
    if(f){
        writeln(summ/2 + (summ % 2 != 0));
    }else{
        writeln(-1);
    }
}

void main(){
    long tests = scan;        // Toggle!
    while(tests--) solve;
}

/*_________________________*That's All Folks!*__________________________*/
import std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;
string[] tk; alias tup = Tuple!(long, long);
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; } }

// cheese-cracker [2022-02-12]

void solve(){
    int n = scan!int;
    auto arr = scanArray;
    long[] opp, ops;
    long oper = 0;
    opp ~= 0;
    for(int i = 1; i < n-1; ++i){
        opp ~= oper;
        oper += arr[i] / 2;
    }
    ops ~= 0;
    oper = 0;
    for(int i = n-2; i > 0; --i){
        ops ~= oper;
        oper += arr[i] / 2;
    }
    ops ~= 0;
    ops.reverse;
    show(ops, opp);
    long ocnt = 0;
    for(int i = 1; i < n-1; ++i){
        ocnt = (arr[i] % 2 != 0);
        if(opp[i] + ops[i] >= ocnt){
            oper += ocnt;
        }else{
            writeln(-1);
            return;
        }
    }
    writeln(oper);
}

void main(){
    long tests = scan;        // Toggle!
    while(tests--) solve;
}

/*_________________________*That's All Folks!*__________________________*/
import std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;
string[] tk; alias tup = Tuple!(long, long);
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; } }

// cheese-cracker [2022-02-12]

void solve(){
    int n = scan!int;
    auto arr = scanArray;
    long[] opp, ops;
    long oper = 0;
    opp ~= 0;
    for(int i = 1; i < n-1; ++i){
        opp ~= oper;
        oper += arr[i] / 2;
    }
    ops ~= 0;
    oper = 0;
    for(int i = n-2; i > 0; --i){
        ops ~= oper;
        oper += arr[i] / 2;
    }
    long ocnt = 0;
    for(int i = 1; i < n-1; ++i){
        ocnt = (arr[i] % 2 != 0);
        if(opp[i] + ops[i] >= ocnt){
            oper += ocnt;
        }else{
            writeln(-1);
            return;
        }
    }
    writeln(oper);
}

void main(){
    long tests = scan;        // Toggle!
    while(tests--) solve;
}

/*_________________________*That's All Folks!*__________________________*/
import std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;
string[] tk; alias tup = Tuple!(long, long);
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; } }

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)); }
double euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }
double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }
double norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }
double dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }

//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 n = RD!int;
		auto a = RDA;

		bool ok;
		foreach (i; 1..n-1)
		{
			if (a[i] % 2 == 0)
				ok = true;
		}
		if (!ok)
			ans[ti] = -1;
		else
		{
			foreach (i; 1..n-1)
				ans[ti] += (a[i]+1) / 2;
		}
	}

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


import std.algorithm;
import std.range;
import std.stdio;
import std.typecons;
import std.traits;
import std.array;
void read(T...)(ref T args)
{
  import std.traits;
  static foreach(i; 0 .. T.length)
    static if(isArray!(T[i]) && !is(T[i] == string))
      foreach(ref e; args[i])
    	read(e);
    else static if(isTuple!(T[i]))
      {
	static foreach(n; 0 .. T[i].Types.length)
	  {
	    read(args[i][n]);
	  }
      }
    else
      readf!" %s "(args[i]);
}
auto brange(alias low, alias high, alias pred, bool value)()
{
  return iota(low, high + 1).map!((a) => cast(int) pred(a)).assumeSorted.equalRange(value);
}
auto ftrue(alias low, alias high, alias pred)()
{
  return brange!(low, high, pred, false).length + low;
}
auto itup(alias k, alias F)()
{
  alias T = Parameters!F;
  foreach(i; 0 .. k)
    {
      T t;
      get(t);
      F(t);
    }
}
alias get = read;
alias w = writeln;
alias ln = long;
ln pmod(ln a, ln m)
{
  return ((a%m+m)%m);
}

int main()
{
  ln t; get(t);
  while(t--)
    {
      ln a, b, c, d, k; get(a, b, c, d, k);
      ln rp = (a + pmod(-a, c)) / c;
      ln rpc = (b + pmod(-b, d)) / d;
      if (rp + rpc <= k)
	{
	  w(rp, " ", rpc);
	}
      else
	{
	  w(-1);
	}
    }
  return 0;
}

import std.stdio;
int main()
{
	int t=0;
	readf(" %d", &t);
	for (int i=0; i<t; i++)
	{
		int a=0;
		int b=0;
		int c=0;
		int d=0;
		int e=0;
		readf(" %d", &a);
		readf(" %d", &b);
		readf(" %d", &c);
		readf(" %d", &d);
		readf(" %d", &e);
		bool flag = false;
		for (int j=0; j<e+1; j++)
		{
			if (j*c>=a && (e-j)*d>=b)
			{
				writeln(j," ", (e-j));
				flag=true;
				break;
			}
		}
		if (flag==false)
		{
			writeln(-1);
		}
	}
	return 0;
}

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

string FMT_F = "%.10f";

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; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
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; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long 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 main()
{
	auto t = RD!int;
	auto ans = new long[2][](t);
	foreach (i; 0..t)
	{
		auto a = RD;
		auto b = RD;
		auto c = RD;
		auto d = RD;
		auto k = RD;
		auto x = (a+c-1)/c;
		auto y = (b+d-1)/d;
		if (x+y <= k)
			ans[i] = [x, y];
		else
			ans[i] = [-1, -1];
	}

	foreach (e; ans)
	{
		if (e[0] == -1)
			writeln(-1);
		else
			writeln(e[0], " ", e[1]);
	}
	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 = 998244353;
//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 main()
{
	auto t = RD!int;
	auto ans = new int[](t);
	foreach (ti; 0..t)
	{
		auto s = RD!string;
		bool start;
		foreach (c; s)
		{
			if (c == '1')
				start = true;
			else if (start)
				++ans[ti];
		}
		foreach_reverse (c; s)
		{
			if (c == '1')
				start = false;
			else if (start)
				--ans[ti];
		}
	}

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

import std.algorithm : max, maxElement;
import std.container : Array;
import std.stdio : stdin, write, writeln;
import std.typecons : Tuple, tuple;

struct IO {
    string readToken() {
        import std.range : empty, front, popFront, split;
        import std.stdio : readln;

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

    int readInt() {
        import std.conv : to;

        return readToken.to!int;
    }

    string[] tokens;
}

int solve(string s) {
    int n = cast(int) s.length;
    int i = 0;
    while (i < n && s[i] == '0') {
        i++;
    }
    if (i == n) {
        return 0;
    }
    int j = n - 1;
    while (s[j] == '0') {
        j--;
    }
    int result = 0;
    for (; j > i; j--) {
        result += s[j] == '0';
    }
    return result;
}

void main() {
    IO io;
    int T = io.readInt;
    while (T--) {
        writeln(solve(io.readToken));
    }
}

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(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0;
string rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;
T chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }

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

void solve(){
	foreach(_; 0 .. rint){
		string s = readln.chomp;
		int a = -1, b = -1;
		foreach(int i, c; s){
			if(c == '1'){
				if(a < 0) a = i;
				b = i;
			}
		}
		if(a < -1) "0".writeln;
		else{
			int ans = 0;
			foreach(int i, c; s){
				if(a <= i && i <= b && c == '0') ans += 1;
			}
			ans.writeln;
		}

	}
}


import std.stdio, std.algorithm, std.conv, std.random;

bool is_good(long x, long A, long B)
{
  if (x < 1)
    return false;
  return x % (A * B) == 0;
}

bool is_nearly_good(long x, long A, long B)
{
  if (x < 1)
    return false;
  return (x % (A * B) != 0) && (x % A == 0);
}

void main()
{
  int t;
  readf!" %d"(t);
  while (t--) {
    long A, B;
    readf!" %d %d"(A, B);
    long x, y, z;
    bool done = false;
    foreach (c1 ; 1 .. 10) {
      if (done)
        break;
      foreach (c2 ; 1 .. 10) {
        if (done)
          break;
        x = A * (B * c1 + 1);
        y = A * (B * c2 - 1);
        z = A * B * (c1 + c2);
        if (x != y && is_good(z, A, B) && is_nearly_good(x, A, B) && is_nearly_good(y, A, B)) {
          writeln("YES\n" ~ [x, y, z].map!text.joiner(" ").text);
          done = true;
        }
      }
    }
    if (!done)
      writeln("NO");
  }
}

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

void main()
{
    auto t = to!long(readln().chomp);
    OUTER: foreach(_; 0..t)
    {
        auto arr = readln().chomp.splitter(" ").map!(to!long).array;
        long a = arr[0];
        long b = arr[1];

        if(b == 1)
        {
            writeln("NO");
            continue OUTER;
        }
        writeln("YES");
        writeln(format("%d %d %d", a*b, a*b+a, a*b*2+a));
    }
}

import std.stdio, std.algorithm, std.conv, std.random;

bool is_good(long x, long A, long B)
{
  if (x < 1)
    return false;
  return x % (A * B) == 0;
}

bool is_nearly_good(long x, long A, long B)
{
  if (x < 1)
    return false;
  return (x % (A * B) != 0) && (x % A == 0);
}

void main()
{
  int t;
  readf!" %d"(t);
  while (t--) {
    long A, B;
    readf!" %d %d"(A, B);
    long x, y, z;
    bool done = false;
    foreach (c1 ; 1 .. 10) {
      if (done)
        break;
      foreach (c2 ; 1 .. 10) {
        if (done)
          break;
        x = A * (B * c1 + 1);
        y = A * (B * c2 - 1);
        z = A * B * (c1 + c2);
        if (is_good(z, A, B) && is_nearly_good(x, A, B) && is_nearly_good(y, A, B)) {
          writeln("YES\n" ~ [x, y, z].map!text.joiner(" ").text);
          done = true;
        }
      }
    }
    if (!done)
      writeln("NO");
  }
}

// Vicfred
// https://codeforces.com/contest/1521/problem/A
// math
import std.stdio;

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

while(t--) {
    long A, B;
    readf("%s %s\n", &A, &B);

    if(B == 1L) {
        "NO".writeln;
        continue;
    }

    long x = A;
    long y = A*B;
    long z = A*(B + 1L);
    "YES".writeln;
    writefln("%s %s %s", x, y, z);
}
}

import std.stdio;
void main()
{
    int q;
    readf!"%d\n"(q);
    foreach (_; 0 .. q)
    {
        long a, b;
        readf!"%d %d\n"(a, b);
        if (b == 1)
            writeln("NO");
        else
            writefln!"YES\n%d %d %d"(a, a * b, a * (b + 1));
    }
}

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

void main()
{
    auto t = to!long(readln().chomp);
    OUTER: foreach(_; 0..t)
    {
        auto arr = readln().chomp.splitter(" ").map!(to!int).array;
        int a = arr[0];
        int b = arr[1];
        int m = max(a,b);

        if(b == 1)
        {
            writeln("NO");
            continue OUTER;
        }
        writeln("YES");
        writeln(format("%d %d %d", a*b, a*b+a, a*b*2+a));
    }
}

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

void main()
{
    auto t = to!long(readln().chomp);
    OUTER: foreach(_; 0..t)
    {
        auto arr = readln().chomp.splitter(" ").map!(to!int).array;
        int a = arr[0];
        int b = arr[1];
        int m = max(a,b);

        if(b == 1) writeln("NO");
        writeln("YES");
        writeln(format("%d %d %d", a*b, a*b+a, a*b*2+a));
    }
}

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

void main()
{
    auto t = to!long(readln().chomp);
    OUTER: foreach(_; 0..t)
    {
        auto arr = readln().chomp.splitter(" ").map!(to!int).array;
        int a = arr[0];
        int b = arr[1];

        for(int i = a; i <= a*b*a; i+= a)
        {
            for(int j = a; j <= a*b*a; j+=a)
            {
                if(i == j) continue;
                int z = i+j;
                if(z % (a*b) == 0 || ((i % (a*b) == 0) != (j % (a*b) == 0)))
                {
                    writeln("YES");
                    writeln(format("%d %d %d", i, j, z));
                    continue OUTER;
                }
            }
        }

        writeln("NO");
    }
}

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

void main()
{
    auto t = to!long(readln().chomp);
    OUTER: foreach(_; 0..t)
    {
        auto arr = readln().chomp.splitter(" ").map!(to!int).array;
        int a = arr[0];
        int b = arr[1];

        for(int i = a; i <= a*b*a; i+= a)
        {
            for(int j = a; j <= a*b*a; j+=a)
            {
                if(i == j || (i+j)%a != 0) continue;
                int z = i+j;
                if(((i % (a*b) == 0) != (j % (a*b) == 0)) != (z % (a*b) == 0))
                {
                    writeln("YES");
                    writeln(format("%d %d %d", i, j, z));
                    continue OUTER;
                }
            }
        }

        writeln("NO");
    }
}

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

void main()
{
    auto t = to!long(readln().chomp);
    OUTER: foreach(_; 0..t)
    {
        auto arr = readln().chomp.splitter(" ").map!(to!int).array;
        int a = arr[0];
        int b = arr[1];

        for(int i = a; i <= int.max; i+= a)
        {
            for(int j = a; j <= int.max; j+=a)
            {
                if(i == j) continue;
                int z = i+j;
                if(((i % (a*b) == 0) != (j % (a*b) == 0)) != (z % (a*b) == 0))
                {
                    writeln("YES");
                    writeln(format("%d %d %d", i, j, z));
                    continue OUTER;
                }
            }
        }

        writeln("NO");
    }
}

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

void main()
{
    auto t = to!long(readln().chomp);
    OUTER: foreach(_; 0..t)
    {
        auto arr = readln().chomp.splitter(" ").map!(to!int).array;
        int a = arr[0];
        int b = arr[1];

        for(int i = a; i <= a*b*a; i+= a)
        {
            for(int j = a; j <= a*b*a; j+=a)
            {
                if(i == j) continue;
                int z = i+j;
                if((i % (a*b) == 0) != (j % (a*b) == 0))
                {
                    if(z % (a*b) == 0) continue;
                    writeln("YES");
                    writeln(format("%d %d %d", i, j, z));
                    continue OUTER;
                }
                else if(z % (a*b) == 0)
                {
                    writeln("YES");
                    writeln(format("%d %d %d", i, j, z));
                    continue OUTER;
                }
            }
        }

        writeln("NO");
    }
}

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

void main()
{
    auto t = to!long(readln().chomp);
    OUTER: foreach(_; 0..t)
    {
        auto arr = readln().chomp.splitter(" ").map!(to!int).array;
        int a = arr[0];
        int b = arr[1];

        for(int i = a; i <= a*b*a; i+= a)
        {
            for(int j = a; j <= a*b*a; j+=a)
            {
                if(i == j) continue;

                if(i % (a*b) == 0 || j % (a*b) == 0)
                {
                    int z = i+j;
                    writeln("YES");
                    writeln(format("%d %d %d", i, j, z));
                    continue OUTER;
                }
                else
                {
                    if((i+j) % (a*b) == 0)
                    {
                        writeln("YES");
                        writeln(format("%d %d %d", i, j, i+j));
                        continue OUTER;
                    }
                }
            }
        }

        writeln("NO");
    }
}

// Vicfred
// https://codeforces.com/contest/1521/problem/A
// math
import std.stdio;

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

while(t--) {
    long A, B;
    readf("%s %s\n", &A, &B);

    if(B == 1L) {
        "NO".writeln;
        continue;
    }

    long x = A;
    long y = A*B;
    long z = A*(B + 1L);
    writefln("%s %s %s", x, y, z);
}
}


// Author: Ivan Kazmenko (gassa@mail.ru)
module solution;
import std.algorithm;
import std.conv;
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 !(int)).array;
		auto t = readln.strip;
		auto lo = n.iota.filter !(i => t[i] == 'B')
		    .map !(i => a[i]).array;
		auto hi = n.iota.filter !(i => t[i] == 'R')
		    .map !(i => a[i]).array;
		sort !(q{a < b}) (lo);
		sort !(q{a > b}) (hi);
		auto okLo = lo.length.iota.all !((int i) => lo[i] >= i + 1);
		auto okHi = hi.length.iota.all !((int i) => hi[i] <= n - i);
		writeln (okLo && okHi ? "YES" : "NO");
	}
}

import std.stdio;
import std.conv;
import std.string;
import std.algorithm;
import std.algorithm.searching;
import std.algorithm.sorting;
import std.math;

void main() {
    int cases = to!int(strip(readln()));

    // per testcase
    for (int t = 0; t < cases; t++) {
        int n;
        readf!"%d\n"(n);

        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            if (i == n-1) readf!"%d\n"(a[i]);
                else readf!"%d "(a[i]);
        }

        int[] up = new int[0];
        int[] down = new int[0];
        for (int i = 0; i < n; i++) {
            char c;
            if (i == n-1) readf!"%c\n"(c);
            else readf!"%c"(c);

            if (c == 'R') up ~= [a[i]];
            else down ~= [a[i]];
        }

        up.sort!("a > b");
        down.sort!("a < b");

        bool possible = true;
        int upper = n;
        for (int i = 0; i < up.length; i++) {
            if (up[i] > upper) possible = false;
            upper --;
        }

        int lower = 1;
        for (int i = 0; i < down.length; i++) {
            if (down[i] < lower) possible = false;
            lower ++;
        }

        if (possible) writeln("YES");
        else writeln("NO");

    }
}

import std.stdio;
import std.conv;
import std.string;
import std.algorithm;
import std.algorithm.searching;
import std.algorithm.sorting;
import std.math;

void main() {
    int cases = to!int(strip(readln()));

    // per testcase
    for (int t = 0; t < cases; t++) {
        int n;
        readf!"%d\n"(n);

        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            if (i == n-1) readf!"%d\n"(a[i]);
                else readf!"%d "(a[i]);
        }

        int[] up = new int[0];
        int[] down = new int[0];
        for (int i = 0; i < n; i++) {
            char c;
            if (i == n-1) readf!"%c\n"(c);
            else readf!"%c"(c);

            if (c == 'R') up ~= [a[i]];
            else down ~= [a[i]];
        }

        up.sort!("a > b");
        down.sort!("a < b");

        bool possible = true;
        int upper = n;
        for (int i = 0; i < up.length; i++) {
            if (up[i] > upper) possible = false;
            upper --;
        }

        int lower = 0;
        for (int i = 0; i < down.length; i++) {
            if (down[i] < lower) possible = false;
            lower ++;
        }

        if (possible) writeln("YES");
        else writeln("NO");

    }
}


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

string FMT_F = "%.10f";

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; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
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; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long 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 main()
{
	auto t = RD!int;
	auto ans = new long[](t);
	foreach (i; 0..t)
	{
		auto a = RD;
		auto b = RD;
		auto n = RD;
		long x, y;
		if (n == 0)
		{
			x = a;
		}
		else if ((n-1) % 3 != 0)
		{
			x = a;
		}
		if (n % 3 != 0)
		{
			y = b;
		}
		ans[i] = x^y;
	}

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

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(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	int t = read.to!int;
	foreach(_; 0 .. t){
		long a = read.to!long;
		long b = read.to!long;
		long n = read.to!long;

		if(n % 3 == 0) a.writeln;
		if(n % 3 == 1) b.writeln;
		if(n % 3 == 2) (a ^b).writeln;
	}

}

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, 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)); }

void main() {
  try {
    for (; ; ) {
      const numCases = readInt();
      foreach (caseId; 0 .. numCases) {
        const A = readLong();
        const B = readLong();
        const N = readLong();
        long ans;
        switch (N % 3) {
          case 0: ans = A; break;
          case 1: ans = B; break;
          case 2: ans = A ^ B; break;
          default: assert(false);
        }
        writeln(ans);
      }
    }
  } catch (EOFException e) {
  }
}


import std.stdio;
import std.algorithm;

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

	int[] res = new int[2 * n];
	fill(res, n);
	for (int i = 1, j = 0, k = n - 1; i < n; i += 2, j++, k--)
		res[j] = res[k] = i;
	for (int i = 2, j = n, k = 2 * n - 2; i < n; i += 2, j++, k--)
		res[j] = res[k] = i;

	writefln("%(%d %)", res);
}

import std.stdio;
import std.algorithm;

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

	int[] res = new int[2 * n];
	fill(res, n);
	for (int i = 1, j = 0, k = n - 1; i < n; i += 2, j++, k--)
		res[j] = res[k] = i;
	for (int i = 2, j = n, k = 2 * n - 2; i < n; i += 2, j++, k--)
		res[j] = res[k] = i;

	for (int i = 0; i < res.length; i++)
		printf("%d%c", res[i], i == res.length - 1 ? '\n' : ' ');
}


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.stdio;

void main() {
    auto S = readln.chomp;
    auto T = readln.chomp;

    long hatena = 0;
    foreach (s; S) if (s == '?') hatena += 1;
    auto cnt2 = new long[](26);
    foreach (s; S) if (s != '?') cnt2[s - 'a'] += 1;

    auto cnt = new long[](26);
    foreach (t; T) cnt[t - 'a'] += 1;

    long hi = 10^^7;
    long lo = 0;
    auto hoge = new long[](26);
    long h;

    while (hi - lo > 1) {
        long mid = (hi + lo) / 2;
        foreach (i; 0..26) hoge[i] = cnt[i] * mid - cnt2[i];
        h = hatena;
        foreach (i; 0..26) h -= max(0, hoge[i]);
        if (h >= 0) lo = mid;
        else hi = mid;
    }

    foreach (i; 0..26) cnt[i] = cnt[i] * lo - cnt2[i];
    int p = 0;
    while (p < 26 && cnt[p] <= 0) p += 1;
    auto ans = new char[](S.length);

    foreach (i; 0..S.length) {
        if (S[i] == '?' && p < 26) {
            ans[i] = (p.to!char + 'a').to!char;
            cnt[p] -= 1;
            while (p < 26 && cnt[p] <= 0) p += 1;
        } else if (S[i] == '?' && p >= 26){
            ans[i] = 'z';
        } else {
            ans[i] = S[i];
        }
    }

    ans.writeln;
}

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

void main(){
	auto s=readln.strip, t=readln.strip;
	int w=0;
	int[26] f,g;
	foreach(c;s) ++('a'<=c&&c<='z'?f[c-'a']:w);
	foreach(c;t) ++g[c-'a'];
	auto ns=s.dup;
	int i=0;
	while(f[].all!(c=>c>=0)){
		f[]-=g[];
		foreach(k,ref c;f){
			if(c>=0) continue;
			int d=min(-c,w);
			c+=d,w-=d;
			foreach(j;0..d){
				while(ns[i]!='?') i++;
				ns[i]=cast(char)('a'+k);
			}
		}
	}
	writeln(ns.to!string);
}

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.stdio;

void main() {
    auto S = readln.chomp;
    auto T = readln.chomp;

    long hatena = 0;
    foreach (s; S) if (s == '?') hatena += 1;
    auto cnt2 = new long[](26);
    foreach (s; S) if (s != '?') cnt2[s - 'a'] += 1;

    auto cnt = new long[](26);
    foreach (t; T) cnt[t - 'a'] += 1;

    int hi = 10^^7;
    int lo = 0;
    auto hoge = new long[](26);
    long h;

    while (hi - lo > 1) {
        int mid = (hi + lo) / 2;
        foreach (i; 0..26) hoge[i] = cnt[i] * mid - cnt2[i];
        h = hatena;
        foreach (i; 0..26) h -= max(0, hoge[i]);
        if (h >= 0) lo = mid;
        else hi = mid;
    }

    foreach (i; 0..26) cnt[i] = cnt[i] * lo - cnt2[i];
    int p = 0;
    while (p < 26 && cnt[p] <= 0) p += 1;
    auto ans = new char[](S.length);

    foreach (i; 0..S.length) {
        if (S[i] == '?' && p < 26) {
            ans[i] = (p.to!char + 'a').to!char;
            cnt[i] -= 1;
            while (p < 26 && cnt[p] <= 0) p += 1;
        } else if (S[i] == '?' && p >= 26){
            ans[i] = 'z';
        } else {
            ans[i] = S[i];
        }
    }

    ans.writeln;
}