Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type:   +  a_{i} — add non-negative integer a_{i} to the multiset. Note, that she has a multiset, thus there may be many occurrences of the same integer.   -  a_{i} — delete a single occurrence of non-negative integer a_{i} from the multiset. It's guaranteed, that there is at least one a_{i} in the multiset.  ? s — count the number of integers in the multiset (with repetitions) that match some pattern s consisting of 0 and 1. In the pattern, 0 stands for the even digits, while 1 stands for the odd. Integer x matches the pattern s, if the parity of the i-th from the right digit in decimal notation matches the i-th from the right digit of the pattern. If the pattern is shorter than this integer, it's supplemented with 0-s from the left. Similarly, if the integer is shorter than the pattern its decimal notation is supplemented with the 0-s from the left. 

For example, if the pattern is s = 010, than integers 92, 2212, 50 and 414 match the pattern, while integers 3, 110, 25 and 1030 do not.


-----Input-----

The first line of the input contains an integer t (1 ≤ t ≤ 100 000) — the number of operation Sonya has to perform.

Next t lines provide the descriptions of the queries in order they appear in the input file. The i-th row starts with a character c_{i} — the type of the corresponding operation. If c_{i} is equal to '+' or '-' then it's followed by a space and an integer a_{i} (0 ≤ a_{i} < 10^18) given without leading zeroes (unless it's 0). If c_{i} equals '?' then it's followed by a space and a sequence of zeroes and onse, giving the pattern of length no more than 18.

It's guaranteed that there will be at least one query of type '?'.

It's guaranteed that any time some integer is removed from the multiset, there will be at least one occurrence of this integer in it.


-----Output-----

For each query of the third type print the number of integers matching the given pattern. Each integer is counted as many times, as it appears in the multiset at this moment of time.


-----Examples-----
Input
12
+ 1
+ 241
? 1
+ 361
- 241
? 0101
+ 101
? 101
- 101
? 101
+ 4000
? 0

Output
2
1
2
1
1

Input
4
+ 200
+ 200
- 200
? 0

Output
1



-----Note-----

Consider the integers matching the patterns from the queries of the third type. Queries are numbered in the order they appear in the input.   1 and 241.  361.  101 and 361.  361.  4000.

Source: codeforces | Difficulty: MEDIUM
Tags: Data structures

Implementation


Solutions:
t = int(input())
d = [0] * 262143
convert = str.maketrans('0123456789', '0101010101')
for _ in range(t):
	(c, a) = input().split()
	if c == '?':
		print(d[int(a, 2)])
	else:
		d[int(a.translate(convert), 2)] += 1 if c == '+' else -1


n = int(input())
ans = [0] * 2 ** 18
trantab = str.maketrans('0123456789', '0101010101')
for i in range(n):
	(ch, s) = map(str, input().split())
	if ch == '+':
		ans[int(s.translate(trantab), 2)] += 1
	elif ch == '-':
		ans[int(s.translate(trantab), 2)] -= 1
	else:
		print(ans[int(s.translate(trantab), 2)])


t = str.maketrans('0123456789', '0101010101')
dct = {}
for _ in range(int(input())):
	(q, a) = input().split()
	if q == '+':
		c = int(a.translate(t))
		try:
			dct[c] += 1
		except:
			dct[c] = 1
	elif q == '-':
		c = int(a.translate(t))
		try:
			dct[c] -= 1
		except:
			dct[c] = 1
	else:
		c = int(a.translate(t))
		try:
			print(dct[c])
		except:
			print(0)


import random, math
from copy import deepcopy as dc
from bisect import bisect_left, bisect_right
T = str.maketrans('0123456789', '0101010101')

def solution(num):
	num = str(num)
	global T
	return num.translate(T)

def input_test():
	ma = [0] * 300000
	for _ in range(int(input())):
		q = list(input().strip().split(' '))
		if q[0] == '+':
			par = int(solution(q[1]), 2)
			ma[par] += 1
		elif q[0] == '-':
			par = int(solution(q[1]), 2)
			ma[par] -= 1
		else:
			par = int(q[1], 2)
			print(ma[par])

def test():
	pass
input_test()


from sys import stdin
(d, res, elem) = ({}, '', '0101010101')
a = lambda : stdin.readline().split()
for _ in range(int(stdin.readline())):
	(c, x) = map(str, a())
	if c != '?':
		x = [*x]
		x = [elem[int(y)] for (i, y) in enumerate(x)]
		x = ''.join(x)
	x = x[x.find('1'):]
	if c == '+':
		if d.get(x) == None:
			d[x] = 0
		d[x] += 1
	elif c == '-':
		d[x] -= 1
	elif d.get(x) == None:
		res += '0' + '\n'
	else:
		res += str(d[x]) + '\n'
print(res)


from sys import stdin

def main():
	cnt = [0] * 2 ** 18
	t = str.maketrans('0123456789', '0101010101')
	input()
	for (sign, s) in map(str.split, stdin):
		if sign == '?':
			print(cnt[int(s, 2)])
		else:
			cnt[int(s.translate(t), 2)] += 1 if sign == '+' else -1
