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

immutable int letters = 26;

void main ()
{
	readln;
	int n, k;
	while (readf !(" %s %s") (n, k) > 0)
	{
		readln;
		auto s = readln.strip;
		auto d = new int [letters];
		foreach (char c; s)
		{
			d[c - 'a'] += 1;
		}
                int lo = 0;
                int let = 0;
                foreach (i; 0..k)
                {
			while (d[let] == 0)
			{
				let += 1;
				lo = i;
			}
			d[let] -= 1;
			n -= 1;
                }

		string res = "" ~ cast (char) (let + 'a');
		if (lo == 0)
		{
			while (d[let] == 0)
			{
				let += 1;
			}
			if (d[let] == n)
			{
				foreach (z; 0..(d[let] + k - 1) / k)
				{
					res ~= cast (char) (let + 'a');
				}
			}
			else
			{
				foreach (cur; 0..letters)
				{
					foreach (z; 0..d[cur])
					{
						res ~= cast (char) (cur + 'a');
					}
				}
	        	}
		}
		writeln (res);
	}
}

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

void main()
{
    auto T = readln.chomp.to!int;
    foreach (_t; 0..T) {
        auto nk = readln.split.to!(int[]);
        auto N = nk[0];
        auto K = nk[1];

        auto SS = readln.chomp.to!(dchar[]);
        sort(SS);
        auto S = SS.to!(char[]);

        char[] a;
        if (N == 1) {
            a = S;
        } else if (S[0] != S[K-1]) {
            a = [S[K-1]];
        } else if (S[0] == S[$-1]) {
            foreach (_c; 0..(S.length.to!int+K-1)/K) a ~= S[0];
        } else if (S[K] == S[$-1]) {
            auto n = S.length.to!int-K;
            a ~= S[0];
            foreach (_c; 0..(n+K-1)/K) a ~= S[K];
        } else {
            a = [S[0]] ~ S[K..$];
        }
        writeln(a);
    }
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		auto a = new int[](n);
		foreach (i; 0..n)
			a[i] = s[i] - 'a';
		a.sort();

		{
			auto cnt = new int[](26);
			foreach (i; 0..n)
			{
				++cnt[a[i]];
			}

			int c, cc;
			foreach (i; 0..26)
			{
				if (cnt[i] != 0)
				{
					++c;
					if (cc == 0)
						cc = cnt[i];
				}
			}
			debug writeln("c:", c);
			if (c == 1)
			{
				foreach (i; 0..(n+k-1)/k)
				{
					ans[ti] ~= cast(char)('a'+a[i*k]);
				}
				continue;
			}
			else if (c == 2 && cc == k)
			{
				foreach (i; 0..(n+k-1)/k)
				{
					ans[ti] ~= cast(char)('a'+a[i*k]);
				}
				continue;
			}
		}
		{
			auto cnt = new int[](26);
			foreach (i; 0..k)
			{
				++cnt[a[i]];
			}
			int p;
			foreach_reverse (i; 0..26)
			{
				if (cnt[i] == 0) continue;
				p = i;
				break;
			}
			ans[ti] ~= cast(char)('a'+p);
			if (cnt[p] != k) continue;
		}
		debug writeln("ans:", ans[ti]);
		foreach (i; k..n)
			ans[ti] ~= cast(char)('a'+a[i]);
	}

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

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

string FMT_F = "%.10f";

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

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

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

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

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

		auto a = new int[](n);
		foreach (i; 0..n)
			a[i] = s[i] - 'a';
		a.sort();

		int l;
		while (l < n)
		{
			auto cnt = new int[](26);
			foreach (i; l..min(l+k, n))
			{
				++cnt[a[i]];
			}
			int p, p2;
			foreach_reverse (i; 0..26)
			{
				if (cnt[i] == 0) continue;
				p = i;
				break;
			}
			foreach (i; 0..26)
			{
				if (cnt[i] == 0) continue;
				p2 = i;
				break;
			}
			debug writeln(cnt);

			auto c = cast(char)('a'+p);
			if (k != cnt[p] || l+k >= n)
			{
				ans[ti] ~= c;
				break;
			}
			else
			{
				if (l == 0)
					ans[ti] ~= c;
				else
				{
					foreach (i; 0..cnt[p2])
						ans[ti] ~= c;
				}
			}
			l += k;
		}
	}

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

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

void main()
{
    auto T = readln.chomp.to!int;
    foreach (_t; 0..T) {
        auto nk = readln.split.to!(int[]);
        auto N = nk[0];
        auto K = nk[1];

        auto SS = readln.chomp.to!(dchar[]);
        sort(SS);
        auto S = SS.to!(char[]);

        char[] a;
        if (N == 1) {
            a = S;
        } else if (S[0] != S[K-1]) {
            a = [S[K-1]];
            continue;
        } else if (S[0] == S[$-1]) {
            foreach (_c; 0..(S.length.to!int+K-1)/K) a ~= S[0];
        } else if (S[K] == S[$-1]) {
            auto n = S.length.to!int-K;
            a ~= S[0];
            foreach (_c; 0..(n+K-1)/K) a ~= S[K];
        } else {
            a = [S[0]] ~ S[K..$];
        }
        writeln(a);
    }
}

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

void main()
{
    auto T = readln.chomp.to!int;
    foreach (_t; 0..T) {
        auto nk = readln.split.to!(int[]);
        auto N = nk[0];
        auto K = nk[1];

        auto SS = readln.chomp.to!(dchar[]);
        sort(SS);
        auto S = SS.to!(char[]);

        char[] a;
        if (N == 1) {
            writeln(S);
            continue;
        } else if (S[0] != S[K-1]) {
            writeln(S[K-1]);
            continue;
        } else if (S[0] == S[$-1]) {
            foreach (_c; 0..(S.length.to!int+K-1)/K) a ~= S[0];
            writeln(a);
            continue;
        }

        int[26] cs;
        foreach (c; S) ++cs[c-'a'];
        bool b;
        foreach (c; cs) if (c%K != 0) b = true;
        if (b) {
            if (S[K] == S[$-1]) {
                auto n = S.length.to!int-K;
                a ~= S[0];
                foreach (_c; 0..(n+K-1)/K) a ~= S[K];
            } else {
                a = [S[0]] ~ S[K..$];
            }
        } else {
            foreach (i, c; cs) foreach (_c; 0..c/K) a ~= i.to!char+'a';
        }
        writeln(a);
    }
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		auto a = new int[](n);
		foreach (i; 0..n)
			a[i] = s[i] - 'a';
		a.sort();

		int l;
		while (l < n)
		{
			auto cnt = new int[](26);
			foreach (i; l..min(l+k, n))
			{
				++cnt[a[i]];
			}
			int p;
			foreach_reverse (i; 0..26)
			{
				if (cnt[i] == 0) continue;
				p = i;
				break;
			}
			debug writeln(cnt);

			auto c = cast(char)('a'+p);
			if (k != cnt[p] || l+k >= n)
			{
				ans[ti] ~= c;
				break;
			}
			else
			{
				if (l == 0)
					ans[ti] ~= c;
				else
				{
					foreach (i; 0..cnt[p])
						ans[ti] ~= c;
				}
			}
			l += k;
		}
	}

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

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

string FMT_F = "%.10f";

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

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

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

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

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

		auto a = new int[](n);
		foreach (i; 0..n)
			a[i] = s[i] - 'a';
		a.sort();

		{
			auto cnt = new int[](26);
			foreach (i; 0..n)
			{
				++cnt[a[i]];
			}

			int c;
			foreach (i; 0..26)
			{
				if (cnt[i] != 0)
					++c;
			}
			bool ok = true;
			if (c != 1)
			{
				foreach (i; 0..26)
				{
					if (cnt[i] % k)
						ok = false;
				}
			}
			if (ok)
			{
				foreach (i; 0..(n+k-1)/k)
				{
					ans[ti] ~= cast(char)('a'+a[i*k]);
				}
				continue;
			}
		}

		{
			auto cnt = new int[](26);
			foreach (i; 0..k)
			{
				++cnt[a[i]];
			}
			int p;
			foreach_reverse (i; 0..26)
			{
				if (cnt[i] == 0) continue;
				p = i;
				break;
			}
			ans[ti] ~= cast(char)('a'+p);
			if (cnt[p] != k) continue;
		}
		foreach (i; k..n)
			ans[ti] ~= cast(char)('a'+a[i]);
	}

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

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

