Read problem statements in [Mandarin Chinese] and [Bengali].

There is an empty bus with M seats and a total of N people, numbered from 1 to N. Everyone is currently outside the bus. You are given a sequence of Q events of the following form.

- +\ i :  It denotes that the person i enters the bus.

- -\ i : It denotes that the person i leaves the bus.

It is guaranteed in the input that each person from 1 to N enters *at most* once as well as leaves the bus *at most* once.

Determine whether the sequence of events is *consistent* or not (i.e. no person leaves the bus before entering and the number of passengers in the bus does not exceed M at any point of time).

------ Input Format ------ 

- The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- Each test case contains Q + 1 lines of input.
- The first line of each test case contains three space-separated integers N, M, Q.
- Q lines follow. For each valid j, j^{th} of these lines contains a character ch, followed by a space and an integer i. Here ch is either '+' or '-' and 1 ≤ i ≤ N.
- It is guaranteed that + i" and - i" appears at most once for every 1 ≤ i ≤ N

------ Output Format ------ 

For each test case, print a single line containing one string - "Consistent" (without quotes) if the sequence is consistent, "Inconsistent" (without quotes) otherwise.

------ Constraints ------ 

$1 ≤ T ≤ 20$
$1 ≤ N ≤ 10^{4}$
$1 ≤ M ≤ 10^{4}$
$1 ≤ Q ≤ 10^{4}$

----- Sample Input 1 ------ 
2
2 1 4
+ 1
+ 2
- 1
- 2
3 2 6
+ 2
+ 1
- 1
+ 3
- 3
- 2
----- Sample Output 1 ------ 
Inconsistent
Consistent
----- explanation 1 ------ 
- Test case $1$: After Person $2$ enters the bus, there are two people inside the bus while the capacity of the bus is $1$.

----- Sample Input 2 ------ 
2
100 10 5
+ 1
+ 2
- 3
+ 3
- 2
6 4 4
+ 3
+ 2
+ 1
+ 4

----- Sample Output 2 ------ 
Inconsistent
Consistent

----- explanation 2 ------ 
- Test case $1$: Person $3$ leaves the bus without entering and thus it is inconsistent.

Source: codechef | Difficulty: MEDIUM
Tags: Data structures

Implementation


Solutions:
for i in range(int(input())):
	(n, m, q) = map(int, input().split())
	bus = set()
	consistent = True
	for x in range(q):
		e = input()
		s = e[0]
		e = int(e[1:])
		if s == '-':
			if e not in bus:
				consistent = False
			else:
				bus.remove(e)
		elif e in bus:
			consistent = False
		else:
			bus.add(e)
			if len(bus) > m:
				consistent = False
	if consistent:
		print('Consistent')
	else:
		print('Inconsistent')


for _ in range(int(input())):
	(n, m, q) = map(int, input().split())
	status = set()
	bl = False
	for j in range(q):
		(ch, i) = input().split()
		i = int(i)
		if ch == '+':
			status.add(i)
		elif i in status:
			status.remove(i)
		else:
			bl = True
		if len(status) > m:
			bl = True
	if bl:
		print('Inconsistent')
	else:
		print('Consistent')


tests = int(input())
for i in range(tests):
	(n, m, q) = map(int, input().split())
	in_bus = set()
	ans = 'Consistent'
	for j in range(q):
		(operation, person) = input().strip().split()
		if operation == '+':
			in_bus.add(person)
		elif person in in_bus:
			in_bus.remove(person)
		else:
			ans = 'Inconsistent'
		if len(in_bus) > m:
			ans = 'Inconsistent'
	print(ans)


for _ in range(int(input())):
	(N, M, Q) = map(int, input().split())
	l = [0] * (N + 1)
	currCount = 0
	flag = 1
	for i in range(Q):
		(ch1, ch2) = map(str, input().split())
		ch2 = int(ch2)
		if flag == 0:
			continue
		if ch1 == '+':
			l[ch2] += 1
			currCount += 1
			if currCount > M:
				flag = 0
		elif l[ch2] == 0:
			flag = 0
		else:
			l[ch2] -= 1
			currCount -= 1
	if flag:
		print('Consistent')
	else:
		print('Inconsistent')