main()


from sys import *

def mask(a):
	res1 = ''
	while a > 0:
		p = a % 10 % 2
		res1 += str(p)
		a //= 10
	res1 += '0' * (18 - len(res1))
	return res1[::-1]
di = dict()
t = int(stdin.readline())
for i in range(t):
	s = stdin.readline().split()
	if s[0] == '+':
		w = mask(int(s[1]))
		if di.get(w, -1) == -1:
			di[w] = 1
		else:
			di[w] += 1
	if s[0] == '-':
		w = mask(int(s[1]))
		di[w] -= 1
	if s[0] == '?':
		w = mask(int(s[1]))
		if di.get(w, -1) == -1:
			print('0')
		else:
			print(di[w])


def calc(v):
	t = ''
	for i in v:
		if i in '02468':
			t += '0'
		else:
			t += '1'
	return int(t, 2)
d = {}
for _ in range(int(input())):
	(a, b) = input().split()
	if a == '+':
		v = calc(b)
		d[v] = d.get(v, 0) + 1
	elif a == '-':
		v = calc(b)
		d[v] = d.get(v, 0) - 1
	else:
		print(d.get(int(b, 2), 0))


from collections import defaultdict
from sys import stdin
from sys import stdout
n = int(stdin.readline())
d = defaultdict(int)
for _ in range(n):
	(s, x) = stdin.readline().split()
	y = ''.join(['1' if c in ['1', '3', '5', '7', '9'] else '0' for c in x]).zfill(18)
	if s == '+':
		d[y] += 1
	elif s == '-':
		d[y] -= 1
	else:
		stdout.write(str(d[y]) + '\n')


import math
import collections
mp = collections.defaultdict(int)
for _ in range(int(input())):
	(c, x) = input().split()
	if c == '+':
		n = len(x)
		flag = ''
		for j in range(n - 1, -1, -1):
			if x[j] in '02468':
				flag = '0' + flag
			else:
				flag = '1' + flag
		mp[flag] += 1
	elif c == '-':
		n = len(x)
		flag = ''
		for j in range(n - 1, -1, -1):
			if x[j] in '02468':
				flag = '0' + flag
			else:
				flag = '1' + flag
		mp[flag] -= 1
	else:
		ans = 0
		while x and x[0] == '0':
			x = x[1:]
		if not x:
			x = '0'
		while len(x) < 19:
			ans += mp[x]
			x = '0' + x
		print(ans)


t = int(input())
dc = [0] * 2 ** 19
tt = str.maketrans('0123456789', '0101010101')
for i in range(0, t):
	st = input().split()
	if st[0] == '+':
		dc[int(st[1].translate(tt), 2)] += 1
	elif st[0] == '-':
		dc[int(st[1].translate(tt), 2)] -= 1
	else:
		mu = int(st[1], 2)
		print(dc[mu])


from sys import stdin
f = stdin
text = f.read().splitlines()
t = int(text[0])
counts = {}
numset = {}

def buildbinary(a):
	return int(''.join(map(str, [int(i) % 2 for i in a])), base=2)

def performaddition(a):
	patternrep = buildbinary(a)
	if patternrep not in counts:
		counts[patternrep] = 0
	counts[patternrep] += 1
	if a not in numset:
		numset[a] = 0
	numset[a] += 1

def performremove(a):
	numset[a] -= 1
	counts[buildbinary(a)] -= 1

def performquery(a):
	binq = int(a, base=2)
	mask = 2 ** len(a) - 1
	if binq not in counts:
		print(0)
	else:
		print(counts[binq])
for query in map(lambda x: x.split(), text[1:]):
	q = query[0]
	if q == '+':
		performaddition(query[1])
		pass
	if q == '-':
		performremove(query[1])
		pass
	if q == '?':
		performquery(query[1])
		pass


import math, sys, bisect, heapq
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
int1 = lambda x: int(x) - 1
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))
ilelec = lambda : map(int1, input().split())
alelec = lambda : list(map(int1, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])

class Tree:

	def __init__(self):
		self.children = ['0'] * 2
		self.count = 0

class Main:

	def __init__(self):
		self.root = self.getNode()

	def getNode(self):
		return Tree()

	def insert(self, s):
		head = self.root
		n = len(s)
		for i in range(n):
			x = int(s[i]) % 2
			if head.children[x] == '0':
				head.children[x] = self.getNode()
			head = head.children[x]
		head.count += 1

	def fun(self, s):
		head = self.root
		n = len(s)
		c = 0
		for i in range(n):
			x = int(s[i]) % 2
			if head.children[x] == '0':
				return c
			head = head.children[x]
			if head.count >= 1:
				if all((int(j) % 2 == 0 for j in s[i + 1:])):
					c += head.count
		x = 0
		while head.children[x] != '0':
			head = head.children[x]
			c += head.count
		return c

	def remove(self, s):
		head = self.root
		n = len(s)
		for i in range(n):
			x = int(s[i]) % 2
			if head.children[x] == '0':
				head.children[x] = self.getNode()
			head = head.children[x]
		head.count -= 1
		head.isEnd = False