string FMT_F = "%.10f";

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

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

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

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

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

		auto a = new int[](n);
		foreach (i; 0..n)
			a[i] = s[i] - 'a';
		a.sort();

		if (k == 1)
		{
			foreach (i; 0..n)
			{
				ans[ti] ~= cast(char)('a'+a[i]);
			}
			continue;
		}

		{
			auto cnt = new int[](26);
			foreach (i; 0..k)
			{
				++cnt[a[i]];
			}
			int p;
			foreach_reverse (i; 0..26)
			{
				if (cnt[i] == 0) continue;
				p = i;
				break;
			}
			ans[ti] ~= cast(char)('a'+p);
			if (cnt[p] != k) continue;
		}
		int l = k;
		while (l < n)
		{
			if (l+k < n)
			{
				foreach (i; l..min(l+k, n))
				{
					ans[ti] ~= cast(char)('a'+a[i]);
				}
				l += k;
				continue;
			}

			auto cnt = new int[](26);
			foreach (i; l..min(l+k, n))
			{
				++cnt[a[i]];
			}
			int p;
			foreach (i; 0..26)
			{
				if (cnt[i] == 0) continue;
				p = i;
				break;
			}
			debug writeln(cnt);

			if (cnt[p] == min(k, n-l) && l+k >= n)
			{
				ans[ti] ~= cast(char)('a'+p);
				break;
			}
			l += k;
		}
	}

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

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

string FMT_F = "%.10f";

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

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

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

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

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

		auto a = new int[](n);
		foreach (i; 0..n)
			a[i] = s[i] - 'a';
		a.sort();

		{
			auto cnt = new int[](26);
			foreach (i; 0..n)
			{
				++cnt[a[i]];
			}

			int c;
			foreach (i; 0..26)
			{
				if (cnt[i] != 0)
					++c;
			}
			debug writeln("c:", c);
			if (c <= 2)
			{
				foreach (i; 0..(n+k-1)/k)
				{
					ans[ti] ~= cast(char)('a'+a[i*k]);
				}
				continue;
			}
		}
		{
			auto cnt = new int[](26);
			foreach (i; 0..k)
			{
				++cnt[a[i]];
			}
			int p;
			foreach_reverse (i; 0..26)
			{
				if (cnt[i] == 0) continue;
				p = i;
				break;
			}
			ans[ti] ~= cast(char)('a'+p);
			if (cnt[p] != k) continue;
		}
		debug writeln("ans:", ans[ti]);
		foreach (i; k..n)
			ans[ti] ~= cast(char)('a'+a[i]);
	}

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

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

string FMT_F = "%.10f";

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

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

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

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

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

		auto a = new int[](n);
		foreach (i; 0..n)
			a[i] = s[i] - 'a';
		a.sort();

		{
			auto cnt = new int[](26);
			foreach (i; 0..n)
			{
				++cnt[a[i]];
			}
			bool ok = true;
			foreach (i; 0..26)
			{
				if (cnt[i] % k)
					ok = false;
			}
			if (ok)
			{
				foreach (i; 0..n/k)
				{
					ans[ti] ~= cast(char)('a'+a[i*k]);
				}
				continue;
			}
		}

		{
			auto cnt = new int[](26);
			foreach (i; 0..k)
			{
				++cnt[a[i]];
			}
			int p;
			foreach_reverse (i; 0..26)
			{
				if (cnt[i] == 0) continue;
				p = i;
				break;
			}
			ans[ti] ~= cast(char)('a'+p);
			if (cnt[p] != k) continue;
		}
		int l = k;
		while (l < n)
		{
			if (l+k < n)
			{
				foreach (i; l..min(l+k, n))
				{
					ans[ti] ~= cast(char)('a'+a[i]);
				}
				l += k;
				continue;
			}

			auto cnt = new int[](26);
			foreach (i; l..min(l+k, n))
			{
				++cnt[a[i]];
			}
			int p;
			foreach (i; 0..26)
			{
				if (cnt[i] == 0) continue;
				p = i;
				break;
			}
			debug writeln(cnt);

			if (cnt[p] == min(k, n-l) && l+k >= n)
			{
				ans[ti] ~= cast(char)('a'+p);
				break;
			}
			l += k;
		}
	}

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


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

struct XD
{
    int a;
    int b;
    int opCmp(ref const XD xd) const
    {
        if (a - b > xd.a - xd.b) return 1;
        if (a - b < xd.a - xd.b) return -1;
        return 0;
    }
}

void solve(XD[] xds, int n, int k)
{
    sort(xds);
    auto bs = new int[n];
    bs[n - 1] = xds[n - 1].b;
    for (int i = n - 2; i >= 0; -- i)
    {
        bs[i] = bs[i + 1] + xds[i].b;
    }
    auto ans = int.max;
    auto sum = 0;
    foreach (i; 0 .. k)
    {
        sum += xds[i].a;
    }
    for (int i = k; i < n; ++ i)
    {
        ans = min(ans, sum + bs[i]);
        sum += xds[i].a;
    }
    ans = min(ans, sum);
    writeln(ans);
}

int main(string[] args)
{
    int n, k;
    while (readf("%d %d\n", &n, &k) == 2)
    {
        auto xds = new XD[n];
        foreach (i; 0 .. n)
        {
            readf(" %d", &xds[i].a);
        }
        readln;
        foreach (i; 0 .. n)
        {
            readf(" %d", &xds[i].b);
        }
        readln;
        solve(xds, n, k);
    }
    return 0;
}

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

alias Tuple!(int, "diff", int, "i") Prod;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto K = s[1];
    auto A = readln.split.map!(to!int).array;
    auto B = readln.split.map!(to!int).array;

    auto P = new Prod[](N);
    foreach (i; 0..N) {
        P[i] = Prod(A[i]-B[i], i);
    }
    P.sort!"a.diff < b.diff"();

    long ans = 0;
    foreach (i, p; enumerate(P)) {
        if (i < K) ans += A[p.i];
        else if (p.diff <= 0) ans += A[p.i];
        else ans += B[p.i];
    }

    ans.writeln;
}

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

struct XD
{
    int a;
    int b;
    int opCmp(ref const XD xd) const
    {
        if (a - b > xd.a - xd.b) return 1;
        if (a - b < xd.a - xd.b) return -1;
        return 0;
    }
}

void solve(XD[] xds, int n, int k)
{
    sort(xds);
    auto ans = 0;
    foreach (i; 0 .. k)
    {
        ans += xds[i].a;
    }
    int i;
    for (i = k; i < n && xds[i].a < xds[i].b; ++ i)
    {
        ans += xds[i].a;
    }
    for (; i < n; ++ i)
    {
        ans += xds[i].b;
    }
    writeln(ans);
}

int main(string[] args)
{
    int n, k;
    while (readf("%d %d\n", &n, &k) == 2)
    {
        auto xds = new XD[n];
        foreach (i; 0 .. n)
        {
            readf(" %d", &xds[i].a);
        }
        readln;
        foreach (i; 0 .. n)
        {
            readf(" %d", &xds[i].b);
        }
        readln;
        solve(xds, n, k);
    }
    return 0;
}


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

long[5000] a;
long[5000] b;
long[][] dp;
long nonrev;

long solve(int first, int last)
{
  if (last - first >= 2) {
    long result = ((dp[first + 1][last - 1] != 0) ? (dp[first + 1][last - 1]) : solve(first + 1, last - 1)) -
                    a[first] * b[first] - a[last] * b[last] +
                    a[first] * b[last] + a[last] * b[first];
    dp[first][last] = result;
    return result;
  } else if (last - first == 1) {
    long result = nonrev -
                  a[first] * b[first] - a[last] * b[last] +
                  a[first] * b[last] + a[last] * b[first];
    dp[first][last] = result;
    return result;
  } else {
    dp[first][last] = nonrev;
    return nonrev;
  }
}