for z in range(int(input())):
	(n, m, q) = [int(x) for x in input().split()]
	v = set()
	r = 0
	for i in range(q):
		(a, b) = [x for x in input().split()]
		if a == '+':
			v.add(int(b))
			if len(v) > m:
				r = 1
		elif int(b) not in v:
			r = 1
		else:
			v.remove(int(b))
	if r == 0:
		print('Consistent')
	else:
		print('Inconsistent')


for i in range(int(input())):
	(n, m, q) = map(int, input().split())
	l1 = []
	check = True
	while q > 0:
		(ch, s) = map(str, input().split())
		if ch == '+':
			if s in l1:
				check = False
			else:
				l1.append(s)
				if len(l1) > m:
					check = False
		elif ch == '-':
			if s not in l1:
				check = False
			else:
				l1.remove(s)
		q -= 1
	if not check:
		print('Inconsistent')
	else:
		print('Consistent')


for _ in range(int(input())):
	(n, m, q) = map(int, input().split())
	c = 0
	dictionary = dict()
	flag = True
	for j in range(q):
		(sign, i) = map(str, input().split())
		if sign == '-':
			if i not in dictionary:
				flag = False
			c -= 1
		if sign == '+':
			c += 1
			if c > m:
				flag = False
			dictionary[i] = sign
	if flag:
		print('Consistent')
	else:
		print('Inconsistent')


for _ in range(int(input())):
	(n, m, q) = map(int, input().split())
	bus = []
	inconsistent = False
	for i in range(q):
		(act, person) = map(str, input().split())
		if act == '+':
			if len(bus) == m:
				inconsistent = True
			else:
				bus.append(person)
		elif person in bus:
			bus.remove(person)
		else:
			inconsistent = True
	if inconsistent:
		print('Inconsistent')
	else:
		print('Consistent')


for i in range(int(input())):
	(n, m, q) = map(int, input().split())
	c = 0
	flag = 0
	l = []
	for i in range(q):
		(a, b) = map(str, input().split())
		if a == '+':
			c += 1
			r = int(b)
			if i == 0:
				l.append(r)
			elif r in l:
				flag = 1
			elif r not in l:
				l.append(r)
			if c > m:
				flag = 1
		elif a == '-':
			c = c - 1
			r = int(b)
			if c < 0 or r not in l:
				flag = 1
			if r in l:
				l.remove(r)
	if flag == 1:
		print('Inconsistent')
	else:
		print('Consistent')


t = int(input())
for i in range(t):
	(N, M, Q) = map(int, input().split())
	queue = []
	inconsistent = 0
	for j in range(Q):
		(operator, operand) = map(str, input().split())
		operand = int(operand)
		if operator == '+':
			if len(queue) >= M:
				inconsistent = 1
			elif operand in queue:
				inconsistent = 1
			else:
				queue.append(operand)
		elif len(queue) == 0:
			inconsistent = 1
		elif operand not in queue:
			inconsistent = 1
		else:
			queue.remove(operand)
	if inconsistent:
		print('Inconsistent')
	else:
		print('Consistent')


t = int(input())
for j in range(t):
	(n, m, q) = tuple(map(int, input().split()))
	d = []
	f = 1
	for k in range(q):
		(a, b) = input().split()
		if a == '+':
			if b in d:
				f = 0
			else:
				d.append(b)
				if len(d) > m:
					f = 0
		if a == '-':
			if b not in d:
				f = 0
			else:
				d.remove(b)
	if f == 1:
		print('Consistent')
	else:
		print('Inconsistent')


for i in range(int(input())):
	(n, m, q) = tuple(map(int, input().split()))
	bl = []
	flag = True
	for x in range(q):
		(ch, a) = input().split()
		if ch == '+':
			if a in bl:
				flag = False
			else:
				bl.append(a)
				if len(bl) > m:
					flag = False
		if ch == '-':
			if a not in bl:
				flag = False
			else:
				bl.remove(a)
	if flag:
		print('Consistent')
	else:
		print('Inconsistent')