t = Main()
N = int(input())
for i in range(N):
	S = input()
	if S[0] == '+':
		a = S[1:][::-1].strip()
		t.insert(a)
	elif S[0] == '-':
		a = S[1:][::-1].strip()
		t.remove(a)
	else:
		a = S[1:][::-1].strip()
		print(t.fun(a))


def convert(strVal):
	ls = list()
	for c in strVal:
		if ord(c) & 1:
			ls.append('1')
		else:
			ls.append('0')
	a = ''.join(ls)
	return int(a)
from collections import defaultdict
inputList = defaultdict(int)
inputNum = int(input())
for x in range(0, inputNum):
	inputStr = input()
	firstValue = inputStr[0]
	secondValue = inputStr[2:]
	if firstValue != '?':
		convertedValue = convert(secondValue)
	if firstValue == '+':
		inputList[convertedValue] += 1
	elif firstValue == '-':
		inputList[convertedValue] -= 1
	elif firstValue == '?':
		patString = int(secondValue)
		count = inputList[patString]
		print(count)


import sys, os, io
from sys import stdin, stdout

def binaryToDecimal(n):
	num = n
	dec_value = 0
	base1 = 1
	len1 = len(num)
	for i in range(len1 - 1, -1, -1):
		if num[i] == '1':
			dec_value += base1
		base1 = base1 * 2
	return dec_value

def convert(n):
	ss = []
	for i in n:
		ss.append(str(int(i) & 1))
	return binaryToDecimal(ss)
t = stdin.readline()
d = {}
ab = [0] * 262145
for _ in range(int(t)):
	(a, b) = map(str, sys.stdin.readline().strip().split())
	if a == '+':
		c = convert(b)
		ab[c] += 1
		b = int(b)
		if b not in d:
			d[b] = 0
		d[b] += 1
	elif a == '-':
		c = convert(b)
		ab[c] -= 1
		b = int(b)
		if d[b] == 1:
			d.pop(b)
		else:
			d[b] -= 1
	else:
		b = binaryToDecimal(b)
		print(ab[b])


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
from collections import defaultdict
from itertools import permutations
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def convert_num(number):
	number_list = list(map(int, number))
	res = ''.join((str(d & 1) for d in number_list))
	return '0' * (18 - len(res)) + res

def convert_pattern(pattern):
	return '0' * (18 - len(pattern)) + pattern
t = int(input())
multiset = defaultdict(int)
while t:
	t -= 1
	(op, item) = input().split()
	if op == '+':
		multiset[convert_num(item)] += 1
	elif op == '-':
		multiset[convert_num(item)] -= 1
	else:
		print('%d\n' % multiset[convert_pattern(item)])


from sys import stdin
from sys import stdout
from collections import defaultdict
r = set('02468')

def main():
	n = int(stdin.readline())
	a = defaultdict(int)
	for _ in range(n):
		(command, x) = stdin.readline().strip().split(' ')
		m = mask(x)
		if command == '+':
			a[m] += 1
		if command == '-':
			a[m] -= 1
		if command == '?':
			stdout.write(str(a[m]) + '\n')
			stdout.flush()

def mask(n):
	result = ''
	for x in n:
		if x in r:
			result += '0'
		else:
			result += '1'
	return int(result)
main()


from sys import stdout, stdin
d = {}
for _ in range(int(input())):
	t = stdin.readline()
	t = str(t)
	s = t[0]
	n = t[2:]
	b = '0' * (18 - (len(n) - 1))
	for i in n:
		if i != '\n':
			if int(i) % 2 == 0:
				b += '0'
			else:
				b += '1'
	if s == '+':
		if b in d:
			d[b] += 1
		else:
			d[b] = 1
	elif s == '-':
		d[b] -= 1
	elif b in d:
		stdout.write(str(d[b]))
		print()
	else:
		print(0)


from collections import defaultdict
import sys
numbers = defaultdict(int)
sys.stdin.readline()
for line in sys.stdin:
	(operation, operator) = line.split()
	operator = ''.join(['1' if char in ['1', '3', '5', '7', '9'] else '0' for char in operator]).zfill(18)
	if operation == '+':
		numbers[operator] += 1
	elif operation == '-':
		numbers[operator] -= 1
	else:
		print(numbers[operator])


t = int(input())
T = str.maketrans('0123456789', '0101010101')
d = {}
for _ in ' ' * t:
	(a, b) = input().split()
	b = int(b.translate(T))
	if a == '?':
		print(d.get(b, 0))
	elif a == '+':
		d[b] = d.get(b, 0) + 1
	else:
		d[b] -= 1


t = str.maketrans('0123456789', '0101010101')
C = (1 << 18) * [0]
for _ in range(int(input())):
	(c, a) = input().split()
	if '?' == c:
		print(C[int(a, 2)])
	else:
		C[int(a.translate(t), 2)] += 1 if '-' != c else -1