void main()
{
  int n, i, j, first, last;

  dp = new long[][](5000, 5000);

  readf!(" %d")(n);
  for (i = 0; i < n; i++)
    readf!(" %d")(a[i]);
  for (i = 0; i < n; i++)
    readf!(" %d")(b[i]);

  nonrev = 0;
  for (i = 0; i < n; i++)
    nonrev += a[i] * b[i];

  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++)
      dp[i][j] = 0;

  long best = 0;
  for (first = 0; first < n; first++) {
    for (last = first; last < n; last++) {
      long result = solve(first, last);
      if (result > best) {
        best = result;
      }
    }
  }
  writeln(best);
}

import std;

long[5000] a;
long[5000] b;
long[][] dp;
long nonrev;

long solve(int first, int last)
{
  if (last - first >= 2) {
    long result = ((dp[first + 1][last - 1] != 0) ? (dp[first + 1][last - 1]) : solve(first + 1, last - 1)) -
                    a[first] * b[first] - a[last] * b[last] +
                    a[first] * b[last] + a[last] * b[first];
    dp[first][last] = result;
    return result;
  } else if (last - first == 1) {
    long result = nonrev -
                  a[first] * b[first] - a[last] * b[last] +
                  a[first] * b[last] + a[last] * b[first];
    dp[first][last] = result;
    return result;
  } else {
    dp[first][last] = nonrev;
    return nonrev;
  }
}

void main()
{
  int n, i, j, first, last;

  dp = new long[][](5000, 5000);

  readf!(" %d")(n);
  for (i = 0; i < n; i++)
    readf!(" %d")(a[i]);
  for (i = 0; i < n; i++)
    readf!(" %d")(b[i]);

  nonrev = 0;
  for (i = 0; i < n; i++)
    nonrev += a[i] * b[i];

  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++)
      dp[i][j] = 0;

  long best = 0;
  for (first = 0; first < n; first++) {
    for (last = first; last < n; last++) {
      long result = solve(first, last);
      if (result > best) {
        best = result;
      }
    }
  }
  writeln(best);
}

import std.stdio;

long[5000] a;
long[5000] b;
long[][] dp;
long nonrev;

long solve(int first, int last)
{
  if (dp[first][last] != 0)
    return dp[first][last];
  if (last - first >= 2) {
    long result = ((dp[first + 1][last - 1] != 0) ? (dp[first + 1][last - 1]) : solve(first + 1, last - 1)) -
                    a[first] * b[first] - a[last] * b[last] +
                    a[first] * b[last] + a[last] * b[first];
    dp[first][last] = result;
    return result;
  } else if (last - first == 1) {
    long result = nonrev -
                  a[first] * b[first] - a[last] * b[last] +
                  a[first] * b[last] + a[last] * b[first];
    dp[first][last] = result;
    return result;
  } else {
    dp[first][last] = nonrev;
    return nonrev;
  }
}

void main()
{
  int n, i, j, first, last;

  dp = new long[][](5000, 5000);

  readf!(" %d")(n);
  for (i = 0; i < n; i++)
    readf!(" %d")(a[i]);
  for (i = 0; i < n; i++)
    readf!(" %d")(b[i]);

  nonrev = 0;
  for (i = 0; i < n; i++)
    nonrev += a[i] * b[i];

  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++)
      dp[i][j] = 0;

  long best = 0;
  for (first = n - 1; first >= 0; first--) {
    for (last = first; last < n; last++) {
      long result = solve(first, last);
      if (result > best) {
        best = result;
      }
    }
  }
  writeln(best);
}

import std.stdio;

long[5000] a;
long[5000] b;
long[][] dp;
long nonrev;

long solve(int first, int last)
{
  if (dp[first][last] != 0)
    return dp[first][last];
  if (last - first >= 2) {
    long result = ((dp[first + 1][last - 1] != 0) ? (dp[first + 1][last - 1]) : solve(first + 1, last - 1)) -
                    a[first] * b[first] - a[last] * b[last] +
                    a[first] * b[last] + a[last] * b[first];
    dp[first][last] = result;
    return result;
  } else if (last - first == 1) {
    long result = nonrev -
                  a[first] * b[first] - a[last] * b[last] +
                  a[first] * b[last] + a[last] * b[first];
    dp[first][last] = result;
    return result;
  } else {
    dp[first][last] = nonrev;
    return nonrev;
  }
}

void main()
{
  int n, i, j, first, last;

  dp = new long[][](5000, 5000);

  readf!(" %d")(n);
  for (i = 0; i < n; i++)
    readf!(" %d")(a[i]);
  for (i = 0; i < n; i++)
    readf!(" %d")(b[i]);

  nonrev = 0;
  for (i = 0; i < n; i++)
    nonrev += a[i] * b[i];

  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++)
      dp[i][j] = 0;

  long best = 0;
  for (first = 0; first < n; first++) {
    for (last = first; last < n; last++) {
      long result = solve(first, last);
      if (result > best) {
        best = result;
      }
    }
  }
  writeln(best);
}

import std.stdio;

long[5000] a;
long[5000] b;
long[][] dp;
long nonrev;

long solve(int first, int last)
{
  if (last - first >= 2) {
    long result = ((dp[first + 1][last - 1] != 0) ? (dp[first + 1][last - 1]) : solve(first + 1, last - 1)) -
                    a[first] * b[first] - a[last] * b[last] +
                    a[first] * b[last] + a[last] * b[first];
    dp[first][last] = result;
    return result;
  } else if (last - first == 1) {
    long result = nonrev -
                  a[first] * b[first] - a[last] * b[last] +
                  a[first] * b[last] + a[last] * b[first];
    dp[first][last] = result;
    return result;
  } else {
    dp[first][last] = nonrev;
    return nonrev;
  }
}

void main()
{
  int n, i, j, first, last;

  dp = new long[][](5000, 5000);

  readf!(" %d")(n);
  for (i = 0; i < n; i++)
    readf!(" %d")(a[i]);
  for (i = 0; i < n; i++)
    readf!(" %d")(b[i]);

  nonrev = 0;
  for (i = 0; i < n; i++)
    nonrev += a[i] * b[i];

  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++)
      dp[i][j] = 0;

  long best = 0;
  for (first = 0; first < n; first++) {
    for (last = first; last < n; last++) {
      long result = solve(first, last);
      if (result > best) {
        best = result;
      }
    }
  }
  writeln(best);
}

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

string FMT_F = "%.10f";

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

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

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
double[] rotate(double[] vec, double rad) { return [cos(rad) * vec[0] - sin(rad) * vec[1], sin(rad) * vec[0] + cos(rad) * vec[1]]; }

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

void main()
{
	auto n = RD!int;
	auto a = RDA;
	auto b = RDA;

	auto c = new long[](n+1);
	foreach (i; 0..n)
	{
		c[i+1] = c[i] + a[i] * b[i];
	}

	long ans = c[n];
	foreach (m; 0..n-1)
	{
		auto l = m;
		auto r = m+1;
		long x;
		while (l >= 0 && r < n)
		{
			x += a[r] * b[l] + a[l] * b[r];
			long tmp = c[l] + c[n] - c[r+1] + x;
			ans.chmax(tmp);
			--l; ++ r;
		}
	}
	foreach (m; 1..n-1)
	{
		auto l = m-1;
		auto r = m+1;
		long x = a[m] * b[m];
		while (l >= 0 && r < n)
		{
			x += a[r] * b[l] + a[l] * b[r];
			long tmp = c[l] + c[n] - c[r+1] + x;
			ans.chmax(tmp);
			--l; ++r;
		}
	}

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

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

long solve(long[] a, long[] b)
{
    auto n = to!int(a.length);
    auto s = new long[n];
    s[0] = a[0] * b[0];
    foreach (i; 1 .. n) s[i] = s[i - 1] + a[i] * b[i];
    auto dp = new long[][](n, 3);
    foreach (i; 0 .. n) dp[i][1] = a[i] * b[i];
    long res = s[n - 1];
    foreach (i; 1 .. n)
    {
        foreach (j; 0 .. n - i)
        {
            dp[j][2] = dp[j + 1][0] + a[j] * b[j + i] + a[j + i] * b[j];
            long v = dp[j][2] + (s[n - 1] - s[j + i]);
            if (j > 0) v += s[j - 1];
            res = max(res, v);
        }
        foreach (j; 0 .. n)
        {
            dp[j][0] = dp[j][1];
            dp[j][1] = dp[j][2];
        }
    }
    return res;
}

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

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

long[] a;
long[] b;
long[][] dp;
long nonrev;

long solve(int first, int last)
{
  if (last - first >= 2) {
    long result = ((dp[first + 1][last - 1] != 0) ? (dp[first + 1][last - 1]) : solve(first + 1, last - 1)) -
                    a[first] * b[first] - a[last] * b[last] +
                    a[first] * b[last] + a[last] * b[first];
    dp[first][last] = result;
    return result;
  } else if (last - first == 1) {
    long result = nonrev -
                  a[first] * b[first] - a[last] * b[last] +
                  a[first] * b[last] + a[last] * b[first];
    dp[first][last] = result;
    return result;
  } else {
    dp[first][last] = nonrev;
    return nonrev;
  }
}

void main()
{
  int n, x, i, j, first, last;

  writeln(0);
  stdout.flush;
  return;

  readf!" %s "(n);
  dp = new long[][](n, n);
  a = new long[](n);
  b = new long[](n);

  for (i = 0; i < n; i++)
    readf!" %s "(a[i]);
  for (i = 0; i < n; i++)
    readf!" %s "(b[i]);

  nonrev = 0;
  for (i = 0; i < n; i++)
    nonrev += a[i] * b[i];

  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++)
      dp[i][j] = 0;

  long best = 0;
  for (first = 0; first < n; first++) {
    for (last = first; last < n; last++) {
      long result = solve(first, last);
      if (result > best) {
        best = result;
      }
    }
  }
  writeln(best);
  stdout.flush;
}