t = int(input())
for i in range(t):
	(n, m, q) = map(int, input().split())
	peopleArray = [0] * n
	flag = 0
	count = 0
	for j in range(q):
		s = input().split()
		f = int(s[1])
		if s[0] == '-':
			f = -1 * f
			peopleArray[abs(f) - 1] -= 1
			count -= 1
		else:
			peopleArray[f - 1] += 1
			count += 1
		if count > m or count < 0:
			flag = 1
		if peopleArray[abs(f) - 1] < 0 or peopleArray[abs(f) - 1] > 1:
			flag = 1
	if flag == 0:
		print('Consistent')
	else:
		print('Inconsistent')


a = int(input())
for j in range(a):
	(n, m, q) = map(int, input().split())
	a = [0] * (n + 1)
	corin = 0
	people = 0
	for i in range(q):
		(pm, person) = input().split()
		person = int(person)
		if pm == '+':
			a[person] += 1
			people += 1
			if people > m:
				corin = -1
		else:
			a[person] -= 1
			people -= 1
			if a[person] == -1:
				corin = -1
	if corin == -1:
		print('Inconsistent')
	else:
		print('Consistent')


def solve():
	(n, m, q) = map(int, input().split())
	from collections import defaultdict
	di = defaultdict(int)
	cnt = 0
	flag = True
	que = list()
	for i in range(q):
		s = input()
		s = s.split()
		que.append(s)
	for i in range(q):
		s = que[i]
		if s[0] == '+':
			cnt += 1
			di[int(s[1])] += 1
			if cnt > m:
				flag = False
				break
		else:
			cnt -= 1
			di[int(s[1])] -= 1
			if di[int(s[1])] < 0:
				flag = False
				break
	if not flag:
		print('Inconsistent')
	else:
		print('Consistent')
for _ in range(int(input())):
	solve()


for _ in range(int(input())):
	(n, m, q) = map(int, input().split())
	l = []
	bus = []
	for i in range(q):
		(s, num) = input().split()
		l.append((s, num))
	ans = 1
	for (s, num) in l:
		if s == '+':
			if len(bus) >= m:
				ans = 0
				break
			else:
				bus.append(num)
		elif len(bus) == 0 or num not in bus:
			ans = 0
			break
		else:
			bus.remove(num)
	if ans == 1:
		print('Consistent')
	else:
		print('Inconsistent')


try:
	T = int(input())
	while T:
		(N, M, Q) = map(int, input().split())
		sign = [''] * Q
		n = [0] * Q
		arr = [0] * N
		flag = 1
		for i in range(Q):
			(sign[i], n[i]) = input().split()
		count = 0
		for i in range(Q):
			if sign[i] == '+':
				arr[int(n[i]) - 1] = 1
				count += 1
			elif arr[int(n[i]) - 1] == 0:
				print('Inconsistent')
				flag = 0
				break
			else:
				arr[int(n[i]) - 1] = 0
				count -= 1
			if count < 0 or count > M:
				print('Inconsistent')
				flag = 0
				break
		if flag:
			print('Consistent')
		T -= 1
except:
	pass


for _ in range(int(input())):
	(n, m, q) = map(int, input().split())
	cnst = True
	bsli = []
	for i in range(q):
		(sgn, ni) = map(str, input().split())
		ni = int(ni)
		if sgn == '+':
			bsli.append(ni)
		elif ni in bsli:
			bsli.remove(ni)
		else:
			cnst = False
		if len(bsli) > m:
			cnst = False
	if cnst:
		print('Consistent')
	else:
		print('Inconsistent')


import sys
input = sys.stdin.readline

def rii():
	return range(int(input().strip()))

def ii():
	return int(input().strip())

def mii():
	return map(int, input().strip().split(' '))

def lmii():
	return list(map(int, input().strip().split(' ')))

def si():
	return str(input().strip())
success = 'Consistent'
failure = 'Inconsistent'