t = int(input())
T = str.maketrans('0123456789', '0101010101')
l = [0] * 300000
for _ in ' ' * t:
	(a, b) = input().split()
	if a == '?':
		print(l[int(b, 2)])
	else:
		l[int(b.translate(T), 2)] += 1 if a == '+' else -1


from sys import stdin
from sys import stdout
from collections import defaultdict
r = set('02468')

def main():
	n = int(stdin.readline())
	a = defaultdict(int)
	for i in range(n):
		(op, x) = stdin.readline().split()
		m = ''
		for c in x:
			if c in r:
				m += '0'
			else:
				m += '1'
		m = int(m)
		if op == '?':
			stdout.write(str(a[m]) + '\n')
			stdout.flush()
		elif op == '+':
			a[m] += 1
		elif op == '-':
			a[m] -= 1
main()


from collections import defaultdict
from sys import stdin
inp = stdin.readline

def convert_num(number):
	number_list = list(map(int, number))
	res = ''.join((str(d & 1) for d in number_list))
	return '0' * (18 - len(res)) + res

def convert_pattern(pattern):
	return '0' * (18 - len(pattern)) + pattern
t = int(inp())
multiset = defaultdict(int)
while t:
	t -= 1
	(op, item) = inp().split()
	if op == '+':
		multiset[convert_num(item)] += 1
	elif op == '-':
		multiset[convert_num(item)] -= 1
	else:
		print(multiset[convert_pattern(item)])


LVL = 18
from collections import defaultdict

def pattern_repr(x):
	rep = [1 if int(x) % 2 else 0 for x in x]
	return [0] * (LVL - len(rep)) + rep

class Node:

	def __init__(self, key, node_id=0):
		self.key = key
		self.node_id = node_id
		self.left = None
		self.right = None

class CodeforcesTask713ASolution:

	def __init__(self):
		self.result = ''
		self.t = 0
		self.queries = []

	def read_input(self):
		self.t = int(input())
		for _ in range(self.t):
			self.queries.append(input().split(' '))

	def process_task(self):
		res = []
		root = Node(0, 1)
		node_id = 2
		treesol = False
		if treesol:
			for query in self.queries:
				if query[0] in '+-':
					pattern = pattern_repr(query[1])
					current = root
					while pattern:
						if pattern[0]:
							if current.right:
								current = current.right
							else:
								current.right = Node(0, node_id)
								current = current.right
								node_id += 1
						elif current.left:
							current = current.left
						else:
							current.left = Node(0, node_id)
							current = current.left
							node_id += 1
						pattern = pattern[1:]
					current.key += 1 if query[0] == '+' else -1
				else:
					pattern = [int(x) for x in '0' * (LVL - len(query[1])) + query[1]]
					current = root
					while pattern:
						if pattern[0]:
							if current.right:
								current = current.right
							else:
								current = Node(0)
								pattern = []
						elif current.left:
							current = current.left
						else:
							current = Node(0)
							pattern = []
						pattern = pattern[1:]
					res.append(current.key)
		else:
			counts = defaultdict(int)
			for query in self.queries:
				if query[0] in '+-':
					pattern = '0' * (LVL - len(query[1])) + ''.join(('1' if int(x) % 2 else '0' for x in query[1]))
					counts[pattern] += 1 if query[0] == '+' else -1
				else:
					pattern = '0' * (LVL - len(query[1])) + query[1]
					res.append(counts[pattern])
		self.result = '\n'.join([str(x) for x in res])

	def get_result(self):
		return self.result
Solution = CodeforcesTask713ASolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


import sys

def count_mask(val):
	val = val[::-1]
	mask = ''
	for i in val:
		mask += str(int(i) % 2)
	while len(mask) < 18:
		mask += '0'
	return mask[::-1]
n = int(sys.stdin.readline())
d = dict()
for i in range(n):
	(zn, val) = sys.stdin.readline().split()
	if zn == '+':
		mask = count_mask(val)
		try:
			d[mask] += 1
		except:
			d[mask] = 0
			d[mask] += 1
	if zn == '-':
		mask = count_mask(val)
		d[mask] -= 1
	if zn == '?':
		mask = val[::-1]
		while len(mask) < 18:
			mask += '0'
		mask = mask[::-1]
		try:
			sys.stdout.write(str(d[mask]))
			sys.stdout.write('\n')
		except:
			sys.stdout.write('0')
			sys.stdout.write('\n')


from collections import defaultdict
from sys import stdin, stdout

def convertNum(val):
	digs = list(map(int, val))
	res = ''.join((str(d & 1) for d in digs))
	return '0' * (18 - len(res)) + res

def convertPat(pat):
	return '0' * (18 - len(pat)) + pat
cnt = defaultdict(int)
for _ in range(int(stdin.readline())):
	op = stdin.readline().split()
	if op[0] == '+':
		cnt[convertNum(op[1])] += 1
	elif op[0] == '-':
		cnt[convertNum(op[1])] -= 1
	elif op[0] == '?':
		stdout.write('%d\n' % cnt[convertPat(op[1])])
	else:
		raise Exception


