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

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 = 998244353;
//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 str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	auto T = RD!int;
	auto ans = new char[][][](T);
	foreach (i; 0..T)
	{
		auto r = RD!int;
		auto c = RD!int;
		auto k = RD!int;
		auto s = new string[](r);
		foreach (j; 0..r)
			s[j] = RD!string;
		ans[i] = new char[][](r, c);

		int rice;
		foreach (y; 0..r)
		{
			foreach (x; 0..c)
			{
				if (s[y][x] == 'R')
					++rice;
			}
		}
		auto cnt1 = rice / k;
		auto cnt2 = rice % k;
		int cnt;
		int num;
		foreach (y; 0..r)
		{
			if (y % 2 == 0)
			{
				foreach (x; 0..c)
				{
					if (s[y][x] == 'R')
					{
						++cnt;
						if (cnt > cnt1+(num < cnt2 ? 1 : 0))
						{
							++num;
							cnt = 1;
						}
					}
					ans[i][y][x] = str[num];
				}
			}
			else
			{
				foreach_reverse (x; 0..c)
				{
					if (s[y][x] == 'R')
					{
						++cnt;
						if (cnt > cnt1+(num < cnt2 ? 1 : 0))
						{
							++num;
							cnt = 1;
						}
					}
					ans[i][y][x] = str[num];
				}
			}
		}
	}

	foreach (e; ans)
	{
		foreach (y; 0..e.length)
		{
			writeln(e[y]);
		}
	}

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

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

void solve(){
	int t = rint;
	foreach(_; 0 .. t){
		int r = rint, c = rint, k = rint;
		bool[][] uf;
		char[][] ansf = new char[][](r, c);
		foreach(i; 0 .. r) uf ~= readln.chomp.to!(char[]).map!(c => c == 'R').array;

		int sum;
		foreach(i; 0 .. r) foreach(j; 0 .. c) if(uf[i][j]) sum += 1;

		int h = 0;
		char[] symbols = ("ABCDEFGHIJKLMNOPQRSTUVWXYZ" ~
		"abcdefghijklmnopqrstuvwxyz" ~ "0123456789").to!(char[]);
		int cnt;
		int[] quota;
		foreach(x; 0 .. k){
			if(x < sum % k) quota ~= sum / k + 1;
			else quota ~= sum / k;
		}
		log("quota:", quota);
		foreach(i; 0 .. r){
			if(i % 2 == 0) foreach(j; 0 .. c){
				if(uf[i][j]) cnt += 1;
				if(cnt > quota[h]) cnt = 1, h += 1;
				ansf[i][j] = symbols[h];
			}
			else foreach_reverse(j; 0 .. c){
				if(uf[i][j]) cnt += 1;
				if(cnt > quota[h]) cnt = 1, h += 1;
				ansf[i][j] = symbols[h];
			}
		}
		foreach(i; 0 .. r) ansf[i].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.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)); }

char tr(int x) {
  if (x < 10) return cast(char)('0' + x);
  if (x < 36) return cast(char)('A' + (x - 10));
  if (x < 62) return cast(char)('a' + (x - 36));
  assert(false);
}

void main() {
  try {
    for (; ; ) {
      const numCases = readInt();
      foreach (caseId; 0 .. numCases) {
        const M = readInt();
        const N = readInt();
        const K = readInt();
        auto A = new string[M];
        foreach (x; 0 .. M) {
          A[x] = readToken();
        }

        int rice;
        foreach (x; 0 .. M) {
          rice += A[x].count('R');
        }
        const q = rice / K, r = rice % K;

        alias Pt = Tuple!(int, "x", int, "y");
        Pt[] ps;
        foreach (x; 0 .. M) {
          if (x % 2 == 0) {
            foreach (y; 0 .. N) {
              ps ~= Pt(x, y);
            }
          } else {
            foreach_reverse (y; 0 .. N) {
              ps ~= Pt(x, y);
            }
          }
        }
        const psLen = cast(int)(ps.length);

        auto ans = new int[][](M, N);
        int pos;
        foreach (k; 0 .. K) {
          int need = q + ((k < r) ? 1 : 0);
          int cnt;
          for (; cnt < need; ++pos) {
            const x = ps[pos].x, y = ps[pos].y;
            ans[x][y] = k;
            if (A[x][y] == 'R') {
              ++cnt;
            }
          }
        }
        for (; pos < psLen; ++pos) {
          const x = ps[pos].x, y = ps[pos].y;
          ans[x][y] = K - 1;
        }

        foreach (x; 0 .. M) {
          foreach (y; 0 .. N) {
            write(tr(ans[x][y]));
          }
          writeln();
        }
      }
    }
  } catch (EOFException e) {
  }
}

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

void main ()
{
	string names;
	foreach (c; 'a'..'z' + 1)
	{
		names ~= cast (char) (c);
	}
	foreach (c; 'A'..'Z' + 1)
	{
		names ~= cast (char) (c);
	}
	foreach (c; '0'..'9' + 1)
	{
		names ~= cast (char) (c);
	}
	debug {writeln (names);}

	int tests;
	readf !(" %s") (tests);
	foreach (test; 0..tests)
	{
		int r, c, k;
		readf !(" %s %s %s") (r, c, k);
		readln;

		auto board = new string [r];
		int num = 0;
		foreach (row; 0..r)
		{
			board[row] = readln.strip;
			num += board[row].count ('R');
		}
		int part = num / k;
		auto give = new int [k];
		foreach (i; 0..num)
		{
			give[i % k] += 1;
		}

		auto ans = new char [] [] (r, c);
		int cur = 0;
		int team = 0;
		foreach (row; 0..r)
		{
			foreach (col0; 0..c)
			{
				auto col = (row & 1) ? col0 : c - col0 - 1;
				ans[row][col] = names[team];
				debug {writeln (row, " ", col, " ", team);}
				cur += (board[row][col] == 'R');
				if (cur >= give[team])
				{
					cur = 0;
					team = min (team + 1, k - 1);
				}
			}
		}
		writefln !("%-(%s\n%)") (ans);
	}
}

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;

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