class Bus:

	def __init__(self, population, capacity):
		self.m = capacity
		self.n = population
		self.o = 0
		self.joined = set()

	def process_event(self, event):
		(action, number) = event.split(' ')
		n = int(number)
		if action == '+':
			self.o += 1
			self.joined.add(n)
		elif action == '-':
			self.o -= 1
			if n not in self.joined:
				return False
			else:
				self.joined.remove(n)
		if any([self.o > self.m, self.o < 0]):
			return False
		return True

def solve(*args):
	(n, m, events) = args
	b = Bus(n, m)
	while len(events) > 0:
		if b.process_event(events.pop(0)) == False:
			return failure
	return success

def do_codechef():
	for t in rii():
		(n, m, q) = mii()
		events = list()
		for _ in range(q):
			events.append(si())
		print(solve(n, m, events))
do_codechef()
exit()


try:
	for _ in range(int(input())):
		p = [int(i) for i in input().split()]
		n = p[0]
		m = p[1]
		q = p[2]
		t = []
		l = set()
		t = True
		count = 0
		for i in range(q):
			p = [str(i) for i in input().split()]
			if p[0] == '+':
				if m > 0 and p[1] not in l:
					m -= 1
					l.add(p[1])
				else:
					t = False
			elif p[0] == '-':
				if p[1] not in l:
					t = False
				else:
					l.remove(p[1])
					m += 1
		if t:
			print('Consistent')
		else:
			print('Inconsistent')
except Exception:
	pass


t = int(input())
for i in range(t):
	(n, m, q) = map(int, input().split())
	l = []
	b = []
	for j in range(q):
		(s, k) = input().split()
		l.append((s, k))
	ans = 1
	for (s, k) in l:
		if s == '+':
			if len(b) >= m:
				ans = 0
				break
			else:
				b.append(k)
		elif len(b) == 0 or k not in b:
			ans = 0
			break
		else:
			b.remove(k)
	print('Consistent' if ans == 1 else 'Inconsistent')


for t in range(int(input())):
	(n, m, q) = map(int, input().split())
	d = {}
	flag = 1
	for i in range(0, q):
		l = list(map(str, input().split()))
		if l[0] == '-' and l[1] not in d:
			flag = 0
		elif l[0] == '-' and l[1] in d:
			del d[l[1]]
		elif l[0] == '+' and l[1] in d:
			flag = 0
		elif l[0] == '+' and l[1] not in d:
			d[l[1]] = '+'
			if len(d) > m:
				flag = 0
	if flag == 0:
		print('Inconsistent')
	else:
		print('Consistent')


for _ in range(int(input())):
	(n, m, q) = map(int, input().split())
	res = []
	pin = []
	for __ in range(q):
		(ch, pi) = input().split()
		if pi not in pin and ch == '-' or len(pin) > m or (ch == '+' and len(pin) >= m):
			res.append(0)
		if ch == '+':
			pin.append(pi)
		elif ch == '-':
			if pi not in pin:
				res.append(0)
			else:
				pin.remove(pi)
	if len(res) == 0:
		print('Consistent')
	else:
		print('Inconsistent')


for _ in range(int(input())):
	(n, m, q) = map(int, input().split())
	p = []
	count = True
	for _ in range(q):
		chi = input().split()
		ch = str(chi[0])
		i = int(chi[1])
		if ch == '+':
			p.append(i)
			if len(p) > m:
				count = False
		elif ch == '-' and i not in p:
			count = False
		elif ch == '-' and i in p:
			p.remove(i)
	if count:
		print('Consistent')
	else:
		print('Inconsistent')


for _ in range(int(input())):
	(n, m, q) = map(int, input().strip().split())
	signaa = []
	yaa = []
	ans = []
	remaining = m
	f = 0
	for i in range(q):
		x = input().strip().split()
		signaa.append(x[0])
		yaa.append(int(x[1]))
	for i in range(len(yaa)):
		sign = signaa[i]
		y = yaa[i]
		if sign == '+':
			if remaining > 0:
				ans.append(y)
				remaining -= 1
			else:
				f = 1
				print('Inconsistent')
				break
		elif y in ans:
			ii = ans.index(y)
			ans.pop(ii)
			remaining += 1
		else:
			f = 1
			print('Inconsistent')
			break
	if f == 0:
		print('Consistent')