import std.stdio;
int main()
{
	int a=0;
	int b=0;
	readf(" %d", &a);
	readf(" %d", &b);
	bool[] m = new bool[b];
	for (int i=0; i<b; i++)
	{
		m[i]=false;
	}
	for (int i=0; i<a; i++)
	{
		int c=0;
		readf(" %d", &c);
		for (int j=0; j<c; j++)
		{
		    int d=0;
			readf(" %d", &d);
			m[d-1]=true;
		}
	}
	int count=0;
	for (int i=0; i<b; i++)
	{
		if (m[i]==false)
		{
			count=count+1;
		}
	}
	if (count==0)
	{
		writeln("YES");
	}
	else
	{
		writeln("NO");
	}
	return 0;
}

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

void main() {
    int n, m;
    readf("%d %d\n", &n, &m);
    int[] bulbs = new int[m];
    foreach (i; 0..n) {
        int[] buttons = readln.chomp.split.map!(to!int).array;
        foreach (e; buttons[1..$]) {
            bulbs[e - 1]++;
        }
    }

    if (bulbs.all) {
        writeln("YES");
    } else {
        writeln("NO");
    }
}

import std.algorithm, std.range, std.stdio;
void main () {
	int n, m;
	readf (" %s %s ", &n, &m);
	int [string] b;
	n.iota.each !(_ => readln.split.drop (1).each !(x => b[x]++));
	writeln (b.length == m ? "YES" : "NO");
}

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

void main ()
{
	int n, m;
	while (readf (" %s %s ", &n, &m) > 0)
	{
		int [] [] a;
		foreach (i; 0..n)
		{
			a ~= readln.split.drop (1).map !(to !(int)).array;
		}
		writeln (m.iota.map !(q{a + 1})
		    .all !(x => a.any !(b => b.canFind (x))) ? "YES" : "NO");
	}
}

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

void main ()
{
	int n, m;
	while (readf (" %s %s ", &n, &m) > 0)
	{
		int [] [] a;
		foreach (i; 0..m)
		{
			a ~= readln.split.drop (1).map !(to !(int)).array;
		}
		writeln (n.iota.map !(q{a + 1})
		    .all !(x => a.any !(b => b.canFind (x))) ? "YES" : "NO");
	}
}

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

void main() {
    int n, m;
    readf("%d %d\n", &n, &m);
    int[] bulbs = new int[m];
    foreach (i; 0..n) {
        int[] buttons = readln.chomp.split.map!(to!int).array;
        foreach (e; buttons) {
            bulbs[e - 1]++;
        }
    }

    if (bulbs.all) {
        writeln("YES");
    } else {
        writeln("NO");
    }
}


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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(long);
		writeln ((n & (n - 1)) == 0 ? "NO" : "YES");
	}
}

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

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

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

    while(n % 2 == 0) {
        n /= 2;
    }

    if(n > 1)
        "Yes".writeln;
    else
        "No".writeln;
}
}

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto t = RD!int;
	auto ans = new bool[](t);
	foreach (ti; 0..t)
	{
		auto n = RD;
		while (n % 2 == 0)
		{
			n /= 2;
		}
		ans[ti] = n > 1;
	}

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

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

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

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

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

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

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

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

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

void main()
{
    int T; get(T);
    while (T--) {
        long N; get(N);
        while (N % 2 == 0) N /= 2;
        writeln(N == 1 ? "NO" : "YES");
    }
}

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(long);
		writeln (n % 2 == 0 ? "NO" : "YES");
	}
}


// Code By H~$~C

module main;

import core.stdc.stdlib, core.stdc.string;
import std.stdio, std.array, std.string, std.math, std.uni;
import std.algorithm, std.range, std.random, std.container;
import std.conv, std.typecons, std.functional;

immutable Maxn = 4005;

int n, m, st, ed;
int[Maxn] p;
Tuple!(int, long)[][Maxn] g;
long[Maxn] dists, distt;
long[][Maxn] sum;
int[][Maxn] cnt;
long[][Maxn] dp1, dp2;
Tuple!(Tuple!(long, int), Tuple!(long, int))[Maxn] suf1, suf2;

void dijkstra(int st, ref long[Maxn] dist) {
  Tuple!(long, int)[] fucking = new Tuple!(long, int)[Maxn * 20];
  BinaryHeap!(Tuple!(long, int)[]) pq = BinaryHeap!(Tuple!(long, int)[])(fucking, 0);
  pq.insert(tuple(0L, st));
  dist[] = lnf;
  dist[st] = 0;
  while (!pq.empty) {
    auto pr = pq.front; pq.popFront;
    int u = pr[1];
    long d = -pr[0];
    if (d != dist[u]) continue;
    foreach(fuck; g[u]) {
      int v = fuck[0];
      long w = fuck[1];
      if (dist[v] > d + w) {
        dist[v] = d + w;
        pq.insert(tuple(-dist[v], v));
      }
    }
  }
}

// FIXME
void solve(in int testcase) {
  n.read, m.read, st.read, ed.read;
  p[1 .. n + 1] = readarray!int;
  foreach(i; 1 .. m + 1) {
    int u, v; long w;
    u.read, v.read, w.read;
    g[u] ~= tuple(v, w);
    g[v] ~= tuple(u, w);
  }
  dijkstra(st, dists);
  dijkstra(ed, distt);

  long[] vec;
  foreach(i; 1 .. n + 1)
    vec ~= [dists[i], distt[i]];
  vec = vec.sort.unique.array;
  int len = cast(int)vec.length + 1;
  foreach(i; 0 .. vec.length + 2)
    dp1[i].length = dp2[i].length = sum[i].length = cnt[i].length = len + 1;
  foreach(i; 1 .. n + 1) {
    dists[i] = vec.lower_bound(dists[i]);
    distt[i] = vec.lower_bound(distt[i]);
    cnt[cast(int)dists[i]][cast(int)distt[i]]++;
    sum[cast(int)dists[i]][cast(int)distt[i]] += p[i];
  }
  for (int i = len - 1; i >= 0; --i) {
    for (int j = len - 1; j >= 0; --j) {
      cnt[i][j] += cnt[i][j + 1] + cnt[i + 1][j] - cnt[i + 1][j + 1];
      sum[i][j] += sum[i][j + 1] + sum[i + 1][j] - sum[i + 1][j + 1];
    }
  }

  void update_answer(ref Tuple!(Tuple!(long, int), Tuple!(long, int)) x, Tuple!(long, int) y) {
    if (y < x[0]) swap(y, x[0]);
    if (y[1] == x[0][1]) return ;
    x[1] = min(x[1], y);
  }
  for (int i = len - 1; i >= 0; --i) {
    for (int j = len - 1; j >= 0; --j) {
      if (!cnt[i][j]) continue;
      dp1[i][j] = sum[i][j] - (cnt[i][j] != suf1[j][0][1] ? suf1[j][0] : suf1[j][1])[0];
      dp2[i][j] = sum[i][j] - (cnt[i][j] != suf2[i][0][1] ? suf2[i][0] : suf2[i][1])[0];
      update_answer(suf1[j], tuple(dp2[i][j], cnt[i][j]));
      update_answer(suf2[i], tuple(dp1[i][j], cnt[i][j]));
    }
  }

  long ans1 = dp1[0][0], ans2 = sum[0][0] - dp1[0][0];
  if (ans1 == ans2) "Flowers".writeln;
  else if (ans1 < ans2) "Cry".writeln;
  else "Break a heart".writeln;
}

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

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

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

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

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