void solve(){
	int t = rint;
	foreach(_; 0 .. t){
		int r = rint, c = rint, k = rint;
		bool[][] uf;
		char[][] ansf = new char[][](r, c);
		foreach(i; 0 .. r) uf ~= readln.chomp.to!(char[]).map!(c => c == 'R').array;

		int sum;
		foreach(i; 0 .. r) foreach(j; 0 .. c) if(uf[i][j]) sum += 1;

		int h = 0;
		char[] symbols = ("ABCDEFGHIJKLMNOPQRSTUVWXYZ" ~
		"abcdefghijklmnopqrstuvwxyz" ~ "0123456789").to!(char[]);
		int cnt;
		int[] quota;
		foreach(x; 0 .. k){
			if(x < sum % k) quota ~= sum / k + 1;
			else quota ~= sum / k;
		}
		foreach(i; 0 .. r){
			if(i % 2 == 0) foreach(j; 0 .. c){
				if(uf[i][j]) cnt += 1;
				ansf[i][j] = symbols[h];
				if(cnt >= quota[h]) cnt = 0, h += 1;
			}
			else foreach_reverse(j; 0 .. c){
				if(uf[i][j]) cnt += 1;
				ansf[i][j] = symbols[h];
				if(cnt >= quota[h]) cnt = 0, h += 1;
			}
		}
		foreach(i; 0 .. r) ansf[i].writeln;
	}

}

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

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 = 998244353;
//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 str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	auto T = RD!int;
	auto ans = new char[][][](T);
	foreach (i; 0..T)
	{
		auto r = RD!int;
		auto c = RD!int;
		auto k = RD!int;
		auto s = new string[](r);
		foreach (j; 0..r)
			s[j] = RD!string;
		ans[i] = new char[][](r, c);

		int rice;
		foreach (y; 0..r)
		{
			foreach (x; 0..c)
			{
				if (s[y][x] == 'R')
					++rice;
			}
		}
		auto cnt1 = rice / k;
		auto cnt2 = rice % k;
		int cnt;
		int num;
		foreach (y; 0..r)
		{
			if (y % 2 == 0)
			{
				foreach (x; 0..c)
				{
					ans[i][y][x] = str[num];
					if (s[y][x] == 'R')
					{
						++cnt;
						if (cnt >= cnt1+(num < cnt2 ? 1 : 0))
						{
							++num;
							cnt = 0;
						}
					}
				}
			}
			else
			{
				foreach_reverse (x; 0..c)
				{
					ans[i][y][x] = str[num];
					if (s[y][x] == 'R')
					{
						++cnt;
						if (cnt >= cnt1+(num < cnt2 ? 1 : 0))
						{
							++num;
							cnt = 0;
						}
					}
				}
			}
		}
	}

	foreach (e; ans)
	{
		foreach (y; 0..e.length)
		{
			writeln(e[y]);
		}
	}

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

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 = 998244353;
//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 char[][][](T);
	foreach (i; 0..T)
	{
		auto r = RD!int;
		auto c = RD!int;
		auto k = RD!int;
		auto s = new string[](r);
		foreach (j; 0..r)
			s[j] = RD!string;
		ans[i] = new char[][](r, c);

		int rice;
		foreach (y; 0..r)
		{
			foreach (x; 0..c)
			{
				if (s[y][x] == 'R')
					++rice;
			}
		}
		auto cnt1 = rice / k;
		auto cnt2 = rice % k;
		int cnt;
		int num;
		foreach (y; 0..r)
		{
			if (y % 2 == 0)
			{
				foreach (x; 0..c)
				{
					ans[i][y][x] = cast(char)(('0'+num)%256);
					if (s[y][x] == 'R')
					{
						++cnt;
						if (cnt >= cnt1+(num < cnt2 ? 1 : 0))
						{
							++num;
							cnt = 0;
						}
					}
				}
			}
			else
			{
				foreach_reverse (x; 0..c)
				{
					ans[i][y][x] = cast(char)(('0'+num)%256);
					if (s[y][x] == 'R')
					{
						++cnt;
						if (cnt >= cnt1+(num < cnt2 ? 1 : 0))
						{
							++num;
							cnt = 0;
						}
					}
				}
			}
		}
	}

	foreach (e; ans)
	{
		foreach (y; 0..e.length)
		{
			writeln(e[y]);
		}
	}

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

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 = 998244353;
//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 str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	auto T = RD!int;
	auto ans = new char[][][](T);
	foreach (i; 0..T)
	{
		auto r = RD!int;
		auto c = RD!int;
		auto k = RD!int;
		auto s = new string[](r);
		foreach (j; 0..r)
			s[j] = RD!string;
		ans[i] = new char[][](r, c);

		int rice;
		foreach (y; 0..r)
		{
			foreach (x; 0..c)
			{
				if (s[y][x] == 'R')
					++rice;
			}
		}
		auto cnt1 = rice / k;
		auto cnt2 = rice % k;
		int cnt;
		int num;
		foreach (y; 0..r)
		{
			if (y % 2 == 0)
			{
				foreach (x; 0..c)
				{
					if (s[y][x] == 'R')
					{
						++cnt;
						if (cnt > cnt1+(num < cnt2 ? 1 : 0))
						{
							++num;
							cnt = 0;
						}
					}
					ans[i][y][x] = str[num];
				}
			}
			else
			{
				foreach_reverse (x; 0..c)
				{
					if (s[y][x] == 'R')
					{
						++cnt;
						if (cnt > cnt1+(num < cnt2 ? 1 : 0))
						{
							++num;
							cnt = 0;
						}
					}
					ans[i][y][x] = str[num];
				}
			}
		}
	}

	foreach (e; ans)
	{
		foreach (y; 0..e.length)
		{
			writeln(e[y]);
		}
	}

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

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 = 998244353;
//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 char[][][](T);
	foreach (i; 0..T)
	{
		auto r = RD!int;
		auto c = RD!int;
		auto k = RD!int;
		auto s = new string[](r);
		foreach (j; 0..r)
			s[j] = RD!string;
		ans[i] = new char[][](r, c);

		int rice;
		foreach (y; 0..r)
		{
			foreach (x; 0..c)
			{
				if (s[y][x] == 'R')
					++rice;
			}
		}
		auto cnt1 = rice / k;
		auto cnt2 = rice % k;
		int cnt;
		int num;
		foreach (y; 0..r)
		{
			if (y % 2 == 0)
			{
				foreach (x; 0..c)
				{
					ans[i][y][x] = num.to!string[0];
					if (s[y][x] == 'R')
					{
						++cnt;
						if (cnt >= cnt1+(num < cnt2 ? 1 : 0))
						{
							++num;
							cnt = 0;
						}
					}
				}
			}
			else
			{
				foreach_reverse (x; 0..c)
				{
					ans[i][y][x] = num.to!string[0];
					if (s[y][x] == 'R')
					{
						++cnt;
						if (cnt >= cnt1+(num < cnt2 ? 1 : 0))
						{
							++num;
							cnt = 0;
						}
					}
				}
			}
		}
	}

	foreach (e; ans)
	{
		foreach (y; 0..e.length)
		{
			writeln(e[y]);
		}
	}

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

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 = 998244353;
//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 str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	auto T = RD!int;
	auto ans = new char[][][](T);
	foreach (i; 0..T)
	{
		auto r = RD!int;
		auto c = RD!int;
		auto k = RD!int;
		auto s = new string[](r);
		foreach (j; 0..r)
			s[j] = RD!string;
		ans[i] = new char[][](r, c);

		int rice;
		foreach (y; 0..r)
		{
			foreach (x; 0..c)
			{
				if (s[y][x] == 'R')
					++rice;
			}
		}
		auto cnt1 = rice / k;
		auto cnt2 = rice % k;
		int cnt;
		int num;
		foreach (y; 0..r)
		{
			if (y % 2 == 0)
			{
				foreach (x; 0..c)
				{
					if (s[y][x] == 'R')
					{
						++cnt;
						if (cnt >= cnt1+(num < cnt2 ? 1 : 0))
						{
							++num;
							cnt = 0;
						}
					}
					ans[i][y][x] = str[num];
				}
			}
			else
			{
				foreach_reverse (x; 0..c)
				{
					if (s[y][x] == 'R')
					{
						++cnt;
						if (cnt >= cnt1+(num < cnt2 ? 1 : 0))
						{
							++num;
							cnt = 0;
						}
					}
					ans[i][y][x] = str[num];
				}
			}
		}
	}

	foreach (e; ans)
	{
		foreach (y; 0..e.length)
		{
			writeln(e[y]);
		}
	}

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

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 = 998244353;
//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 char[][][](T);
	foreach (i; 0..T)
	{
		auto r = RD!int;
		auto c = RD!int;
		auto k = RD!int;
		auto s = new string[](r);
		foreach (j; 0..r)
			s[j] = RD!string;
		ans[i] = new char[][](r, c);

		int rice;
		foreach (y; 0..r)
		{
			foreach (x; 0..c)
			{
				if (s[y][x] == 'R')
					++rice;
			}
		}
		auto cnt1 = rice / k;
		auto cnt2 = rice % k;
		int cnt;
		int num;
		foreach (y; 0..r)
		{
			if (y % 2 == 0)
			{
				foreach (x; 0..c)
				{
					ans[i][y][x] = cast(char)(('a'+num)%256);
					if (s[y][x] == 'R')
					{
						++cnt;
						if (cnt >= cnt1+(num < cnt2 ? 1 : 0))
						{
							++num;
							cnt = 0;
						}
					}
				}
			}
			else
			{
				foreach_reverse (x; 0..c)
				{
					ans[i][y][x] = cast(char)(('a'+num)%256);
					if (s[y][x] == 'R')
					{
						++cnt;
						if (cnt >= cnt1+(num < cnt2 ? 1 : 0))
						{
							++num;
							cnt = 0;
						}
					}
				}
			}
		}
	}

	foreach (e; ans)
	{
		foreach (y; 0..e.length)
		{
			writeln(e[y]);
		}
	}

	stdout.flush();
	debug readln();
}


import std.stdio;
import std.exception;
import std.algorithm;
import std.math;

int gcd(int a, int b) { return a == 0 ? b : gcd(b % a, a); }

void main() { while (solve()) {} }

enum N = 100500;

struct node {
	int g;
	int mn, cntmn;
	int len;
	this(int val) {
		this.g = val;
		this.mn = val;
		this.cntmn = 1;
		this.len = 1;
	}
	int ans() {
		if (mn != g) return len;
		return len - cntmn;
	}
}

node merge(node a, node b) {
	node res;
	res.len = a.len + b.len;
	res.g = gcd(a.g, b.g);
	res.mn = min(a.mn, b.mn);
	res.cntmn = 0;
	if (res.mn == a.mn) res.cntmn += a.cntmn;
	if (res.mn == b.mn) res.cntmn += b.cntmn;
	return res;
}

node[4 * N] t;
int[N] a;

void build(size_t v, size_t lf, size_t rg) {
	if (lf + 1 == rg) {
		t[v] = node(a[lf]);
		return;
	}
	size_t mid = (lf + rg) / 2;
	build(v * 2 + 1, lf, mid);
	build(v * 2 + 2, mid, rg);
	t[v] = merge(t[v * 2 + 1], t[v * 2 + 2]);
}

node get(size_t from, size_t to, size_t v, size_t lf, size_t rg) {
	if (from == lf && to == rg) return t[v];
	size_t mid = (lf + rg) / 2;
	if (to <= mid) return get(from, to, v * 2 + 1, lf, mid);
	if (from >= mid) return get(from, to, v * 2 + 2, mid, rg);
	return merge(get(from, mid, v * 2 + 1, lf, mid),
		get(mid, to, v * 2 + 2, mid, rg));
}

size_t n;