for _ in range(int(input())):
	(n, m, q) = map(int, input().split(' '))
	l = []
	flag = 1
	for __ in range(q):
		(c, i) = input().split(' ')
		i = int(i)
		if c == '-' and i not in l:
			flag = 0
			continue
		if c == '+' and len(l) >= m:
			flag = 0
			continue
		if c == '+' and (i not in l and len(l) < m):
			l.append(i)
		if c == '-' and i in l:
			l.remove(i)
	if flag == 1:
		print('Consistent')
	else:
		print('Inconsistent')


t = int(input())
while t:
	(n, m, q) = map(int, input().split())
	a = [False for _ in range(n + 1)]
	ans = 'Consistent'
	cnt = 0
	while q:
		(c, num) = map(str, input().split())
		nu = int(num)
		if c == '+' and a[nu]:
			ans = 'Inconsistent'
		elif c == '+':
			a[nu] = True
			cnt += 1
		if c == '-' and (not a[nu]):
			ans = 'Inconsistent'
		elif c == '-':
			a[nu] = False
			cnt -= 1
		if cnt > m:
			ans = 'Inconsistent'
		q -= 1
	print(ans)
	t -= 1


def solve():
	(n, m, q) = [int(x) for x in input().split()]
	busCount = 0
	dicti = {}
	ls = []
	for i in range(q):
		temp = [x for x in input().split()]
		ls.append(temp)
	for temp in ls:
		ch = temp[0]
		i = int(temp[1])
		if ch == '+':
			if i in dicti:
				print('Inconsistent')
				return
			elif busCount < m:
				dicti[i] = 1
				busCount += 1
			else:
				print('Inconsistent')
				return
		if ch == '-':
			if i in dicti:
				del dicti[i]
				busCount -= 1
			else:
				print('Inconsistent')
				return
	print('Consistent')
t = int(input())
while t != 0:
	solve()
	t -= 1


for i in range(int(input())):
	(n, m, q) = [int(x) for x in input().split()]
	cnt = 0
	ans = 'Consistent'
	entered = []
	for j in range(q):
		query = input()
		if query[0] == '+':
			cnt += 1
			entered.append(query[2])
		else:
			if query[2] not in entered:
				ans = 'Inconsistent'
			else:
				entered.remove(query[2])
			cnt -= 1
		if cnt > m:
			ans = 'Inconsistent'
	print(ans)


def solve(n, m, events):
	state = {}
	count = 0
	for e in events:
		(type, number) = (e[0], int(e[1:].strip()))
		if type == '+':
			count += 1
			if count > m:
				print('Inconsistent')
				return
			state[number] = 1
		elif type == '-':
			if number not in state:
				print('Inconsistent')
				return
			del state[number]
			count -= 1
		else:
			print('Inconsistent')
			return
	print('Consistent')
t = int(input())
for i in range(t):
	(n, m, q) = map(int, input().split())
	events = []
	for _ in range(q):
		events.append(input())
	solve(n, m, events)


def eval(n, m, q):
	change = []
	st1 = ''
	sum = 0
	for j in range(q):
		change.append(input())
	for w in change:
		st1 = st1 + w
		if w[0] == '-':
			if '+ ' + w[2:] not in st1:
				return -1
			sum = sum - 1
		elif w[0] == '+':
			sum = sum + 1
		if sum > m:
			return -1
	print('Consistent')
	return 1
for _ in range(int(input())):
	(n, m, q) = map(int, input().split())
	if eval(n, m, q) == -1:
		print('Inconsistent')


for t in range(int(input())):
	l = list(map(int, input().split()))
	(n, m, q) = (l[0], l[1], l[2])
	(entered, c, flag) = (set(), 0, 0)
	for i in range(q):
		(a, b) = map(str, input().split())
		if flag == 0:
			if a == '+':
				c += 1
				entered.add(b)
				if c > m:
					flag = 1
			else:
				c -= 1
				if b not in entered:
					flag = 1
	if flag == 0:
		print('Consistent')
	else:
		print('Inconsistent')