def pattern_of_number(n):
	pattern = ''
	p = 10 ** 17
	for i in range(18):
		pattern += '0' if n // p % 2 == 0 else '1'
		p //= 10
	return pattern

def solve():
	pattern_dict = {}
	t = int(input())
	for i in range(t):
		query = input()
		if query[0] == '+':
			number = int(query[2:])
			pattern = pattern_of_number(number)
			if pattern in pattern_dict:
				pattern_dict[pattern] += 1
			else:
				pattern_dict[pattern] = 1
		elif query[0] == '-':
			number = int(query[2:])
			pattern = pattern_of_number(number)
			if pattern_dict[pattern] > 1:
				pattern_dict[pattern] -= 1
			else:
				pattern_dict.pop(pattern)
		else:
			pattern = query[2:].strip()
			actual_pattern = '0' * (18 - len(pattern)) + pattern
			if actual_pattern in pattern_dict:
				print(pattern_dict[actual_pattern])
			else:
				print(0)
solve()


n = int(input())
d = {}

def get_mask(num):
	res = ''
	for el in num:
		if int(el) & 1:
			res += '1'
		else:
			res += '0'
	return '0' * (18 - len(num)) + res
for _ in range(n):
	(c, v) = input().split(' ')
	if c == '?':
		v = '0' * (18 - len(v)) + v
		if d.get(v) != None:
			print(d[v])
		else:
			print(0)
	elif c == '+':
		v = get_mask(v)
		if d.get(v) != None:
			d[v] += 1
		else:
			d[v] = 1
	else:
		v = get_mask(v)
		d[v] -= 1


import sys
from collections import Counter
from sys import stdin
input()
c = [0] * 2 ** 18
deg = [0] * 18
for i in range(18):
	deg[i] = 2 ** i
t = str.maketrans('0123456789', '0101010101')
for (ch, n) in map(str.split, stdin):
	if ch == '?':
		print(c[int(n, 2)])
	n = n.translate(t)
	if ch == '+':
		c[int(n, 2)] += 1
	if ch == '-':
		c[int(n, 2)] -= 1


from sys import stdin, stdout

def fin():
	return stdin.readline().strip()

def fout(x):
	stdout.write(str(x) + '\n')

def getKey(snum):
	resB = []
	for i in snum:
		if int(i) & 1:
			resB.append('1')
		else:
			resB.append('0')
	return int(''.join(map(str, resB)), 2)

def b2d(snum):
	return int(snum, 2)
dic = {}
for _ in range(int(fin())):
	num = 0
	(op, snum) = map(str, fin().split())
	if op == '+':
		k = getKey(snum)
		dic[k] = dic.get(k, 0) + 1
	elif op == '-':
		k = getKey(snum)
		if k in dic:
			if dic[k] == 1:
				dic.pop(k)
			else:
				dic[k] -= 1
	else:
		k = b2d(snum)
		if k in dic:
			fout(dic[k])
		else:
			fout(0)


num = int(input())
multiset = [0] * 2 ** 18
t = str.maketrans('0123456789', '0101010101')
while num:
	opr = input().split()
	if opr[0] == '+':
		multiset[int(opr[1].translate(t), 2)] += 1
	elif opr[0] == '-':
		multiset[int(opr[1].translate(t), 2)] -= 1
	elif opr[0] == '?':
		print(multiset[int(opr[1], 2)])
	num -= 1


import sys

def solve():
	d = dict()
	n = int(sys.stdin.readline().strip())
	ans = ''
	for line in sys.stdin:
		(op, i) = line.strip().split(' ')
		m = ''.join(['1' if char in ['1', '3', '5', '7', '9'] else '0' for char in i]).zfill(18)
		if op == '+':
			d.setdefault(m, 0)
			d[m] += 1
		if op == '-':
			d[m] -= 1
		if op == '?':
			ans += '{:d}\n'.format(d.get(m, 0))
	return ans
ans = solve()
print(ans)


present = {}
coded = {}
cc = {}

def encode(s):
	a = ''
	for i in range(len(s)):
		if int(s[i]) % 2 == 0:
			a += '0'
		else:
			a += '1'
	x = ''
	for i in range(18 - len(a)):
		x += '0'
	x += a
	return x

def add(num):
	present[num] = present.get(num, 0) + 1
	x = encode(num)
	cc[num] = x
	coded[x] = coded.get(x, 0) + 1

def delete(num):
	present[num] -= 1
	coded[cc[num]] -= 1

def query(patt):
	x = ''
	for i in range(18 - len(patt)):
		x += '0'
	x = x + patt
	if x in coded:
		print(coded[x])
	else:
		print(0)
t = int(input())
for q in range(t):
	(ty, i) = input().split()
	if ty == '+':
		add(i)
	if ty == '-':
		delete(i)
	if ty == '?':
		query(i)


n = int(input())
a = []
wk1 = '0' * 18
rules = str.maketrans('0123456789', '0101010101')
trans = lambda x: str.translate(x, rules)
d = {}
for _ in range(n):
	(x, y) = input().split()
	y = int(trans(y), 2)
	if x == '+':
		d[y] = d.get(y, 0) + 1
	elif x == '-':
		d[y] -= 1
	elif x == '?':
		print(d.get(y, 0))


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 10 ** 9 + 7
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]