bool solve() {
	if (!readf(" %s", &n)) return false;
	foreach (i; 0..n)
		enforce(readf(" %s", &a[i]));
	build(0, 0, n);
	size_t m;
	enforce(readf(" %s", &m));
	foreach (i; 0..m) {
		size_t lf, rg;
		enforce(readf(" %s %s", &lf, &rg));
		lf--;
		node res = get(lf, rg, 0, 0, n);
		writeln(res.ans);
	}
	return true;
}

import std.stdio;
import std.conv;

immutable N = 100001;

int[N] a;
int[4*N] tree;
int[][int] mapper;

int gcd(int a, int b) {
  while (b != 0) {
    int t = a % b;
    a = b;
    b = t;
  }
  return a;
}

void build(int x, int l, int r) {
  if (l == r) {
    tree[x] = a[l];
  } else {
    int mid = (l + r) >> 1;
    build(x << 1, l, mid);
    build(x << 1 | 1, mid + 1, r);
    tree[x] = gcd(tree[x << 1], tree[x << 1 | 1]);
  }
}

int query(int x, int l, int r, int ql, int qr) {
  if (l > qr || r < ql) {
    return 0;
  } else if (l >= ql && r <= qr) {
    return tree[x];
  } else {
    int mid = (l + r) >> 1;
    return gcd(query(x << 1, l, mid, ql, qr), query(x << 1 | 1, mid + 1, r, ql, qr));
  }
}

void main() {
  int n; readf(" %s", &n);
  for (int i = 0; i < n; i++) {
    readf(" %s", &a[i]);
    mapper[a[i]] ~= i;
  }
  build(1, 0, n - 1);
  int t; readf(" %s", &t);
  while (t--) {
    int l, r; readf(" %s %s", &l, &r); l--; r--;
    int g = query(1, 0, n - 1, l, r);
    if (g in mapper) {
      int ll, rr;
      int lo = -1, hi = to!(int)(mapper[g].length);
      while (lo + 1 < hi) {
        int mid = (lo + hi) >> 1;
        if (mapper[g][mid] < l) lo = mid;
        else hi = mid;
      }
      ll = hi;
      lo = -1; hi = to!(int)(mapper[g].length);
      while (lo + 1 < hi) {
        int mid = (lo + hi) >> 1;
        if (mapper[g][mid] > r) hi = mid;
        else lo = mid;
      }
      rr = lo;
      writeln((r - l + 1) - (rr - ll + 1));
    } else {
      writeln(r - l + 1);
    }
  }
}

import std.stdio;
import std.conv;

immutable N = 100001;

int[N] a;
int[4*N] tree;
int[][int] mapper;

int gcd(int a, int b) {
  while (b != 0) {
    int t = a % b;
    a = b;
    b = t;
  }
  return a;
}

void build(int x, int l, int r) {
  if (l == r) {
    tree[x] = a[l];
  } else {
    int mid = (l + r) >> 1;
    build(x << 1, l, mid);
    build(x << 1 | 1, mid + 1, r);
    tree[x] = gcd(tree[x << 1], tree[x << 1 | 1]);
  }
}

int query(int x, int l, int r, int ql, int qr) {
  if (l > qr || r < ql) {
    return 0;
  } else if (l >= ql && r <= qr) {
    return tree[x];
  } else {
    int mid = (l + r) >> 1;
    return gcd(query(x << 1, l, mid, ql, qr), query(x << 1 | 1, mid + 1, r, ql, qr));
  }
}

void main() {
  int n; readf(" %s", &n);
  for (int i = 0; i < n; i++) {
    readf(" %s", &a[i]);
    mapper[a[i]] ~= i;
  }
  build(1, 0, n - 1);
  int t; readf(" %s", &t);
  while (t--) {
    int l, r; readf(" %s %s", &l, &r); l--; r--;
    int g = query(1, 0, n - 1, l, r);
    if (g in mapper) {
      int ll, rr;
      int lo = -1, hi = to!(int)(mapper[g].length);
      while (lo + 1 < hi) {
        int mid = (lo + hi) >> 1;
        if (mapper[g][mid] < l) lo = mid;
        else hi = mid;
      }
      ll = hi;
      lo = -1; hi = to!(int)(mapper[g].length);
      while (lo + 1 < hi) {
        int mid = (lo + hi) >> 1;
        if (mapper[g][mid] > r) hi = mid;
        else lo = mid;
      }
      rr = lo;
      writeln((r - l + 1) - (rr - ll + 1));
    } else {
      writeln(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; }
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; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }

long mod = 10^^9 + 7;
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 N = RD!uint;
	auto M = RD!uint;
	auto a = new long[][](N);
	foreach (i; 0..N)
	{
		a[i] = RDR.ARR;
	}

	long x = a[0][0];
	foreach (i; 1..N)
	{
		x ^= a[i][0];
		debug writeln(x);
	}

	uint pos_i = N, pos_j;
	(){
	foreach (i; 0..N)
	{
		foreach (j; 1..M)
		{
			if (x != 0) return;
			x ^= a[i][j-1];
			x ^= a[i][j];
			pos_i = i;
			pos_j = j;
		}
	}}();

	if (x == 0)
		writeln("NIE");
	else
	{
		writeln("TAK");
		if (pos_i == 0)
			write(pos_j+1);
		else
			write(1);
		foreach (i; 1..N)
		{
			if (i == pos_i)
				write(" ", pos_j+1);
			else
				write(" ", 1);
		}
		writeln();
	}
	stdout.flush();
	debug readln();
}

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

int[500][500] IS;
int[10][500] BS;

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];
    foreach (i; 0..N) {
        int[10] ds;
        foreach (j, n; readln.split.to!(int[])) {
            IS[i][j] = n;
            foreach (d; 0..10) {
                auto x = (n>>d)&1;
                if (!j) {
                    ds[d] = x;
                } else if (ds[d] != x) {
                    ds[d] = 2;
                }
            }
        }
        BS[i] = ds;
    }
    int targ_d = -1, one_cnt;
    foreach (d; 0..10) {
        one_cnt = 0;
        foreach (i; 0..N) {
            if (BS[i][d] == 2) {
                targ_d = d;
            } else if (BS[i][d] == 1) {
                ++one_cnt;
            }
        }
        if (one_cnt%2 == 1) targ_d = d;
        if (targ_d != -1) break;
    }
    if (targ_d == -1) {
        writeln("NIE");
        return;
    }
    one_cnt = one_cnt%2 == 1 ? 0 : 1;
    int[] r;
    foreach (j, ns; IS[0..N]) {
        if (BS[j][targ_d] != 2) {
            r ~= 1;
        } else {
            foreach (int i, n; ns[0..M]) {
                auto x = (n>>targ_d)&1;
                if (one_cnt && x) {
                    --one_cnt;
                    r ~= i+1;
                    break;
                } else if (!one_cnt && !x) {
                    r ~= i+1;
                    break;
                }
            }
        }
    }
    writeln("TAK");
    writeln(r.to!(string[]).join(" "));
}

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; }
T read(T)(){ return read.to!T; }
T[] read(T)(long n){ return n.iota.map!(_ => read!T).array; }
T[][] read(T)(long m, long n){ return m.iota.map!(_ => read!T(n)).array; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){

	int n = read!int;
	int m = read!int;
	int[][] as = read!int(n, m);

	int i1 = 0, j1 = 0;
	bool f = 0;
A:
	foreach(i; 0 .. n){
		int[] q = as[i];
		foreach(j; 0 .. m){
			if(q[j] != q[0]){
				i1 = i;
				j1 = j;
				f = 1;
				break A;
			}
		}
	}

	int ansj = 0;
	int xor;
	foreach(i; 0 .. n) xor ^= as[i][0];
	if(xor == 0){
		if(j1 != 0) ansj = j1;
		else{
			"NIE".writeln;
			return;
		}
	}

	"TAK".writeln;
	int[] ans;
	foreach(i; 0 .. n) ans ~= 1;
	ans[i1] = ansj + 1;
	ans.map!(to!string).join(" ").writeln;

}

import std.stdio : writef, readf, readln, writeln, writefln, write;
import std.array : array, split;
import std.algorithm : sort, each, maxElement, minElement;
import std.conv : to;
import std.range : iota, tee, enumerate;
import std.algorithm.comparison : equal, max, min;
import std.container.rbtree : RBT = RedBlackTree;
import std.string : strip;
import core.memory : GC;
import std.typecons : tuple;

alias Tree = RBT!int;