for tc in range(int(input())):
	ls = list(map(int, input().split()))
	mem = [0] * (ls[0] + 1)
	flag = 1
	req = ls[1]
	for x in range(ls[2]):
		s = input()
		sign = s[0]
		me = int(s[2:])
		if sign == '+':
			if req > 0:
				req -= 1
				mem[me] = 1
			else:
				flag = 0
		elif mem[me] == 1:
			mem[me] = 0
			req += 1
		else:
			flag = 0
	if flag:
		print('Consistent')
	else:
		print('Inconsistent')


t = int(input())
for i in range(t):
	(n, m, q) = map(int, input().split())
	arr = [False] * (n + 1)
	count = 0
	ans = 'Consistent'
	for j in range(q):
		(a, b) = input().split()
		if a == '-':
			if not arr[int(b)]:
				ans = 'Inconsistent'
			else:
				arr[int(b)] = False
				count -= 1
		else:
			arr[int(b)] = True
			count += 1
		if 0 <= count <= m:
			continue
		else:
			ans = 'Inconsistent'
	print(ans)


T = int(input())
for t in range(T):
	(n, m, q) = [int(i) for i in input().split()]
	ans = True
	tot = 0
	present = dict()
	for i in range(q):
		(a, b) = input().split()
		if a == '+':
			tot += 1
			present[b] = 1
			if tot > m:
				ans = False
		elif b not in present:
			ans = False
		else:
			present[b] = 0
			tot -= 1
	if ans:
		print('Consistent')
	else:
		print('Inconsistent')


for _ in range(int(input())):
	(n, m, q) = map(int, input().split())
	arr = [0] * (n + 1)
	f = 1
	s = 0
	for i in range(q):
		l = input().split()
		if l[0] == '+':
			if arr[int(l[-1])] == 0:
				s += 1
				arr[int(l[-1])] = 1
			else:
				f = 0
		elif arr[int(l[-1])] == 1:
			arr[int(l[-1])] = 0
			s -= 1
		else:
			f = 0
		if s > m:
			f = 0
	if f:
		print('Consistent')
	else:
		print('Inconsistent')


def checkEvent(m, temp, cur):
	if temp[0] == '-':
		if passanger[int(temp[1]) - 1] == 0:
			return (False, cur)
	else:
		passanger[int(temp[1]) - 1] += 1
	cur += 1 if temp[0] == '+' else -1
	if cur > m:
		return (False, cur)
	return (True, cur)
t = int(input())
for _ in range(t):
	(n, m, q) = map(int, input().split())
	passanger = [0] * n
	cur = 0
	ans = True
	for _ in range(q):
		temp = list(input().split())
		tempAns = checkEvent(m, temp, cur)
		if tempAns[0]:
			cur = tempAns[1]
		else:
			ans = False
	if ans:
		print('Consistent')
	else:
		print('Inconsistent')


t = int(input())
for _ in range(t):
	(n, m, q) = map(int, input().split())
	flag = 'Consistent'
	currCount = 0
	arr = [0] * n
	for i in range(q):
		(ch, val) = input().split()
		val = int(val) - 1
		if ch == '+':
			arr[val] += 1
			currCount += 1
			if currCount > m:
				flag = 'Inconsistent'
		else:
			arr[val] -= 1
			currCount -= 1
			if arr[val] < 0 or currCount < 0:
				flag = 'Inconsistent'
	print(flag)


def solveC():
	bus = set()
	for a in A:
		if a[0] == '+':
			if len(bus) >= M:
				return 'Inconsistent'
			else:
				bus.add(a[1])
		elif a[1] not in bus:
			return 'Inconsistent'
		else:
			bus.remove(a[1])
	return 'Consistent'
for _ in range(int(input())):
	(N, M, Q) = [int(x) for x in input().split()]
	A = [[x if x in ['+', '-'] else int(x) for x in input().split()] for q in range(Q)]
	print(solveC())


t = int(input())
for tc in range(t):
	(n, m, q) = map(int, input().split())
	d = {}
	cur = 0
	res = 1
	for k in range(q):
		(ch, i) = map(str, input().split())
		i = int(i)
		if ch == '+' and res != -1:
			cur += 1
			d[i] = 1
			if cur > m:
				res = -1
		elif ch == '-' and res != -1:
			cur -= 1
			if cur < 0:
				res = -1
			try:
				d.pop(i)
			except:
				res = -1
	if res == 1:
		print('Consistent')
	else:
		print('Inconsistent')