def getID(n):
	n = int(n)
	s = []
	for i in range(18):
		here = n % 10
		n //= 10
		s.append(str(here % 2))
	return ''.join(s)[::-1]
have = defaultdict(int)
for _ in range(Int()):
	(t, n) = input().split()
	if t == '+':
		have[getID(n)] += 1
	elif t == '-':
		have[getID(n)] -= 1
	else:
		n = '0' * (18 - len(n)) + n
		print(have[n])


from sys import *
odd = set(['1', '9', '3', '5', '7'])

def mask(a):
	res = '0' * (18 - len(a))
	for i in a:
		if i in odd:
			res += '1'
		else:
			res += '0'
	return res
di = dict()
t = int(stdin.readline())
for i in range(t):
	s = stdin.readline().split()
	if s[0] == '+':
		w = mask(s[1])
		if di.get(w, -1) == -1:
			di[w] = 1
		else:
			di[w] += 1
	if s[0] == '-':
		w = mask(s[1])
		di[w] -= 1
	if s[0] == '?':
		w = mask(s[1])
		if di.get(w, -1) == -1:
			print('0')
		else:
			print(di[w])


t = int(input())
rules = str.maketrans('0123456789', '0101010101')
trans = lambda x: str.translate(x, rules)
(cnt, res) = ({}, [])
for _ in range(t):
	(op, n) = input().split()
	n = int(trans(n), 2)
	if op == '+':
		cnt[n] = cnt.get(n, 0) + 1
	elif op == '-':
		cnt[n] -= 1
	else:
		res.append(str(cnt.get(n, 0)))
print('\n'.join(res))


import sys
import re

def mask2(s):
	m = int('0', 2)
	while len(s) > 0:
		m *= 2
		m += int(s[0]) % 2
		s = s[1:]
	return m

def mask(s):
	return int(re.sub('[02468]', '0', re.sub('[13579]', '1', s)), 2)

def solve():
	d = dict()
	n = int(sys.stdin.readline().strip())
	ans = ''
	for line in sys.stdin:
		(op, i) = line.strip().split(' ')
		m = mask(i)
		if op == '+':
			d.setdefault(m, 0)
			d[m] += 1
		if op == '-':
			d[m] -= 1
		if op == '?':
			ans += '{:d}\n'.format(d.get(m, 0))
	return ans
ans = solve()
print(ans)


from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

def input():
	return sys.stdin.readline()

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())
mp = defaultdict(int)

def key(x):
	res = 0
	for i in range(len(x)):
		res = 2 * res + int(x[i]) % 2
	return res
for _ in range(int(input())):
	a = input().strip().split()
	if a[0] == '+':
		mp[key(a[1])] += 1
	elif a[0] == '-':
		mp[key(a[1])] -= 1
		pass
	else:
		print(mp[key(a[1])])


from collections import defaultdict

class trie:

	def __init__(self):
		(self.nodes1, self.nodes2) = (None, None)
		(self.count1, self.count2) = (0, 0)

	def add(self, s, i):
		if i >= len(s):
			return
		md = int(s[i]) % 2
		if md == 0:
			if not self.nodes1:
				self.nodes1 = trie()
			self.count1 += 1
			self.nodes1.add(s, i + 1)
		else:
			if not self.nodes2:
				self.nodes2 = trie()
			self.count2 += 1
			self.nodes2.add(s, i + 1)

	def remove(self, s, i):
		if i >= len(s):
			return
		md = int(s[i]) % 2
		if md == 0:
			self.count1 -= 1
			self.nodes1.remove(s, i + 1)
			if self.count1 == 0:
				self.nodes1 = None
		else:
			self.count2 -= 1
			self.nodes2.remove(s, i + 1)
			if self.count2 == 0:
				self.nodes2 = None

	def search(self, s, i, mn):
		if i >= len(s):
			return mn
		md = int(s[i]) % 2
		if md == 0:
			if self.nodes1:
				return self.nodes1.search(s, i + 1, min(mn, self.count1))
			else:
				return 0
		elif self.nodes2:
			return self.nodes2.search(s, i + 1, min(mn, self.count2))
		else:
			return 0
t = int(input())
st = set('02468')
mp = defaultdict(int)
res = []
while t > 0:
	t -= 1
	(c, s) = input().split()
	if c == '+':
		ss = ''
		for i in s:
			if i in st:
				ss += '0'
			else:
				ss += '1'
		mp[int(ss, 2)] += 1
	elif c == '-':
		ss = ''
		for i in s:
			if i in st:
				ss += '0'
			else:
				ss += '1'
		mp[int(ss, 2)] -= 1
	elif c == '?':
		res.append(mp[int(s, 2)])
print(*res, sep='\n')