void main() {
    GC.disable();

    uint n, m;

    readf(" %s %s\n", n, m);

    auto a = new int[][n];
    uint saver = 100000000;
    uint x1 = 0;
    uint x2 = 0;
    uint pos2 = 0;
    uint pos1 = 0;
    bool flag = false;
    foreach (i; 0 .. n) {
        a[i] = new int[m];
        foreach (j; 0 .. m)
            readf(" %s", a[i][j]);

        auto ma = a[i].enumerate.maxElement!"a.value";
        auto mi = a[i].enumerate.minElement!"a.value";
        if (ma[1] != mi[1] && !flag) {
            saver = i;
            x1 ^= ma[1];
            x2 ^= mi[1];
            pos1 = ma[0];
            pos2 = mi[0];
            flag = true;
        }
        else {
            x1 ^= a[i][0];
            x2 ^= a[i][0];
        }
    }

    if (x1 == 0 && x2 == 0) {
        writeln("NIE");
    }
    else {
        writeln("TAK");
        foreach (i; 0 .. n) {
            if (i != saver)
                write(1, " ");
            else {
                if (x1 != 0)
                    write(pos1 + 1, " ");
                else if (x2 != 0)
                    write(pos2 + 1, " ");
            }
        }
        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 s = readln.split.map!(to!int);
    auto H = s[0];
    auto W = s[1];
    auto A = H.iota.map!(_ => readln.split.map!(to!int).array).array;

    auto x = A.map!(a => a.front).reduce!"a ^ b";
    int r = -1, c = -1;

    if (x == 0) {
        outer: foreach (i; 0..H) {
            foreach (j; 1..W) {
                if (A[i][j] != A[i][0]) {
                    r = i;
                    c = j;
                    break outer;
                }
            }
        }
        if (r == -1) {
            writeln("NIE");
            return;
        }
    }

    writeln("TAK");
    H.iota.map!(i => i == r ? c + 1 : 1).map!(to!string).join(" ").writeln;
}

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

int[500][500] IS;
int[10][500] BS;

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];
    foreach (i; 0..N) {
        int[10] ds;
        foreach (j, n; readln.split.to!(int[])) {
            IS[i][j] = n;
            foreach (d; 0..10) {
                auto x = (n>>d)&1;
                if (!j) {
                    ds[d] = x;
                } else if (ds[d] != x) {
                    ds[d] = 2;
                }
            }
        }
        BS[i] = ds;
    }
    int targ_d = -1, free_cnt, one_cnt;
    foreach (d; 0..10) {
        one_cnt = 0;
        foreach (i; 0..N) {
            if (BS[i][d] == 2) {
                targ_d = d;
                ++free_cnt;
            } else if (BS[i][d] == 1) {
                ++one_cnt;
            }
        }
        if (one_cnt%2 == 1) targ_d = d;
    }
    if (targ_d == -1) {
        writeln("NIE");
        return;
    }
    one_cnt = one_cnt%2 == 1 ? 0 : 1;
    int[] r;
    foreach (j, ns; IS[0..N]) {
        if (BS[j][targ_d] != 2) {
            r ~= 1;
        } else {
            foreach (int i, n; ns[0..M]) {
                auto x = (n>>targ_d)&1;
                if (one_cnt && x) {
                    --one_cnt;
                    r ~= i+1;
                } else if (!one_cnt && !x) {
                    r ~= i+1;
                }
            }
        }
    }
    writeln("TAK");
    writeln(r.to!(string[]).join(" "));
}

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

int[500][500] IS;
int[10][500] BS;

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];
    foreach (i; 0..N) {
        int[10] ds;
        foreach (j, n; readln.split.to!(int[])) {
            IS[i][j] = n;
            foreach (d; 0..10) {
                auto x = (n>>d)&1;
                if (!j) {
                    ds[d] = x;
                } else if (ds[d] != x) {
                    ds[d] = 2;
                }
            }
        }
        BS[i] = ds;
    }
    int targ_d = -1, free_cnt, one_cnt;
    foreach (d; 0..10) {
        one_cnt = 0;
        foreach (i; 0..N) {
            if (BS[i][d] == 2) {
                targ_d = d;
                ++free_cnt;
            } else if (BS[i][d] == 1) {
                ++one_cnt;
            }
        }
        if (one_cnt%2 == 1) targ_d = d;
        if (targ_d != -1) break;
    }
    if (targ_d == -1) {
        writeln("NIE");
        return;
    }
    one_cnt = one_cnt%2 == 1 ? 0 : 1;
    int[] r;
    foreach (j, ns; IS[0..N]) {
        if (BS[j][targ_d] != 2) {
            r ~= 1;
        } else {
            foreach (int i, n; ns[0..M]) {
                auto x = (n>>targ_d)&1;
                if (one_cnt && x) {
                    --one_cnt;
                    r ~= i+1;
                } else if (!one_cnt && !x) {
                    r ~= i+1;
                }
            }
        }
    }
    writeln("TAK");
    writeln(r.to!(string[]).join(" "));
}

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

int[500][500] IS;
int[10][500] BS;

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];
    foreach (i; 0..N) {
        int[10] ds;
        foreach (j, n; readln.split.to!(int[])) {
            IS[i][j] = n;
            foreach (d; 0..10) {
                auto x = (n>>d)&1;
                if (!j) {
                    ds[d] = x;
                } else if (ds[d] != x) {
                    ds[d] = 2;
                }
            }
        }
        BS[i] = ds;
    }
    int targ_d = -1, targ_i, free_cnt, one_cnt;
    foreach (d; 0..10) {
        one_cnt = 0;
        foreach (i; 0..N) {
            if (BS[i][d] == 2) {
                targ_d = d;
                ++free_cnt;
            } else if (BS[i][d] == 1) {
                ++one_cnt;
            }
        }
        if (one_cnt%2 == 1) targ_d = d;
    }
    if (targ_d == -1) {
        writeln("NIE");
        return;
    }
    one_cnt = one_cnt%2 == 1 ? 0 : 1;
    int[] r;
    foreach (j, ns; IS[0..N]) {
        if (BS[j][targ_d] != 2) {
            r ~= 1;
        } else {
            foreach (int i, n; ns[0..M]) {
                auto x = (n>>targ_d)&1;
                if (one_cnt && x) {
                    --one_cnt;
                    r ~= i+1;
                } else if (!one_cnt && !x) {
                    r ~= i+1;
                }
            }
        }
    }
    writeln(r.to!(string[]).join(" "));
}

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; }
T read(T)(){ return read.to!T; }
T[] read(T)(long n){ return n.iota.map!(_ => read!T).array; }
T[][] read(T)(long m, long n){ return m.iota.map!(_ => read!T(n)).array; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){

	int n = read!int;
	int m = read!int;
	int[][] as = read!int(n, m);

	int i1, j1;
	bool f = 0;
A:
	foreach(i; 0 .. n){
		int[] q = as[i];
		foreach(j; 0 .. m){
			if(q[j] != q[0]){
				i1 = i;
				j1 = j;
				f = 1;
				break A;
			}
		}
	}
	if(! f){
		"NIE".writeln;
		return;
	}

	int xor;
	foreach(i; 0 .. n) xor ^= as[i][0];
	int ansj;
	if(xor != 0) ansj = 0; else ansj = j1;

	"TAK".writeln;
	int[] ans;
	foreach(i; 0 .. n) ans ~= 1;
	ans[i1] = ansj + 1;
	ans.map!(to!string).join(" ").writeln;

}

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; }
T read(T)(){ return read.to!T; }
T[] read(T)(long n){ return n.iota.map!(_ => read!T).array; }
T[][] read(T)(long m, long n){ return m.iota.map!(_ => read!T(n)).array; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){

	int n = read!int;
	int m = read!int;
	int[][] as = read!int(n, m);

	int i1, j1;
	bool f = 0;
A:
	foreach(i; 0 .. n){
		int[] q = as[i];
		foreach(j; 0 .. m){
			if(q[j] != q[0]){
				i1 = i;
				j1 = j;
				f = 1;
				break A;
			}
		}
	}
	if(! f){
		"NIE".writeln;
		return;
	}

	int xor;
	foreach(i; 0 .. n){
		if(i != i1) xor ^= as[i][0];
	}
	int ansj;
	if((xor ^ as[i1][0]) != 0) ansj = 0; else ansj = j1;

	"TAK".writeln;
	int[] ans;
	foreach(i; 0 .. n){
		if(i != i1) ans ~= 1;
		else ans ~= ansj + 1;
	}
	ans.map!(to!string).join(" ").writeln;

}

import std.stdio : writef, readf, readln, writeln, writefln, write;
import std.array : array, split;
import std.algorithm : sort, each, maxElement, minElement;
import std.conv : to;
import std.range : iota, tee, enumerate;
import std.algorithm.comparison : equal, max, min;
import std.container.rbtree : RBT = RedBlackTree;
import std.string : strip;
import core.memory : GC;
import std.typecons : tuple;

alias Tree = RBT!int;