t = int(input())
for i in range(t):
	(n, m, q) = map(str, input().split())
	n = int(n)
	m = int(m)
	q = int(q)
	a = [0] * n
	count = 0
	ans = 'Consistent'
	for j in range(q):
		(x, y) = map(str, input().split())
		if x == '+':
			a[int(y) - 1] += 1
			count += 1
			if count > m:
				ans = 'Inconsistent'
		else:
			a[int(y) - 1] -= 1
			count -= 1
			if a[int(y) - 1] == -1:
				ans = 'Inconsistent'
	print(ans)


for _ in range(int(input())):
	(n, m, q) = map(int, input().split())
	l = []
	flag = 0
	a = []
	for i in range(q):
		s1 = list(input().split())
		a.append(s1)
	for s in a:
		if s[0] == '-':
			if s[1] in l:
				l.remove(s[1])
			else:
				flag = 1
				break
		else:
			l.append(s[1])
		if len(l) > m:
			flag = 1
			break
	if flag == 0:
		print('Consistent')
	else:
		print('Inconsistent')


test_cases = int(input())
for i in range(test_cases):
	(n, c, t) = map(int, input().split())
	a = [0] * (n + 1)
	val = 0
	flag = 0
	for j in range(t):
		p = input()
		x = int(p[2:])
		if p[0] == '+':
			a[x] += 1
			val += 1
		elif a[x] <= 0:
			flag = 1
		else:
			a[x] -= 1
			val -= 1
		if val > c:
			flag = 1
	if flag:
		print('Inconsistent')
	else:
		print('Consistent')


cs = int(input())
while cs:
	cs -= 1
	(one, two, three) = map(int, input().split())
	(cx, sq, sq1, val) = (0, [], [], 0)
	while three:
		three -= 1
		sq.append(input())
	for iv in sq:
		if '+' in iv:
			sq1.append(int(iv[-1]))
			if len(sq1) > two:
				val = -1
				break
		elif int(iv[-1]) not in sq1:
			val = -1
			break
		else:
			sq1.remove(int(iv[-1]))
	print('Inconsistent') if len(sq1) > two or val == -1 else print('Consistent')


t = int(input())
for w in range(t):
	(n, m, q) = map(int, input().split())
	l = list()
	flag = 0
	for i in range(q):
		(s, p) = input().split()
		p = int(p)
		if s == '+':
			if len(l) < m:
				l.append(p)
			else:
				flag = 1
		if s == '-':
			if p in l:
				l.remove(p)
			else:
				flag = 1
	if flag == 1:
		print('Inconsistent')
	else:
		print('Consistent')


for _ in range(int(input())):
	(N, M, Q) = map(int, input().split())
	bus = {}
	flag = True
	while Q:
		Q -= 1
		(symbol, number) = input().split()
		number = int(number)
		if symbol == '+':
			if number in bus:
				flag = False
			else:
				bus[number] = 1
		else:
			try:
				del bus[number]
			except:
				flag = False
		if len(bus) > M:
			flag = False
	if flag:
		print('Consistent')
	else:
		print('Inconsistent')


for _ in range(int(input())):
	(N, M, Q) = map(int, input().split())
	result = True
	noOfPassenger = 0
	p = [0 for i in range(N)]
	for __ in range(Q):
		(signa, num) = input().split()
		num = int(num)
		if signa == '-':
			if p[num - 1] == 1:
				noOfPassenger -= 1
				p[num - 1] = 0
			else:
				result = False
		else:
			p[num - 1] = 1
			noOfPassenger += 1
			if noOfPassenger > M:
				result = False
	if result:
		print('Consistent')
	else:
		print('Inconsistent')