// Code By H~$~C

module main;

import core.stdc.stdlib, core.stdc.string;
import std.stdio, std.array, std.string, std.math, std.uni;
import std.algorithm, std.range, std.random, std.container;
import std.conv, std.typecons, std.functional;

immutable Maxn = 4005;

int n, m, st, ed;
int[Maxn] p;
Tuple!(int, long)[][Maxn] g;
long[Maxn] dists, distt;
long[][Maxn] sum;
int[][Maxn] cnt;
long[][Maxn] dp1, dp2;
Tuple!(Tuple!(long, int), Tuple!(long, int))[Maxn] suf1, suf2;

void dijkstra(int st, ref long[Maxn] dist) {
  set!(Tuple!(long, int)) pq = Set(tuple!(long, int)(lnf, 0));
  pq.insert(tuple(0L, st));
  dist[] = lnf;
  dist[st] = 0;
  while (pq.length > 1) {
    auto pr = pq.front; pq.removeFront;
    int u = pr[1];
    long d = pr[0];
    if (d != dist[u]) continue;
    foreach(fuck; g[u]) {
      int v = fuck[0];
      long w = fuck[1];
      if (dist[v] > d + w) {
        dist[v] = d + w;
        pq.insert(tuple(dist[v], v));
      }
    }
  }
}

// FIXME
void solve(in int testcase) {
  n.read, m.read, st.read, ed.read;
  p[1 .. n + 1] = readarray!int;
  foreach(i; 1 .. m + 1) {
    int u, v; long w;
    u.read, v.read, w.read;
    g[u] ~= tuple(v, w);
    g[v] ~= tuple(u, w);
  }
  dijkstra(st, dists);
  dijkstra(ed, distt);

  long[] vec;
  foreach(i; 1 .. n + 1)
    vec ~= [dists[i], distt[i]];
  vec = vec.sort.unique.array;
  int len = cast(int)vec.length + 1;
  foreach(i; 0 .. vec.length + 2)
    dp1[i].length = dp2[i].length = sum[i].length = cnt[i].length = len + 1;
  foreach(i; 1 .. n + 1) {
    dists[i] = vec.lower_bound(dists[i]);
    distt[i] = vec.lower_bound(distt[i]);
    cnt[cast(int)dists[i]][cast(int)distt[i]]++;
    sum[cast(int)dists[i]][cast(int)distt[i]] += p[i];
  }
  for (int i = len - 1; i >= 0; --i) {
    for (int j = len - 1; j >= 0; --j) {
      cnt[i][j] += cnt[i][j + 1] + cnt[i + 1][j] - cnt[i + 1][j + 1];
      sum[i][j] += sum[i][j + 1] + sum[i + 1][j] - sum[i + 1][j + 1];
    }
  }

  void update_answer(ref Tuple!(Tuple!(long, int), Tuple!(long, int)) x, Tuple!(long, int) y) {
    if (y < x[0]) swap(y, x[0]);
    if (y[1] == x[0][1]) return ;
    x[1] = min(x[1], y);
  }
  for (int i = len - 1; i >= 0; --i) {
    for (int j = len - 1; j >= 0; --j) {
      if (!cnt[i][j]) continue;
      dp1[i][j] = sum[i][j] - (cnt[i][j] != suf1[j][0][1] ? suf1[j][0] : suf1[j][1])[0];
      dp2[i][j] = sum[i][j] - (cnt[i][j] != suf2[i][0][1] ? suf2[i][0] : suf2[i][1])[0];
      update_answer(suf1[j], tuple(dp2[i][j], cnt[i][j]));
      update_answer(suf2[i], tuple(dp1[i][j], cnt[i][j]));
    }
  }

  long ans1 = dp1[0][0], ans2 = sum[0][0] - dp1[0][0];
  if (ans1 == ans2) "Flowers".writeln;
  else if (ans1 < ans2) "Cry".writeln;
  else "Break a heart".writeln;
}

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

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

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

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

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

// Code By H~$~C

module main;

import core.stdc.stdlib, core.stdc.string;
import std.stdio, std.array, std.string, std.math, std.uni;
import std.algorithm, std.range, std.random, std.container;
import std.conv, std.typecons, std.functional;

immutable Maxn = 4005;

int n, m, st, ed;
int[Maxn] p;
Tuple!(int, long)[][Maxn] g;
long[Maxn] dists, distt;
long[][Maxn] sum;
int[][Maxn] cnt;
long[][Maxn] dp1, dp2;
Tuple!(Tuple!(long, int), Tuple!(long, int))[Maxn] suf1, suf2;

void dijkstra(int st, ref long[Maxn] dist) {
  set!(Tuple!(long, int)) pq = Set(tuple!(long, int)(-lnf - 1, 0));
  pq.insert(tuple(0L, st));
  dist[] = lnf;
  dist[st] = 0;
  while (pq.length > 1) {
    auto pr = pq.front; pq.removeFront;
    int u = pr[1];
    long d = pr[0];
    if (d != dist[u]) continue;
    foreach(fuck; g[u]) {
      int v = fuck[0];
      long w = fuck[1];
      if (dist[v] > d + w) {
        dist[v] = d + w;
        pq.insert(tuple(dist[v], v));
      }
    }
  }
}

// FIXME
void solve(in int testcase) {
  n.read, m.read, st.read, ed.read;
  p[1 .. n + 1] = readarray!int;
  foreach(i; 1 .. m + 1) {
    int u, v; long w;
    u.read, v.read, w.read;
    g[u] ~= tuple(v, w);
    g[v] ~= tuple(u, w);
  }
  dijkstra(st, dists);
  dijkstra(ed, distt);

  long[] vec;
  foreach(i; 1 .. n + 1)
    vec ~= [dists[i], distt[i]];
  vec = vec.sort.unique.array;
  int len = cast(int)vec.length + 1;
  foreach(i; 0 .. vec.length + 2)
    dp1[i].length = dp2[i].length = sum[i].length = cnt[i].length = len + 1;
  foreach(i; 1 .. n + 1) {
    dists[i] = vec.lower_bound(dists[i]);
    distt[i] = vec.lower_bound(distt[i]);
    cnt[cast(int)dists[i]][cast(int)distt[i]]++;
    sum[cast(int)dists[i]][cast(int)distt[i]] += p[i];
  }
  for (int i = len - 1; i >= 0; --i) {
    for (int j = len - 1; j >= 0; --j) {
      cnt[i][j] += cnt[i][j + 1] + cnt[i + 1][j] - cnt[i + 1][j + 1];
      sum[i][j] += sum[i][j + 1] + sum[i + 1][j] - sum[i + 1][j + 1];
    }
  }

  void update_answer(ref Tuple!(Tuple!(long, int), Tuple!(long, int)) x, Tuple!(long, int) y) {
    if (y < x[0]) swap(y, x[0]);
    if (y[1] == x[0][1]) return ;
    x[1] = min(x[1], y);
  }
  for (int i = len - 1; i >= 0; --i) {
    for (int j = len - 1; j >= 0; --j) {
      if (!cnt[i][j]) continue;
      dp1[i][j] = sum[i][j] - (cnt[i][j] != suf1[j][0][1] ? suf1[j][0] : suf1[j][1])[0];
      dp2[i][j] = sum[i][j] - (cnt[i][j] != suf2[i][0][1] ? suf2[i][0] : suf2[i][1])[0];
      update_answer(suf1[j], tuple(dp2[i][j], cnt[i][j]));
      update_answer(suf2[i], tuple(dp1[i][j], cnt[i][j]));
    }
  }

  long ans1 = dp1[0][0], ans2 = sum[0][0] - dp1[0][0];
  if (ans1 == ans2) "Flowers".writeln;
  else if (ans1 < ans2) "Cry".writeln;
  else "Break a heart".writeln;
}

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

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

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

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

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