void main() {
    GC.disable();

    uint n, m;

    readf(" %s %s\n", n, m);

    auto a = new int[][n];
    uint saver = 100000000;

    uint x1 = 0;
    uint x2 = 0;
    bool flag = false;
    uint pos2 = 0;
    uint pos1 = 0;
    foreach (i; 0 .. n) {
        a[i] = new int[m];
        foreach (j; 0 .. m)
            readf(" %s", a[i][j]);

        auto ma = a[i].enumerate.maxElement!"a.value";
        auto mi = a[i].enumerate.minElement!"a.value";
        if (ma[1] != mi[1] && !flag) {
            saver = i;
            flag = true;
            x1 ^= ma[1];
            x2 ^= mi[1];
            pos1 = ma[0];
            pos2 = mi[0];
        }
        else {
            x1 ^= a[i][0];
            x2 ^= a[i][0];
        }
    }

    if (x1 == 0 && x2 == 0) {
        writeln("NIE");
    }
    else {
        writeln("TAK");
        foreach (i; 0 .. n) {
            if (i != saver)
                write(1, " ");
            else {
                if (x1 != 0)
                    write(pos1 + 1, " ");
                if (x2 != 0)
                    write(pos2 + 1, " ");
            }
        }
        writeln();
    }
}

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; }
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; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }

long mod = 10^^9 + 7;
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 N = RD!uint;
	auto M = RD!uint;
	auto a = new long[][](N);
	foreach (i; 0..N)
	{
		a[i] = RDR.ARR;
	}

	long x = a[0][0];
	foreach (i; 1..N)
	{
		x ^= a[i][0];
		debug writeln(x);
	}

	uint pos_i = N, pos_j;
	(){
	foreach (j; 1..M)
	{
		foreach (i; 0..N)
		{
			if (x != 0) return;
			if (a[i][j] == a[i][j-1]) continue;
			x ^= a[i][j];
			pos_i = i;
			pos_j = j;
		}
	}}();

	if (x == 0)
		writeln("NIE");
	else
	{
		writeln("TAK");
		write(pos_j+1);
		foreach (i; 1..pos_i+1)
		{
			write(" ", pos_j+1);
		}
		foreach (i; pos_i+1..N)
		{
			write(" ", pos_j);
		}
		writeln();
	}
	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.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; }
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; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }

long mod = 10^^9 + 7;
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 N = RD!uint;
	auto M = RD!uint;
	auto a = new long[][](N);
	foreach (i; 0..N)
	{
		a[i] = RDR.ARR;
	}

	long x = a[0][0];
	foreach (i; 1..N)
	{
		x ^= a[i][0];
		debug writeln(x);
	}

	uint pos_i = N, pos_j;
	(){
	foreach (j; 1..M)
	{
		foreach (i; 0..N)
		{
			if (x != 0) return;
			x ^= a[i][j-1];
			x ^= a[i][j];
			pos_i = i;
			pos_j = j;
		}
	}}();

	if (x == 0)
		writeln("NIE");
	else
	{
		writeln("TAK");
		write(pos_j+1);
		foreach (i; 1..pos_i+1)
		{
			write(" ", pos_j+1);
		}
		foreach (i; pos_i+1..N)
		{
			write(" ", pos_j);
		}
		writeln();
	}
	stdout.flush();
	debug readln();
}


import std.stdio;

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

  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      int k = i;
      if (i > n/2){
        k = n - i -1;
      }
      if(j <= n/2+k && j >= n/2-k){
        write("D");
      } else {
        write("*");
      }
    }
    writeln();
  }
}

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

//	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, const T f) { if (t > f) t = f; }
void chmax(T)(ref T t, const T f) { if (t < f) t = f; }

//	Pair
struct Pair(S, T) {
	S x; T y;
	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)(S x, T y) { return Pair!(S, T)(x, y); }

//	Array
int binarySearch(T)(T[] as, 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)(T[] as, T val) { return as.binarySearch((T a) { return (a <  val); }); }
int upperBound(T)(T[] as, T val) { return as.binarySearch((T a) { return (a <= val); }); }
T[] unique(T)(T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }

int N;

void main(string[] args) {
	try {
	for (; ; ) {
		N = readInt;

		char[][] cs = new char[][](N, N);
		foreach (x; 0 .. N) foreach (y; 0 .. N) {
			cs[x][y] = (abs(x - N / 2) + abs(y - N / 2) <= N / 2) ? 'D' : '*';
		}
		foreach (x; 0 .. N) {
			writeln(cs[x].to!string);
		}
	}
	} catch (EOFException) {}
}


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

bool solve (int n, int [] a)
{
	auto m = 1 << n;

	for (int s = 0; s < m; s++)
	{
		int r = m - 1 - s;
		int t = r;
		do
		{
			int cur = 0;
			foreach (i; 0..n)
			{
				if (s & (1 << i))
				{
					cur += a[i];
				}
				if (t & (1 << i))
				{
					cur -= a[i];
				}
			}
			if (cur == 0 && !(s == 0 && t == 0))
			{
				return true;
			}

			t = (t - 1) & r;
		}
		while (t != r);
	}

	return false;
}

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 (n, a) ? "YES" : "NO");
	}
}

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

int N = 10000000 + 32;
int[] gdiffmap;

void update_diffmap(int[] b, int bs, int delta)
{
  int bj = b[bs - 1];
  int diffbase = N;
  int *diffmap = &gdiffmap[diffbase];
  foreach (bii ; 0 .. bs) {
    int bi = b[bii];
    diffmap[bi - bj] += delta;
    diffmap[bj - bi] += delta;
  }
}

bool solve(int[] a, int i, int[] b, int bs)
{
  int[] diffmap = gdiffmap;
  int diffbase = N;
  if (i == a.length)
    return false;

  update_diffmap(b, bs, 1);
  if (diffmap[diffbase + a[i]] > 0) {
    update_diffmap(b, bs, -1);
    return true;
  }

  foreach (bii ; 0 .. bs) {
    b[bs] = b[bii] + a[i];
    if (solve(a, i + 1, b, bs + 1)) {
      update_diffmap(b, bs, -1);
      return true;
    }
  }

  update_diffmap(b, bs, -1);
  return false;
}

void main()
{
  int t;
  readf!" %d "(t);
  gdiffmap = new int[](2 * N);
  while (t--) {
    int n;
    readf!" %d "(n);
    auto a = readln.strip.split.map!(to!int).array;
    auto b = new int[](n + 1);
    writeln(solve(a, 0, b, 1) ? "YES" : "NO");
  }
}

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 int[N];
        foreach (i; 0 .. N) {
          A[i] = readInt();
        }

        bool ans;
        void dfs(int i, bool any, int sum) {
          ans = ans || (any && sum == 0);
          if (i == N) {
            return;
          }
          dfs(i + 1, any, sum);
          dfs(i + 1, true, sum + A[i]);
          dfs(i + 1, true, sum - A[i]);
        }

        dfs(0, false, 0);
        writeln(ans ? "YES" : "NO");
      }
    }
  } catch (EOFException e) {
  }
}


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

void main()
{
	auto n = readln().chomp().to!int();
	auto input = readln().chomp();
	int[] len;

	foreach (sentence; splitter(input, regex(r"[.!?][ ]?"))) {
		if (sentence.length) {
			len ~= sentence.length + 2;
		} else {
			len[0]--;
		}
	}
	len ~= 0;

	auto cnt = 1;
	for (int i = 0; i < len.length - 1; i++) {
		if (len[i] > n) {
			cnt = 0;
			break;
		}
		if (len[i] + len[i+1] > n) {
			len[i+1]--;
			cnt++;
		}
		else len[i+1] += len[i];
	}

	if (cnt) writeln(cnt);
	else writeln("Impossible");
}

module main;
import std.bigint,std.container,std.array,std.algorithm,std.conv,
	std.functional,std.math,std.numeric,std.string,std.range,std.complex,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.variant,
	std.stdio,std.bitmanip;