for _ in range(int(input())):
	(n, m, q) = map(int, input().split())
	(enter, exit, elim) = (dict(), dict(), dict())
	flag = True
	count = 0
	for i in range(q):
		(sign, passenger) = map(str, input().split())
		passenger = int(passenger)
		if sign == '+':
			count += 1
			if count > m:
				flag = False
			try:
				if not exit[passenger] and (not elim[passenger]):
					enter[passenger] = 1
				else:
					flag = False
			except:
				enter[passenger] = 1
		elif sign == '-':
			count -= 1
			try:
				if enter[passenger]:
					exit[passenger] = 1
					elim[passenger] = 1
				else:
					flag = False
			except:
				flag = False
	if flag:
		print('Consistent')
	else:
		print('Inconsistent')


d = {}
t = int(input())
for i in range(t):
	[n, m, q] = [int(k) for k in input().split()]
	for j in range(n):
		d[j + 1] = -1
	so = 0
	c = 1
	for j in range(q):
		[e_l, p] = [str(k) for k in input().split()]
		if e_l == '+' and so == m:
			c = 0
		elif e_l == '+':
			d[int(p)] = 0
			so += 1
		elif e_l == '-' and d[int(p)] == -1:
			c = 0
		else:
			d[int(p)] = 0
			so -= 1
	if c == 1:
		print('Consistent')
	else:
		print('Inconsistent')


for _ in range(int(input())):
	(n, m, q) = map(int, input().split())
	ls = []
	flag = 1
	for _ in range(q):
		(ch, i) = input().split()
		if ch == '+':
			ls.append(i)
		elif i in ls:
			ls.remove(i)
		else:
			flag = 0
		if len(ls) > m:
			flag = 0
	print('Consistent' if flag else 'Inconsistent')


t = int(input())

def main(N, M, Q, op):
	bus = 0
	d = {}
	for (i, j) in op:
		if i == '+':
			bus += 1
			d[j] = True
		elif i == '-':
			bus = bus - 1
			if d.get(j, None) == None:
				return 'Inconsistent'
		if bus > M:
			return 'Inconsistent'
	return 'Consistent'
for k in range(t):
	(N, M, Q) = map(int, input().split(' '))
	op = []
	if N != '+' or N != '-':
		for i in range(Q):
			tem = input().split(' ')
			tem[-1] = int(tem[-1])
			op.append(tem)
	print(main(N, M, Q, op))


from sys import stdin, stdout
for _ in range(int(input())):
	(n, m, q) = map(int, input().split())
	p = 0
	l = []
	flag = True
	for _ in range(q):
		(ch, t) = input().split()
		if flag:
			if ch == '+':
				l.append(t)
				p += 1
				if p > m:
					flag = False
			if ch == '-':
				p -= 1
				if t in l:
					l.remove(t)
				else:
					flag = False
	print('Consistent' if flag else 'Inconsistent')


for u in range(int(input())):
	(n, m, q) = map(int, input().split())
	c = 0
	f = 0
	d = [0 for i in range(n)]
	for i in range(q):
		(s, x) = input().split()
		x = int(x) - 1
		if s == '+':
			d[x] += 1
			c += 1
			if c > m:
				f = 1
		elif d[x] == 1:
			d[x] -= 1
			c -= 1
		else:
			f = 1
	if f == 0:
		print('Consistent')
	else:
		print('Inconsistent')


t = int(input())
for i in range(0, t):
	(a, b, c) = [int(x) for x in input().split()]
	value = True
	list = []
	for i in range(0, c):
		(d, e) = input().split()
		if d == '+':
			list.append(e)
			if len(list) > b:
				value = False
		elif e not in list:
			value = False
		else:
			list.remove(e)
	if value == True:
		print('Consistent')
	else:
		print('Inconsistent')


def func(q, m):
	a = []
	for i in range(q):
		(s, n) = input().split()
		if s == '+':
			a.append(n)
		elif s == '-':
			if n in a:
				a.remove(n)
			else:
				return ('Inconsistent', q - i)
		if len(a) > m:
			return ('Inconsistent', q - i)
	return ('Consistent', q - i)
t = int(input())
for _ in range(t):
	(n, m, q) = map(int, input().split())
	(out, i) = func(q, m)
	for _ in range(i - 1):
		x = input()
	print(out)