t = int(input())
trantab = str.maketrans('0123456789', '0101010101')
a = {}
for i in range(t):
	string = input()
	(oper, number) = string.split()
	pattern = int(number.translate(trantab))
	if oper == '+':
		a[pattern] = a.get(pattern, 0) + 1
	elif oper == '-':
		a[pattern] -= 1
		if not a[pattern]:
			del a[pattern]
	elif pattern in a:
		print(a[pattern])
	else:
		print(0)


from sys import stdin
t = int(input())
diction = dict()
for i in range(t):
	(n, m) = stdin.readline().strip().split()
	string = '0' * (20 - len(m))
	for i in m:
		if int(i) % 2:
			string += '1'
		else:
			string += '0'
	if n == '+':
		if string in diction:
			diction[string] += 1
		else:
			diction[string] = 1
	if n == '-':
		diction[string] -= 1
	if n == '?':
		if string in diction:
			print(diction[string])
		else:
			print(0)


from sys import stdin, exit, setrecursionlimit
setrecursionlimit(10000000)
from math import *
from bisect import bisect_left
from collections import deque
input = stdin.readline
lmi = lambda : list(map(int, input().split()))
mi = lambda : map(int, input().split())
si = lambda : input().strip('\n')
ssi = lambda : input().strip('\n').split()

def conv(b):
	news = ''
	for j in range(18 - len(b)):
		news += '0'
	for j in range(len(b)):
		if int(b[j]) % 2 == 0:
			news += '0'
		else:
			news += '1'
	return news
mp = {}
for _ in range(int(input())):
	(a, b) = ssi()
	if a == '+':
		news = conv(b)
		if news not in mp:
			mp[news] = 0
		mp[news] += 1
	elif a == '-':
		tmp = conv(b)
		mp[tmp] -= 1
		if mp[tmp] == 0:
			del mp[tmp]
	else:
		b = (18 - len(b)) * '0' + b
		if b not in mp:
			print(0)
		else:
			print(mp[b])


from sys import stdin, stdout

def readline():
	return stdin.readline().rstrip()

def writeline(s):
	stdout.write(str(s) + '\n')
n = int(readline())
d = {}
for _ in range(n):
	(op, s) = readline().split()
	patt = ''.join((str(int(c) % 2) for c in s))
	padnum = '{:018}'.format(int(patt))
	if op == '+':
		d[padnum] = d.get(padnum, 0) + 1
	elif op == '-':
		d[padnum] -= 1
	else:
		writeline(d.get(padnum, 0))


def get_pattern_from_number(number):
	pattern = ''
	for i in number:
		if i in '02468':
			pattern += '0'
		else:
			pattern += '1'
	return int(pattern)
storage = {}
for _ in range(int(input())):
	(query, number) = input().split()
	if query == '+':
		pattern = get_pattern_from_number(number)
		storage[pattern] = storage.get(pattern, 0) + 1
	if query == '-':
		pattern = get_pattern_from_number(number)
		storage[pattern] = storage.get(pattern, 0) - 1
	if query == '?':
		print(storage.get(int(number), 0))


from sys import stdin, stdout
from collections import defaultdict
input()
d = defaultdict(int)
regex = str.maketrans('0123456789', '0101010101')
for line in stdin.readlines():
	(typ, val) = line.split()
	if typ == '?':
		print(d[int(val, 2)])
	else:
		val = int(val.translate(regex), 2)
		if typ == '+':
			d[val] += 1
		else:
			d[val] -= 1


import sys
import re

def mask2(s):
	m = int('0', 2)
	while len(s) > 0:
		m *= 2
		m += int(s[0]) % 2
		s = s[1:]
	return m

def mask(s):
	return ''.join(['1' if char in ['1', '3', '5', '7', '9'] else '0' for char in s]).zfill(18)

def solve():
	d = dict()
	n = int(sys.stdin.readline().strip())
	ans = ''
	for line in sys.stdin:
		(op, i) = line.strip().split(' ')
		m = mask(i)
		if op == '+':
			d.setdefault(m, 0)
			d[m] += 1
		if op == '-':
			d[m] -= 1
		if op == '?':
			ans += '{:d}\n'.format(d.get(m, 0))
	return ans
ans = solve()
print(ans)


import sys
import math
import collections
import heapq
input = sys.stdin.readline
d = {}
t = int(input())
for w in range(t):
	(x, y) = (i for i in input().split())
	y = list(y)
	k = len(y)
	for i in range(k):
		if int(y[i]) % 2 == 0:
			y[i] = '0'
		else:
			y[i] = '1'
	y = ''.join(y)
	if k < 30:
		y = '0' * (30 - k) + y
	if x == '+':
		if y in d:
			d[y] += 1
		else:
			d[y] = 1
	elif x == '-':
		d[y] -= 1
	elif y in d:
		print(d[y])
	else:
		print(0)


import math
from collections import *
import sys
from functools import reduce
import time
from itertools import groupby

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

def get_list():
	return list(get_ints())

def get_string():
	return list(input().strip().split())

def printxsp(*args):
	return print(*args, end='')

def printsp(*args):
	return print(*args, end=' ')