import core.stdc.stdio : freopen;
alias RedBlackTree Rbt;
alias redBlackTree rbt;
alias BigInt big;
alias pair!(int,int) pii;
alias pair!(long,long) pll;
alias boyerMooreFinder strfind;
alias make_pair mp;
alias binary_search bins;
alias pair(X,Y)=Tuple!(X,q{fi},Y,q{se});
pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_)
{
	pair!(X,Y) pp;
	pp.fi=x_;
	pp.se=y_;
	return pp;
}
immutable int mod=10^^9+7;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b)
	{
		return a/gcd(a,b)*b;
	}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	size_t lowb(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (!(a[l]<g))?l:r;
	}
	size_t upb(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(g<a[m])r=m;
			else l=m;
		}
		return (g<a[l])?l:r;
	}
	size_t binf(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (g==a[l])?l:a.length;
	}
	bool binary_search(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		return binf(a,g)!=a.length;
	}
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a,in size_t n,in size_t m) if(isRandomAccessRange!X)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n) if(hasSlicing!X)
{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length), ptrs)==ptrs.length;}
bool read(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length)~'\n', ptrs)==ptrs.length;}
nothrow void inf(in char* name) {freopen(name,"r",core.stdc.stdio.stdin);}
nothrow void ouf(in char* name) {freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold schwartzSort multiSort partialSort heapify join filter countUntil
//---------------------------------------------------------------program beginning-----------------------------------------------------------------

void main()
{
	int n;
	loop:while(read(&n))
	{
		auto a=readln.strip.splitter(regex("[.?!]+")).map!(a => a.length+1).array[0..$-1];
		debug writeln(a);
		int pos=0,len,ans;
		while(pos<a.length)
		{
			len=a[pos];
			if(pos!=0)len--;
			if(len>n)
			{
				writeln("Impossible");
				continue loop;
			}
			while(pos<a.length-1 && len+a[pos+1]<=n)
			{
				pos++;
				len+=a[pos];
			}
			ans++;
			pos++;
		}
		writeln(ans);
	}

}

module main;
import std.bigint,std.container,std.array,std.algorithm,std.conv,
	std.functional,std.math,std.numeric,std.string,std.range,std.complex,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.variant,
	std.stdio,std.bitmanip;
import core.stdc.stdio : freopen;
alias RedBlackTree Rbt;
alias redBlackTree rbt;
alias BigInt big;
alias pair!(int,int) pii;
alias pair!(long,long) pll;
alias boyerMooreFinder strfind;
alias make_pair mp;
alias binary_search bins;
alias pair(X,Y)=Tuple!(X,q{fi},Y,q{se});
pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_)
{
	pair!(X,Y) pp;
	pp.fi=x_;
	pp.se=y_;
	return pp;
}
immutable int mod=10^^9+7;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b)
	{
		return a/gcd(a,b)*b;
	}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	size_t lowb(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (!(a[l]<g))?l:r;
	}
	size_t upb(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(g<a[m])r=m;
			else l=m;
		}
		return (g<a[l])?l:r;
	}
	size_t binf(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (g==a[l])?l:a.length;
	}
	bool binary_search(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		return binf(a,g)!=a.length;
	}
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a,in size_t n,in size_t m) if(isRandomAccessRange!X)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n) if(hasSlicing!X)
{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length), ptrs)==ptrs.length;}
bool read(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length)~'\n', ptrs)==ptrs.length;}
nothrow void inf(in char* name) {freopen(name,"r",core.stdc.stdio.stdin);}
nothrow void ouf(in char* name) {freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold schwartzSort multiSort partialSort heapify join filter countUntil
//---------------------------------------------------------------program beginning-----------------------------------------------------------------

void main()
{
	int n;
	loop:while(read(&n))
	{
		auto a=readln.splitter(regex("[.?!\n]+")).map!(a => a.length+1).array;
		int pos=0,len,ans;
		while(pos<a.length)
		{
			len=a[pos];
			if(pos!=0)len--;
			if(len>n)
			{
				writeln("Impossible");
				continue loop;
			}
			while(pos<a.length-1 && len+a[pos+1]<=n)
			{
				pos++;
				len+=a[pos];
			}
			ans++;
			pos++;
		}
		writeln(ans);
	}

}

module main;
import std.bigint,std.container,std.array,std.algorithm,std.conv,
	std.functional,std.math,std.numeric,std.string,std.range,std.complex,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.variant,
	std.stdio,std.bitmanip;
import core.stdc.stdio : freopen;
alias RedBlackTree Rbt;
alias redBlackTree rbt;
alias BigInt big;
alias pair!(int,int) pii;
alias pair!(long,long) pll;
alias boyerMooreFinder strfind;
alias make_pair mp;
alias binary_search bins;
alias pair(X,Y)=Tuple!(X,q{fi},Y,q{se});
pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_)
{
	pair!(X,Y) pp;
	pp.fi=x_;
	pp.se=y_;
	return pp;
}
immutable int mod=10^^9+7;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b)
	{
		return a/gcd(a,b)*b;
	}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	size_t lowb(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (!(a[l]<g))?l:r;
	}
	size_t upb(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(g<a[m])r=m;
			else l=m;
		}
		return (g<a[l])?l:r;
	}
	size_t binf(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (g==a[l])?l:a.length;
	}
	bool binary_search(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		return binf(a,g)!=a.length;
	}
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a,in size_t n,in size_t m) if(isRandomAccessRange!X)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n) if(hasSlicing!X)
{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length), ptrs)==ptrs.length;}
bool read(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length)~'\n', ptrs)==ptrs.length;}
nothrow void inf(in char* name) {freopen(name,"r",core.stdc.stdio.stdin);}
nothrow void ouf(in char* name) {freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold schwartzSort multiSort partialSort heapify join filter countUntil
//---------------------------------------------------------------program beginning-----------------------------------------------------------------

void main()
{
	int n;
	loop:while(read(&n))
	{
		auto a=readln.splitter(regex("[.?!\n]+")).map!(a => a.length+1).array;
		int pos=0,len,ans;
		while(pos<a.length)
		{
			len=a[pos];
			if(len>n)
			{
				writeln("Impossible");
				continue loop;
			}
			while(pos<a.length-1 && len+a[pos+1]+1<=n)
			{
				pos++;
				len+=a[pos]+1;
			}
			ans++;
			pos++;
		}
		writeln(ans);
	}

}

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

void main()
{
	auto n = readln().chomp().to!int();
	auto input = readln().chomp();
	int[] len;

	foreach (sentence; splitter(input, regex(r"[.!?][ ]?"))) {
		if (sentence.length) {
			len ~= sentence.length + 2;
		} else {
			len[$-1]--;
		}
	}
	len ~= 0;

	auto cnt = 1;
	for (int i = 0; i < len.length - 1; i++) {
		if (len[i] > n) {
			cnt = 0;
			break;
		}
		if (len[i] + len[i+1] > n) cnt++;
		else len[i+1] += len[i];
	}

	if (cnt) writeln(cnt);
	else writeln("Impossible");
}


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

T readNum(T)(){
  return readStr.to!T;
}

T[] readNums(T)(){
  return readStr.split.to!(T[]);
}

string readStr(){
  return readln.chomp;
}

void main(){
  auto i = readNums!ulong;
  auto x = i[0];
  auto y = i[1];
  auto z = i[2];

  auto buy = (x / z) + (y / z);

  x %= z;
  y %= z;

  ulong give;
  if(x + y >= z){
    give = min(z - x, z - y);
    buy += (x + y) / z;
  }

  writeln(buy, " ", give);
}

import std.stdio : writef, readf, readln, writeln, writefln;
import std.array : array, split;
import std.algorithm : sort, each, maxElement, minElement;
import std.conv : to;
import std.range : iota, tee, enumerate;
import std.algorithm.comparison : equal, max, min;
import std.container.rbtree : RBT = RedBlackTree;
import std.string : strip;
import core.memory : GC;
import std.typecons : tuple;
import std.math;

alias Tree = RBT!int;
alias ll = long;

void main() {
  GC.disable();

  long x, y, z;
  readf(" %s %s %s", x, y, z);

  long tt = 0;
  tt += x / z;
  tt += y / z;
  long rx = x % z;
  long ry = y % z;
  long ex = 0;

  if (rx + ry >= z) {
    ex = z - max(rx, ry);
    tt++;
  }

  writef("%s %s\n", tt, ex);
}

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

T readNum(T)(){
  return readStr.to!T;
}

T[] readNums(T)(){
  return readStr.split.to!(T[]);
}

string readStr(){
  return readln.chomp;
}

void main(){
  int[] i = readNums!int;
  int x = i[0];
  int y = i[1];
  int z = i[2];

  int buy = (x + y) / z;

  x %= z;
  y %= z;

  int give;
  if(x + y >= z) give = min(x, y);

  writeln(buy, " ", give);
}

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

T readNum(T)(){
  return readStr.to!T;
}

T[] readNums(T)(){
  return readStr.split.to!(T[]);
}

string readStr(){
  return readln.chomp;
}

void main(){
  int[] i = readNums!int;
  int x = i[0];
  int y = i[1];
  int z = i[2];

  int buy = (x / z) + (y / z);

  x %= z;
  y %= z;

  int give;
  if(x + y >= z){
    give = min(x, y);
    buy += (x + y) / z;
  }

  writeln(buy, " ", give);
}


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:

auto getAddrTuple() {
    return tuple();
}

auto getAddrTuple(T, U...)(ref T head, ref U tail) {
    return tuple(&head, getAddrTuple(tail).expand);
}

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

T[ ] allocate(T)(size_t n) {
    return (cast(T*)malloc(n * T.sizeof))[0 .. n];
}

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

char[100_001] _a, _b;
bool[100_000] used;

void main() {
    while (true) {
        version (LocalProject)
            memset(used.ptr, 0x00, used.sizeof);
        auto a = _a[ ];
        auto b = _b[ ];
        readln(a);
        if (a.empty)
            break;
        readln(b);
        a = a[0 .. $ - 1];
        b = b[0 .. $ - 1];
        const n = cast(int)a.length;
        const m = cast(int)b.length;
        //b[0 .. lb] ~ b[rb .. m]
        int la = 0, lb = 0, ra = n, rb = m;
        while (la < n && lb < m) {
            while (la < n && a[la] != b[lb])
                la++;
            if (la == n)
                break;
            used[la] = true;
            debug writeln("Left-using ", la);
            la++;
            lb++;
        }
        int lres = lb, rres = m;
        while (ra && rb) {
            ra--;
            rb--;
            int passed = 0;
            while (ra >= 0 && a[ra] != b[rb])
                if (used[ra--])
                    passed++;
            if (ra < 0)
                break;
            if (used[ra])
                passed++;
            debug writeln("Right-using ", ra);
            while (passed-- > 0 || lb > rb) {
                lb--;
                if (lb) {
                    while (a[--la] != b[lb]) { }
                    do
                        used[la--] = false;
                    while (a[la] != b[lb - 1]);
                    la++;
                } else
                    la = 0;
            }
            if (lb + m - rb > lres + m - rres) {
                lres = lb;
                rres = rb;
            }
        }
        if (!lres && rres == m)
            writeln('-');
        else
            writeln(b[0 .. lres], b[rres .. m]);
    }
}

module main;
import std.bigint,std.container,std.array,std.algorithm,std.conv,
	std.functional,std.math,std.numeric,std.string,std.range,std.complex,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.variant,
	std.stdio,std.bitmanip;
import core.stdc.stdio : freopen;
alias BitArray bitset;
alias RedBlackTree Rbt;
alias redBlackTree rbt;
alias BigInt big;
alias pair!(int,int) pii;
alias pair!(long,long) pll;
alias boyerMooreFinder strfind;
alias make_pair mp;
alias binary_search bins;
alias pair(X,Y)=Tuple!(X,q{fi},Y,q{se});
pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_)
{
	pair!(X,Y) pp;
	pp.fi=x_;
	pp.se=y_;
	return pp;
}
immutable int mod=10^^9+7;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b)
	{
		return a/gcd(a,b)*b;
	}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	size_t lowb(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (!(a[l]<g))?l:r;
	}
	size_t upb(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(g<a[m])r=m;
			else l=m;
		}
		return (g<a[l])?l:r;
	}
	size_t binf(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (g==a[l])?l:a.length;
	}
	bool binary_search(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		return binf(a,g)!=a.length;
	}
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a,in size_t n,in size_t m)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n)
{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length), ptrs)==ptrs.length;}
bool read(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length)~'\n', ptrs)==ptrs.length;}
nothrow void inf(in char* name) {freopen(name,"r",core.stdc.stdio.stdin);}
nothrow void ouf(in char* name) {freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold schwartzSort multiSort partialSort heapify join filter countUntil
//---------------------------------------------------------------program beginning-----------------------------------------------------------------

void main()
{
	string a,b;
	loop:while((a=readln.strip)!="")
	{
		b=readln.strip;
		int[] p,s;
		s.length=p.length=b.length;
		p[]=int.max/4;
		s[]=int.min/4;
		int pos=0;
		for(int i=0;i<b.length && pos<a.length;i++)
		{
			while(pos<a.length && a[pos]!=b[i])pos++;
			if(pos==a.length)break;
			p[i]=pos++;
		}
		pos=a.length-1;
		for(int i=b.length-1;i>=0 && pos>=0;i--)
		{
			while(pos>=0 && a[pos]!=b[i])pos--;
			if(pos<0)break;
			s[i]=pos--;
		}
		debug writeln(p);
		debug writeln(s);
		int ans=p.countUntil!"a==int.max/4",p1=ans,p2=b.length;
		foreach_reverse(i;0..b.length)
		{
			if(s[i]==int.min/4)break;
			int h=lowb(p,s[i]);
			int l=b.length-i;
			l+=h;
			if(l>ans)
			{
				ans=l;
				p1=h;
				p2=i;
			}
		}
		debug writeln(ans);
		debug writeln(p1,' ',p2);
		if(ans==0)writeln('-');
		else if(ans>=b.length)writeln(b);
		else writeln(b[0..p1],b[p2..$]);
	}

}

module main;
import std.bigint,std.container,std.array,std.algorithm,std.conv,
	std.functional,std.math,std.numeric,std.string,std.range,std.complex,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.variant,
	std.stdio,std.bitmanip;
import core.stdc.stdio : freopen;
alias BitArray bitset;
alias RedBlackTree Rbt;
alias redBlackTree rbt;
alias BigInt big;
alias pair!(int,int) pii;
alias pair!(long,long) pll;
alias boyerMooreFinder strfind;
alias make_pair mp;
alias binary_search bins;
alias pair(X,Y)=Tuple!(X,q{fi},Y,q{se});
pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_)
{
	pair!(X,Y) pp;
	pp.fi=x_;
	pp.se=y_;
	return pp;
}
immutable int mod=10^^9+7;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b)
	{
		return a/gcd(a,b)*b;
	}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	size_t lowb(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (!(a[l]<g))?l:r;
	}
	size_t upb(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(g<a[m])r=m;
			else l=m;
		}
		return (g<a[l])?l:r;
	}
	size_t binf(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (g==a[l])?l:a.length;
	}
	bool binary_search(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		return binf(a,g)!=a.length;
	}
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a,in size_t n,in size_t m)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n)
{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length), ptrs)==ptrs.length;}
bool read(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length)~'\n', ptrs)==ptrs.length;}
nothrow void inf(in char* name) {freopen(name,"r",core.stdc.stdio.stdin);}
nothrow void ouf(in char* name) {freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold schwartzSort multiSort partialSort heapify join filter countUntil
//---------------------------------------------------------------program beginning-----------------------------------------------------------------

void main()
{
	string a,b;
	loop:while((a=readln.strip)!="")
	{
		b=readln.strip;
		int[] p,s;
		s.length=p.length=b.length;
		p[]=int.max/4;
		s[]=int.min/4;
		int pos=0;
		for(int i=0;i<b.length && pos<a.length;i++)
		{
			while(pos<a.length && a[pos]!=b[i])pos++;
			if(pos==a.length)break;
			p[i]=pos++;
		}
		pos=a.length-1;
		for(int i=b.length-1;i>=0 && pos>=0;i--)
		{
			while(pos>=0 && a[pos]!=b[i])pos--;
			if(pos<0)break;
			s[i]=pos--;
		}
		debug writeln(p);
		debug writeln(s);
		int ans=p.countUntil!"a==int.max/4",p1=ans-1,p2=b.length;
		foreach_reverse(i;0..b.length)
		{
			if(s[i]==int.min/4)break;
			int h=lowb(p,s[i]);
			int l=b.length-i;
			l+=max(h-1,0);
			if(l>ans)
			{
				ans=l;
				p1=max(0,h-1);
				p2=i;
			}
		}
		debug writeln(ans);
		debug writeln(p1,' ',p2);
		if(ans==0)writeln('-');
		else writeln(b[0..p1+1],b[p2..$]);
	}

}

module main;
import std.bigint,std.container,std.array,std.algorithm,std.conv,
	std.functional,std.math,std.numeric,std.string,std.range,std.complex,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.variant,
	std.stdio,std.bitmanip;
import core.stdc.stdio : freopen;
alias BitArray bitset;
alias RedBlackTree Rbt;
alias redBlackTree rbt;
alias BigInt big;
alias pair!(int,int) pii;
alias pair!(long,long) pll;
alias boyerMooreFinder strfind;
alias make_pair mp;
alias binary_search bins;
alias pair(X,Y)=Tuple!(X,q{fi},Y,q{se});
pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_)
{
	pair!(X,Y) pp;
	pp.fi=x_;
	pp.se=y_;
	return pp;
}
immutable int mod=10^^9+7;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b)
	{
		return a/gcd(a,b)*b;
	}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	size_t lowb(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (!(a[l]<g))?l:r;
	}
	size_t upb(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(g<a[m])r=m;
			else l=m;
		}
		return (g<a[l])?l:r;
	}
	size_t binf(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (g==a[l])?l:a.length;
	}
	bool binary_search(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		return binf(a,g)!=a.length;
	}
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a,in size_t n,in size_t m)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n)
{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length), ptrs)==ptrs.length;}
bool read(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length)~'\n', ptrs)==ptrs.length;}
nothrow void inf(in char* name) {freopen(name,"r",core.stdc.stdio.stdin);}
nothrow void ouf(in char* name) {freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold schwartzSort multiSort partialSort heapify join filter countUntil
//---------------------------------------------------------------program beginning-----------------------------------------------------------------

void main()
{
	string a,b;
	loop:while((a=readln.strip)!="")
	{
		b=readln.strip;
		int[] p,s;
		s.length=p.length=b.length;
		p[]=int.max/4;
		s[]=int.min/4;
		int pos=0;
		for(int i=0;i<b.length && pos<a.length;i++)
		{
			while(pos<a.length && a[pos]!=b[i])pos++;
			if(pos==a.length)break;
			p[i]=pos++;
		}
		pos=a.length-1;
		for(int i=b.length-1;i>=0 && pos>=0;i--)
		{
			while(pos>=0 && a[pos]!=b[i])pos--;
			if(pos<0)break;
			s[i]=pos--;
		}
		debug writeln(p);
		debug writeln(s);
		int ans=p.countUntil!"a==int.max/4",p1=ans-1,p2=b.length;
		foreach_reverse(i;0..b.length)
		{
			if(s[i]==int.min/4)break;
			int h=lowb(p,s[i]);
			int l=b.length-i;
			l+=max(h-1,0);
			if(l>ans)
			{
				ans=l;
				p1=h-1;
				p2=i;
			}
		}
		debug writeln(ans);
		debug writeln(p1,' ',p2);
		if(ans==0)writeln('-');
		else writeln(b[0..p1+1],b[p2..$]);
	}

}

module main;
import std.bigint,std.container,std.array,std.algorithm,std.conv,
	std.functional,std.math,std.numeric,std.string,std.range,std.complex,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.variant,
	std.stdio,std.bitmanip;
import core.stdc.stdio : freopen;
alias BitArray bitset;
alias RedBlackTree Rbt;
alias redBlackTree rbt;
alias BigInt big;
alias pair!(int,int) pii;
alias pair!(long,long) pll;
alias boyerMooreFinder strfind;
alias make_pair mp;
alias binary_search bins;
alias pair(X,Y)=Tuple!(X,q{fi},Y,q{se});
pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_)
{
	pair!(X,Y) pp;
	pp.fi=x_;
	pp.se=y_;
	return pp;
}
immutable int mod=10^^9+7;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b)
	{
		return a/gcd(a,b)*b;
	}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	size_t lowb(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (!(a[l]<g))?l:r;
	}
	size_t upb(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(g<a[m])r=m;
			else l=m;
		}
		return (g<a[l])?l:r;
	}
	size_t binf(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (g==a[l])?l:a.length;
	}
	bool binary_search(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		return binf(a,g)!=a.length;
	}
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a,in size_t n,in size_t m)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n)
{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length), ptrs)==ptrs.length;}
bool read(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length)~'\n', ptrs)==ptrs.length;}
nothrow void inf(in char* name) {freopen(name,"r",core.stdc.stdio.stdin);}
nothrow void ouf(in char* name) {freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold schwartzSort multiSort partialSort heapify join filter countUntil
//---------------------------------------------------------------program beginning-----------------------------------------------------------------

void main()
{
	string a,b;
	loop:while((a=readln.strip)!="")
	{
		b=readln.strip;
		int[] p,s;
		s.length=p.length=b.length;
		p[]=int.max/4;
		s[]=int.min/4;
		int pos=0;
		for(int i=0;i<b.length && pos<a.length;i++)
		{
			while(pos<a.length && a[pos]!=b[i])pos++;
			if(pos==a.length)break;
			p[i]=pos++;
		}
		pos=a.length-1;
		for(int i=b.length-1;i>=0 && pos>=0;i--)
		{
			while(pos>=0 && a[pos]!=b[i])pos--;
			if(pos<0)break;
			s[i]=pos--;
		}
		debug writeln(p);
		debug writeln(s);
		int ans=p.countUntil!"a==int.max/4",p1=ans-1,p2=b.length;
		foreach_reverse(i;0..b.length)
		{
			if(s[i]==int.min/4)break;
			int h=lowb(p,s[i]);
			int l=b.length-i;
			l+=max(h-1,0);
			if(l>ans)
			{
				ans=l;
				p1=h-1;
				p2=i;
			}
		}
		debug writeln(ans);
		debug writeln(p1,' ',p2);
		if(ans==0)writeln('-');
		else if(ans>=b.length)writeln(b);
		else writeln(b[0..p1+1],b[p2..$]);
	}

}


void main() { runSolver(); }

void problem() {
  auto QN = 1;

  auto solve() {
    auto subSolve() {
      auto N = scan!int;
      auto Q = scan!int;
      auto A = scan!long(N);

      long ans = A.sum;

      alias QV = Tuple!(int, "qi", long, "v");
      auto arr = new QV[](N + 1);
      foreach(i; 0..N) arr[i].v = A[i];

      foreach(qi; 1..Q + 1) {
        auto q = scan!int;
        if (q == 1) {
          auto i = scan!int - 1;
          auto v = scan!long;
          auto currentValue = arr[i].qi >= arr[N].qi ? arr[i].v : arr[N].v;
          ans += v - currentValue;
          arr[i] = QV(qi, v);
        } else {
          auto v = scan!long;
          ans = v * N;
          arr[N] = QV(qi, v);
        }

        ans.writeln;
      }
    }

    foreach(i; 0..QN) {
      subSolve();
    }
  }

  outputForAtCoder(&solve);
}

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

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;
T[][] combinations(T)(T[] s, in long m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
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)(long n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");
Point invert(Point p) { return Point(p.y, p.x); }
long[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }
bool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }
bool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }
string charSort(alias S = "a < b")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }
ulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}
T[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }
string toAnswerString(R)(R r) { return r.map!"a.to!string".joiner(" ").array.to!string; }
struct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:"+")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:"-")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:"*")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:"^^", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:"/")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin ("this=this"~op~"r");}}
alias MInt1 = ModInt!(10^^9 + 7);
alias MInt9 = ModInt!(998_244_353);
void outputForAtCoder(T)(T delegate() fn) {
  static if (is(T == float) || is(T == double) || is(T == real)) "%.16f".writefln(fn());
  else static if (is(T == void)) fn();
  else static if (is(T == string)) fn().writeln;
  else static if (isInputRange!T) {
    static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;
    else foreach(r; fn()) r.writeln;
  }
  else fn().writeln;
}
void runSolver() {
  enum BORDER = "==================================";
  debug { BORDER.writeln; while(!stdin.eof) { "<<< Process time: %s >>>".writefln(benchmark!problem(1)); BORDER.writeln; } }
  else problem();
}
enum YESNO = [true: "Yes", false: "No"];

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