// Code By H~$~C

module main;

import core.stdc.stdlib, core.stdc.string;
import std.stdio, std.array, std.string, std.math, std.uni;
import std.algorithm, std.range, std.random, std.container;
import std.conv, std.typecons, std.functional;

immutable Maxn = 4005;

int n, m, st, ed;
int[Maxn] p;
Tuple!(int, long)[][Maxn] g;
long[Maxn] dists, distt;
long[][Maxn] sum;
int[][Maxn] cnt;
long[][Maxn] dp1, dp2;
Tuple!(Tuple!(long, int), Tuple!(long, int))[Maxn] suf1, suf2;

void dijkstra(int st, ref long[Maxn] dist) {
  set!(Tuple!(long, int)) pq = Set(tuple!(long, int)(-1, 0));
  pq.insert(tuple(0L, st));
  dist[] = lnf;
  dist[st] = 0;
  while (pq.length > 1) {
    auto pr = pq.front; pq.removeFront;
    int u = pr[1];
    long d = pr[0];
    if (d != dist[u]) continue;
    foreach(fuck; g[u]) {
      int v = fuck[0];
      long w = fuck[1];
      if (dist[v] > d + w) {
        dist[v] = d + w;
        pq.insert(tuple(dist[v], v));
      }
    }
  }
}

// FIXME
void solve(in int testcase) {
  n.read, m.read, st.read, ed.read;
  p[1 .. n + 1] = readarray!int;
  foreach(i; 1 .. m + 1) {
    int u, v; long w;
    u.read, v.read, w.read;
    g[u] ~= tuple(v, w);
    g[v] ~= tuple(u, w);
  }
  dijkstra(st, dists);
  dijkstra(ed, distt);

  long[] vec;
  foreach(i; 1 .. n + 1)
    vec ~= [dists[i], distt[i]];
  vec = vec.sort.unique.array;
  int len = cast(int)vec.length + 1;
  foreach(i; 0 .. vec.length + 2)
    dp1[i].length = dp2[i].length = sum[i].length = cnt[i].length = len + 1;
  foreach(i; 1 .. n + 1) {
    dists[i] = vec.lower_bound(dists[i]);
    distt[i] = vec.lower_bound(distt[i]);
    cnt[cast(int)dists[i]][cast(int)distt[i]]++;
    sum[cast(int)dists[i]][cast(int)distt[i]] += p[i];
  }
  for (int i = len - 1; i >= 0; --i) {
    for (int j = len - 1; j >= 0; --j) {
      cnt[i][j] += cnt[i][j + 1] + cnt[i + 1][j] - cnt[i + 1][j + 1];
      sum[i][j] += sum[i][j + 1] + sum[i + 1][j] - sum[i + 1][j + 1];
    }
  }

  void update_answer(ref Tuple!(Tuple!(long, int), Tuple!(long, int)) x, Tuple!(long, int) y) {
    if (y < x[0]) swap(y, x[0]);
    if (y[1] == x[0][1]) return ;
    x[1] = min(x[1], y);
  }
  for (int i = len - 1; i >= 0; --i) {
    for (int j = len - 1; j >= 0; --j) {
      if (!cnt[i][j]) continue;
      dp1[i][j] = sum[i][j] - (cnt[i][j] != suf1[j][0][1] ? suf1[j][0] : suf1[j][1])[0];
      dp2[i][j] = sum[i][j] - (cnt[i][j] != suf2[i][0][1] ? suf2[i][0] : suf2[i][1])[0];
      update_answer(suf1[j], tuple(dp2[i][j], cnt[i][j]));
      update_answer(suf2[i], tuple(dp1[i][j], cnt[i][j]));
    }
  }

  long ans1 = dp1[0][0], ans2 = sum[0][0] - dp1[0][0];
  if (ans1 == ans2) "Flowers".writeln;
  else if (ans1 < ans2) "Cry".writeln;
  else "Break a heart".writeln;
}

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

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

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

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

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


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

void main ()
{
	int n, m, k;
	while (readf (" %s %s %s", &n, &m, &k) > 0)
	{
		alias Edge = Tuple !(int, q{u}, int, q{v});
		auto e = new Edge [m];
		auto d = new int [n];
		auto a = new bool [int] [n];
		foreach (ref edge; e)
		{
			readf (" %s %s", &edge.u, &edge.v);
			edge.u -= 1;
			edge.v -= 1;
			d[edge.u] += 1;
			d[edge.v] += 1;
			a[edge.u][edge.v] = true;
			a[edge.v][edge.u] = true;
		}
		debug {writeln (a);}
		debug {writeln (d);}
		debug {writeln (e);}

		alias Record = Tuple !(int, q{deg}, int, q{num});
		auto t = redBlackTree !(Record);
		foreach (i; 0..n)
		{
			t.insert (Record (d[i], i));
		}

		void changeDegree (int v, int delta)
		{
			auto cur = Record (d[v], v);
			auto r = t.equalRange (cur);
			if (r.empty)
			{
				d[v] += delta;
			}
			else
			{
				t.removeKey (cur);
				d[v] += delta;
				cur.deg = d[v];
				t.insert (cur);
			}
		}

		void removeVertex (int v)
		{
			debug {writeln (v, ": ", a[v].length, " ", d[v]);}
			assert (a[v].length == d[v]);
			foreach (u, _; a[v])
			{
				changeDegree (u, -1);
				a[u].remove (v);
			}
			a[v] = null;
			t.removeKey (Record (d[v], v));
			changeDegree (v, -d[v]);
		}

		auto ans = new int [m];
		foreach_reverse (int j, ref edge; e)
		{
			while (!t.empty && t.front.deg < k)
			{
				debug {writeln ("step ", j, ": ", t);}
				removeVertex (t.front.num);
			}
			debug {writeln ("step ", j, ": ", t);}
			ans[j] = t.length.to !(int);
			if (edge.v in a[edge.u])
			{
				changeDegree (edge.u, -1);
				changeDegree (edge.v, -1);
				a[edge.u].remove (edge.v);
				a[edge.v].remove (edge.u);
				debug {writeln ("step ", j, ": ", t);}
			}
		}

		foreach (ref c; ans)
		{
			writeln (c);
		}
	}
}

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

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto K = s[2];
    auto G = new bool[int][](N);
    auto D = new int[](N);
    auto Q = new Tuple!(int, int)[](M);
    foreach (i; 0..M) {
        s = readln.split.map!(to!int);
        G[s[0]-1][s[1]-1] = true;
        G[s[1]-1][s[0]-1] = true;
        D[s[0]-1] += 1;
        D[s[1]-1] += 1;
        Q[i] = tuple(s[0]-1, s[1]-1);
    }

    int sm = N;
    auto valid = new bool[](N);
    fill(valid, true);

    void dfs(int n) {
        if (!valid[n]) return;
        valid[n] = false;
        sm -= 1;
        foreach (m; G[n].keys) {
            if (!G[n][m]) continue;
            D[m] -= 1;
            G[n][m] = false;
            G[m][n] = false;
            if (valid[m] && D[m] < K) {
                dfs(m);
            }
        }
    }

    foreach (i; 0..N) {
        if (D[i] < K) dfs(i);
    }

    int[] ans;
    foreach_reverse (q; Q) {
        ans ~= sm;
        int u = q[0];
        int v = q[1];
        if (!valid[u] || !valid[v]) continue;
        D[u] -= 1;
        D[v] -= 1;
        G[u][v] = false;
        G[v][u] = false;
        if (valid[u] && D[u] < K) dfs(u);
        if (valid[v] && D[v] < K) dfs(v);
    }

    ans.reverse();
    ans.each!writeln;
}


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