DIRECTIONS = [(+0, +1), (+0, -1), (+1, +0), (+1, -1)]
NEIGHBOURS = [(-1, -1), (-1, +0), (-1, +1), (+0, -1), (+1, +1), (+1, +0), (+1, -1), (+0, +1)]
n = int(input())
d = defaultdict(int)
oddDig = '13579'
evenDig = '02468'
for __ in range(n):
	(a, b) = input().split()
	if a in '+-':
		thisPattern = ''
		for i in b:
			if i in evenDig:
				thisPattern += '0'
			else:
				thisPattern += '1'
		thisPattern = thisPattern.rjust(18, '0')
		if a == '+':
			d[thisPattern] += 1
		else:
			d[thisPattern] -= 1
	else:
		b = b.rjust(18, '0')
		print(d[b])


from sys import stdin

def main():
	cnt = [0] * 2 ** 18
	t = str.maketrans('0123456789', '0101010101')
	(_, *l) = stdin.read().splitlines()
	for (sign, s) in map(str.split, l):
		if sign == '?':
			print(cnt[int(s, 2)])
		else:
			cnt[int(s.translate(t), 2)] += 1 if sign == '+' else -1
main()


import itertools
import bisect
import math
from collections import *
import os
import sys
from io import BytesIO, IOBase
ii = lambda : int(input())
lmii = lambda : list(map(int, input().split()))
li = lambda : list(input())
mii = lambda : map(int, input().split())
msi = lambda : map(str, input().split())

def main():
	t = ii()
	d = defaultdict(int)
	for test in range(t):
		s = input()
		sign = s[0]
		ss = s[2:]
		ln = len(ss)
		num = list('0' * (19 - ln) + ss)
		for i in range(len(num)):
			num[i] = str(int(num[i]) % 2 != 0)
		num = ''.join(num)
		if sign == '+':
			d[num] += 1
		elif sign == '-':
			d[num] -= 1
		else:
			print(d[num])
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import math
from collections import defaultdict
q = int(input())
res = defaultdict(int)

def calc(v):
	par = ''
	vl = len(v)
	for i in range(vl):
		if v[i] in '02468':
			par += '0'
		else:
			par += '1'
	return par
qq = []
for j in range(q):
	qq.append(list(map(str, input().split())))
for i in qq:
	(o, v) = (i[0], i[1])
	if o == '+':
		res[calc(v)] += 1
	elif o == '-':
		res[calc(v)] -= 1
	else:
		ans = 0
		while v and v[0] == '0':
			v = v[1:]
		if not v:
			v = '0'
		vl = len(v)
		while vl < 19:
			ans += res[v]
			v = '0' + v
			vl += 1
		print(ans)


from sys import stdin, stdout
quests = int(stdin.readline().rstrip())
multi_set = {}
p = str.maketrans('0123456789', '0101010101')
for i in range(quests):
	(quest, core) = stdin.readline().rstrip().split()
	pattern = int(core.translate(p))
	if quest == '+':
		if pattern in multi_set.keys():
			multi_set[pattern] += 1
		else:
			multi_set[pattern] = 1
	elif quest == '-':
		multi_set[pattern] -= 1
	elif pattern in multi_set:
		stdout.write(str(multi_set[pattern]) + '\n')
	else:
		stdout.write('0\n')


cnt = [0] * 262200
trans = str.maketrans('0123456789', '0101010101')
t = int(input())
for _ in range(t):
	(o, a) = input().split()
	if o == '+':
		cnt[int(a.translate(trans), 2)] += 1
	elif o == '-':
		cnt[int(a.translate(trans), 2)] -= 1
	else:
		print(cnt[int(a, 2)])


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

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

def si():
	return input()

def mi():
	return map(str, input().split())

def li():
	return list(mi())

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
mod = 1000000007
import math

def main():
	t = ii()
	di = {}
	for _ in range(t):
		(c, a) = mi()
		s = ''
		for i in range(len(a)):
			s += str(int(a[i]) % 2)
		d = 18 - len(a)
		s = d * '0' + s
		if c == '+':
			if s in di:
				di[s] += 1
			else:
				di[s] = 1
		elif c == '-':
			di[s] -= 1
		else:
			d = 18 - len(a)
			a = d * '0' + a
			if a in di:
				print(di[a])
			else:
				print(0)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
ans = [0] * 2 ** 18
y = str.maketrans('0123456789', '0101010101')
for i in range(t):
	(x, s) = map(str, input().split())
	if x == '+':
		ans[int(s.translate(y), 2)] += 1
	elif x == '-':
		ans[int(s.translate(y), 2)] -= 1
	else:
		print(ans[int(s.translate(y), 2)])


t = int(input())
d = dict()
rule = str.maketrans('0123456789', '0101010101')
trans = lambda x: str.translate(x, rule)
for i in range(t):
	(x, y) = map(str, input().split())
	obj = int(trans(y), 2)
	if x == '+':
		d[obj] = d.get(obj, 0) + 1
	elif x == '-':
		d[obj] -= 1
	else:
		print(d.get(obj, 0))