import std;

void main()
{
    int n, q;
    scanf("%d %d", &n, &q);
    getchar();
    long[] arr = readln.split.to!(long[]);
    long sum = arr.sum;
    long[long] xch;
    long def_value;
    bool not_rewrited = true;
    outer: foreach(_; 0..q)
    {
        long[] query = readln.split.to!(long[]);
        if (query[0] == 1) {
            if (not_rewrited)
                sum += query[2] - xch.get(query[1], arr[cast(size_t)query[1] - 1]);
            else
                sum += query[2] - xch.get(query[1], def_value);
            xch[query[1]] = query[2];
        }
        else {
            not_rewrited = false;
            sum = n * query[1];
            def_value = query[1];
            xch.clear;
        }
        writeln(sum);
    }
}

void main() { runSolver(); }

void problem() {
  auto QN = 1;

  auto solve() {
    auto subSolve() {
      auto N = scan!int;
      auto Q = scan!int;
      auto A = scan!long(N);

      long ans = A.sum;

      alias QV = Tuple!(int, "qi", long, "v");
      auto arr = new QV[](N + 1);
      foreach(i; 0..N) arr[i].v = A[i];

      foreach(qi; 0..Q) {
        auto q = scan!int;
        if (q == 1) {
          auto i = scan!int - 1;
          auto v = scan!long;
          auto currentValue = arr[i].qi >= arr[N].qi ? arr[i].v : arr[N].v;
          ans += v - currentValue;
          arr[i] = QV(qi, v);
        } else {
          auto v = scan!long;
          ans = v * N;
          arr[N] = QV(qi, v);
        }

        ans.writeln;
      }
    }

    foreach(i; 0..QN) {
      subSolve();
    }
  }

  outputForAtCoder(&solve);
}

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

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;
T[][] combinations(T)(T[] s, in long m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
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)(long n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");
Point invert(Point p) { return Point(p.y, p.x); }
long[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }
bool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }
bool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }
string charSort(alias S = "a < b")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }
ulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}
T[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }
string toAnswerString(R)(R r) { return r.map!"a.to!string".joiner(" ").array.to!string; }
struct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:"+")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:"-")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:"*")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:"^^", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:"/")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin ("this=this"~op~"r");}}
alias MInt1 = ModInt!(10^^9 + 7);
alias MInt9 = ModInt!(998_244_353);
void outputForAtCoder(T)(T delegate() fn) {
  static if (is(T == float) || is(T == double) || is(T == real)) "%.16f".writefln(fn());
  else static if (is(T == void)) fn();
  else static if (is(T == string)) fn().writeln;
  else static if (isInputRange!T) {
    static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;
    else foreach(r; fn()) r.writeln;
  }
  else fn().writeln;
}
void runSolver() {
  enum BORDER = "==================================";
  debug { BORDER.writeln; while(!stdin.eof) { "<<< Process time: %s >>>".writefln(benchmark!problem(1)); BORDER.writeln; } }
  else problem();
}
enum YESNO = [true: "Yes", false: "No"];

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