immutable int mod = 998_244_353;
immutable int NA = -1;

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, k;
		readf !(" %s %s") (n, k);
		readln;

		auto a = readln.splitter.map !(to !(int)).array;
		a[] -= 1;
		auto next = new int [n];
		next[] = NA;
		auto prev = new int [n];
		prev[] = NA;
		foreach (i; 0..n - 1)
		{
			prev[a[i + 1]] = a[i];
			next[a[i]] = a[i + 1];
		}

		auto b = readln.splitter.map !(to !(int)).array;
		b[] -= 1;
		auto used = new bool [n];
		foreach (ref cur; b)
		{
			used[cur] = true;
		}

		int res = 1;
		foreach (i; 0..k)
		{
			int mult = 0;
			if (prev[b[i]] != NA && !used[prev[b[i]]])
			{
				mult += 1;
			}
			if (next[b[i]] != NA && !used[next[b[i]]])
			{
				mult += 1;
			}
			res = (res * mult) % mod;
			if (next[b[i]] != NA)
			{
				prev[next[b[i]]] = prev[b[i]];
			}
			if (prev[b[i]] != NA)
			{
				next[prev[b[i]]] = next[b[i]];
			}
			used[b[i]] = false;
		}
		writeln (res);
	}
}

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

enum MO = 998244353;

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

        auto lef = new int[N + 1];
        auto rig = new int[N + 1];
        rig[0] = A[0];
        lef[A[0]] = 0;
        foreach (i; 0 .. N - 1) {
          rig[A[i]] = A[i + 1];
          lef[A[i + 1]] = A[i];
        }
        rig[A[N - 1]] = 0;
        lef[0] = A[N - 1];

        auto del = new bool[N + 1];
        del[0] = true;
        foreach (k; 0 .. K) {
          del[B[k]] = true;
        }

        long ans = 1;
        foreach (k; 0 .. K) {
          const l = lef[B[k]];
          const r = rig[B[k]];
          rig[l] = r;
          lef[r] = l;
          int num;
          if (!del[l]) ++num;
          if (!del[r]) ++num;
          (ans *= num) %= MO;
        }
        writeln(ans);
      }
    }
  } catch (EOFException e) {
  }
}

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto t = RD!int;
	auto ans = new long[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto k = RD!int;
		auto a = RDA(-1);
		auto b = RDA(-1);

		auto need = new bool[](n);
		foreach (e; b)
		{
			need[e] = true;
		}

		auto pos = new int[](n);
		auto link = new int[][](n);
		foreach (int i; 0..n)
		{
			pos[a[i]] = i;
			link[i] = [i-1, i+1];
		}

		long tmp = 1;
		foreach (e; b)
		{
			auto p = pos[e];
			auto l = link[p][0];
			auto r = link[p][1];
			int cnt;
			if (l != -1)
			{
				if (!need[a[l]])
					++cnt;
				link[l][1] = r;
			}
			if (r != n)
			{
				if (!need[a[r]])
					++cnt;
				link[r][0] = l;
			}
			tmp.modm(cnt);
			need[e] = false;
		}
		ans[ti] = tmp;
	}

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


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

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

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

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

int N;
string S;

void main() {
  try {
    for (; ; ) {
      S = readToken();
      N = cast(int)(S.length);

      auto sum = new long[N];
      foreach (i; 0 .. N - 1) {
        sum[i + 1] = sum[i] + ((S[i .. i + 2] == "vv") ? 1 : 0);
      }
      long ans;
      foreach (i; 0 .. N) {
        if (S[i] == 'o') {
          ans += sum[max(i - 1, 0)] * (sum[$ - 1] - sum[min(i + 1, $ - 1)]);
        }
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}

/+ dub.sdl:
    name "B"
    dependency "dunkelheit" version="1.0.1"
+/

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

int main() {
    Scanner sc = new Scanner(stdin);
    scope(exit) assert(!sc.hasNext);
    string s;
    sc.read(s);

    auto li = s.group.array;

    debug writeln(li);

    long ans = 0;
    auto m = li.length;
    long[] cnt = new long[m + 1];
    long lsm = 0, rsm = 0;
    foreach (tok; li) {
        if (tok[0] == 'v') {
            rsm += tok[1] - 1;
        }
    }
    foreach (tok; li) {
        if (tok[0] == 'v') {
            lsm += tok[1] - 1;
            rsm -= tok[1] - 1;
        }
        if (tok[0] == 'o') {
            ans += lsm * tok[1] * rsm;
        }
    }

    writeln(ans);
    return 0;
}
/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/foundation.d */

// module dkh.foundation;

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

}
/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/container/stackpayload.d */
// module dkh.container.stackpayload;

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

    private T* _data;
    private uint len, cap;

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

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

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

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

    void clear() {
        len = 0;
    }

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

/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/scanner.d */
// module dkh.scanner;

// import dkh.container.stackpayload;

class Scanner {
    import std.stdio : File;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeChar, isStaticArray, isArray;
    import std.algorithm : map;
    private File f;

    this(File f) {
        this.f = f;
    }
    private char[512] lineBuf;
    private char[] line;
    private bool succW() {
        import std.range.primitives : empty, front, popFront;
        import std.ascii : isWhite;
        while (!line.empty && line.front.isWhite) {
            line.popFront;
        }
        return !line.empty;
    }
    private bool succ() {
        import std.range.primitives : empty, front, popFront;
        import std.ascii : isWhite;
        while (true) {
            while (!line.empty && line.front.isWhite) {
                line.popFront;
            }
            if (!line.empty) break;
            line = lineBuf[];
            f.readln(line);
            if (!line.length) return false;
        }
        return true;
    }

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

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

    int unsafeRead(T, Args...)(ref T x, auto ref Args args) {
        if (!readSingle(x)) return 0;
        static if (args.length == 0) {
            return 1;
        } else {
            return 1 + read(args);
        }
    }

    void read(Args...)(auto ref Args args) {
        import std.exception : enforce;
        static if (args.length != 0) {
            enforce(readSingle(args[0]));
            read(args[1..$]);
        }
    }

    bool hasNext() {
        return succ();
    }
}

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

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

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

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

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

int N;
string S;

void main() {
  try {
    for (; ; ) {
      S = readToken();
      N = cast(int)(S.length);

      auto sum = new long[N];
      foreach (i; 0 .. N - 1) {
        sum[i + 1] = sum[i] + ((S[i .. i + 2] == "vv") ? 1 : 0);
      }
      long ans;
      foreach (i; 0 .. N) {
        if (S[i] == 'o') {
          ans += sum[i - 1] * (sum[$ - 1] - sum[i + 1]);
        }
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}


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

  int n, k; rd(n, k);

  auto dp=new int[][](4, k+10);
  const int mod=998244353;

  void add(ref int x, int y){
    x+=y;
    if(x>=mod) x-=mod;
  }
  dp[0][1]=dp[3][1]=1;
  dp[1][2]=dp[2][2]=1;
  for(int i=1; i<n; i++){
    auto nex=new int[][](4, k+10);
    foreach(s; 0..(1<<2)){
      for(int j=1; j<=k; j++){
        foreach(t; 0..(1<<2)){
          if(s==t){
            add(nex[t][j], dp[s][j]);
          }else if((s^t)==((1<<2)-1)){
            if(s==0 || s==3){
              if(j+1<=k){
                add(nex[t][j+1], dp[s][j]);
              }
            }else{
              if(j+2<=k){
                add(nex[t][j+2], dp[s][j]);
              }
            }
          }else if((s==0 || s==3) && (t==1 || t==2)){
            if(j+1<=k){
              add(nex[t][j+1], dp[s][j]);
            }
          }else{
            add(nex[t][j], dp[s][j]);
          }
        }
      }
    }
    dp.swap(nex);
  }
  int tot=0;
  foreach(i; 0..(1<<2)) (tot+=dp[i][k])%=mod;
  writeln(tot);
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x) e=l[i].to!(typeof(e));
}

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

immutable int MD = 998244353;

int add(int a, int b) {
    a += b;
    if (a > MD) a -= MD;
    return a;
}

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

    auto dp = new int[][][] (n+1, 2*k+10, 4);
    dp[1][1][0] = dp[1][1][1] = dp[1][2][2] = dp[1][2][3] = 1;
    foreach (i; 2 .. n+1) {
        foreach (j; 1 .. 2*k+1) {
            dp[i][j][0] = add(dp[i-1][j][0], add(dp[i-1][j-1][1], add(dp[i-1][j][2], dp[i-1][j][3])));
            dp[i][j][1] = add(dp[i-1][j-1][0], add(dp[i-1][j][1], add(dp[i-1][j][2], dp[i-1][j][3])));

            dp[i][j][2] = add(dp[i-1][j-1][0], add(dp[i-1][j-1][1], dp[i-1][j][2]));
            if (j > 1) dp[i][j][2] = add(dp[i][j][2], dp[i-1][j-2][3]);

            dp[i][j][3] = add(dp[i-1][j-1][0], add(dp[i-1][j-1][1], dp[i-1][j][3]));
            if (j > 1) dp[i][j][3] = add(dp[i][j][3], dp[i-1][j-2][2]);

            debug { writeln(i, ' ', j, ' ', dp[i][j]); }
        }
    }

    auto ans = dp[n][k].fold!((a, b) => add(a, b));
    ans.writeln;
}

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

int saiki(int idx, int cnt, int s, int n, int k, int[][] c, int[][][] dp)
{
    if (cnt > k)
    {
        return 0;
    }
    if (dp[idx][cnt][s] != -1)
    {
        return dp[idx][cnt][s];
    }
    if (idx == n)
    {
        dp[idx][cnt][s] = (cnt == k) ? 1 : 0;
        return dp[idx][cnt][s];
    }
    const static int mod = 998244353;
    auto res = 0;
    foreach (i; 0 .. 4)
    {
        auto ret = saiki(idx + 1, cnt + c[s][i], i, n, k, c, dp);
        res = (res + ret) % mod;
    }
    dp[idx][cnt][s] = res;
    return res;
}

void solve(int n, int k)
{
    auto c = new int[][](4, 4);
    foreach (i; 0 .. 4) fill(c[i], 0);
    foreach (i; 1 .. 4) c[0][i] = 1;
    foreach (i; 0 .. 3) c[3][i] = 1;
    c[1][2] = c[2][1] = 2;
    auto dp = new int[][][](n + 1, k + 1, 4);
    foreach (i; 0 .. n + 1)
    {
        foreach (j; 0 .. k + 1)
        {
            fill(dp[i][j], -1);
        }
    }
    const static int mod = 998244353;
    auto res = 0;
    res = (res + saiki(1, 1, 0, n, k, c, dp)) % mod;
    res = (res + saiki(1, 2, 1, n, k, c, dp)) % mod;
    res = (res + saiki(1, 2, 2, n, k, c, dp)) % mod;
    res = (res + saiki(1, 1, 3, n, k, c, dp)) % mod;
    writeln(res);
}

int main(string[] args)
{
    int n, k;
    while (readf("%d %d\n", &n, &k) == 2)
    {
        solve(n, k);
    }
    return 0;
}

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

immutable int MD = 998244353;

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

    auto dp = new uint[][][] (n+1, 2*k+1, 4);
    dp[1][1][0] = dp[1][1][1] = dp[1][2][2] = dp[1][2][3] = 1;
    foreach (i; 2 .. n+1) {
        foreach (j; 1 .. 2*k+1) {
            dp[i][j][0] = dp[i-1][j][0] + dp[i-1][j-1][1] + dp[i-1][j][2] + dp[i-1][j][3];
            dp[i][j][1] = dp[i-1][j-1][0] + dp[i-1][j][1] + dp[i-1][j][2] + dp[i-1][j][3];

            dp[i][j][2] = dp[i-1][j-1][0] + dp[i-1][j-1][1] + dp[i-1][j][2];
            if (j > 1) dp[i][j][2] += dp[i-1][j-2][3];

            dp[i][j][3] = dp[i-1][j-1][0] + dp[i-1][j-1][1] + dp[i-1][j][3];
            if (j > 1) dp[i][j][3] += dp[i-1][j-2][2];

            dp[i][j][] %= MD;
            debug { writeln(i, ' ', j, ' ', dp[i][j]); }
        }
    }

    auto ans = dp[n][k].sum() % MD;
    ans.writeln;
}


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

void main()
{
    int t;
    readf!"%s"(t);
    readln;

    while (t--) {
        int n, d;
        readf!"%s %s"(n, d);
        readln;

        auto arr = readln.chomp.split.map!(to!int).array;

        auto vis = new bool[] (n);
        vis[] = false;

        int ans = -1;
        foreach (i; 0 .. n) {
            if (vis[i]) { continue; }

            int[] tmp;
            int p = i;
            while (!vis[p]) {
                vis[p] = true;
                tmp ~= arr[p];
                p = (p + d) % n;
            }

            tmp = tmp ~ tmp;

            int longest = 0;
            int cur = 0;
            foreach (e; tmp) {
                if (e == 0) { cur = 0; }
                else { cur += 1; }

                longest = max(longest, cur);
            }

            if (longest == tmp.length) {
                ans = -1;
                break;
            }

            ans = max(ans, longest);
        }

        ans.writeln;
    }

}

immutable multi = true;

void solve(int tc)
{
	auto n = readInt!int;
	auto d = readInt!int;
	auto a = ma(n, readInt!int);
	auto inCycle = new bool[](n);
	int steps = 0;
	bool processCycle(int[] cycle)
	{
		debug writeln("processing cycle ", cycle);
		if (cycle.length == 0) return false;
		auto isBad = true;
		foreach(i; cycle)
			if (a[i] == 0)
				isBad = false;
		if (isBad) { return isBad; }
		auto doubleCycle = cycle ~ cycle;
		int last0 = -1;
		foreach(i, ci; doubleCycle)
		{
			if (a[ci] == 0) last0 = cast(int)i;
			if (i >= cycle.length)
			{
				steps = max(steps, cast(int)i - last0);
			}
		}
		return isBad;
	}
	auto bad = false;
	foreach(i; 0 .. n)
	{
		int[] cycle;
		while (!inCycle[i])
		{
			inCycle[i] = true;
			cycle ~= i;
			i = (i+d)%n;
		}
		bad = bad || processCycle(cycle);
	}
	if (!bad) steps.writeln; else (-1).writeln;
}

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

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

void popChar()
{
	import core.stdc.stdio;
	currChar = getchar();
}

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

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


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

string FMT_F = "%.10f";

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

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

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

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

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

		if (s[0][1] == s[1][0])
		{
			if (s[n-1][n-2] == s[0][1])
				ans[ti] ~= [n, n-1];
			if (s[n-2][n-1] == s[0][1])
				ans[ti] ~= [n-1, n];
		}
		else if (s[n-1][n-2] == s[n-2][n-1])
		{
			if (s[0][1] == s[n-1][n-2])
				ans[ti] ~= [1, 2];
			if (s[1][0] == s[n-1][n-2])
				ans[ti] ~= [2, 1];
		}
		else
		{
			if (s[0][1] == '1')
				ans[ti] ~= [1, 2];
			if (s[1][0] == '1')
				ans[ti] ~= [2, 1];
			if (s[n-1][n-2] == '0')
				ans[ti] ~= [n, n-1];
			if (s[n-2][n-1] == '0')
				ans[ti] ~= [n-1, n];
		}
	}

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

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

string FMT_F = "%.10f";

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

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

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

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

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

		if (s[0][1] == s[1][0])
		{
			if (s[n-1][n-2] == s[0][1])
				ans[ti] ~= [n, n-1];
			if (s[n-2][n-1] == s[0][1])
				ans[ti] ~= [n-1, n];
		}
		else if (s[n-1][n-2] == s[n-2][n-1])
		{
			if (s[0][1] == s[n-1][n-2])
				ans[ti] ~= [1, 2];
			if (s[1][2] == s[n-1][n-2])
				ans[ti] ~= [2, 1];
		}
		else
		{
			if (s[0][1] == '1')
				ans[ti] ~= [1, 2];
			if (s[1][2] == '1')
				ans[ti] ~= [2, 1];
			if (s[n-1][n-2] == '0')
				ans[ti] ~= [n, n-1];
			if (s[n-2][n-1] == '0')
				ans[ti] ~= [n-1, n];
		}
	}

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

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

string FMT_F = "%.10f";

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

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

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

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

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

		if (s[0][1] == s[1][0])
		{
			if (s[n-1][n-2] == s[0][1])
				ans[ti] ~= [n, n-1];
			if (s[n-2][n-1] == s[0][1])
				ans[ti] ~= [n-1, n];
		}
		else
		{
			if (s[0][1] == '1')
				ans[ti] ~= [1, 2];
			if (s[1][2] == '1')
				ans[ti] ~= [2, 1];
			if (s[n-1][n-2] == '0')
				ans[ti] ~= [n, n-1];
			if (s[n-2][n-1] == '0')
				ans[ti] ~= [n-1, n];
		}
	}

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