#include <stdio.h>
#include <string.h>
using namespace std;
unsigned short S[300][1 << 16];
char A[300];
int main()
{
int n, i;
char type;
scanf("%d\n", &n);
while(n--)
{
gets(A);
int len = strlen(A);
unsigned short hash = 0, p_pow = 0;
if (A[0] == '+')
{
for(i = 1, len--; i < len; i++)
{
hash += (A[i] - 'a') << p_pow;
p_pow += 2;
S[i][hash]++;
}
}
else
{
for(i = 1; i < len; i++)
{
hash += (A[i] - 'a') << p_pow;
p_pow += 2;
}
printf("%d\n", (int)S[len - 1][hash]);
}
}
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnVuc2lnbmVkIHNob3J0IFNbMzAwXVsxIDw8IDE2XTsKY2hhciBBWzMwMF07CgppbnQgbWFpbigpCnsKCWludCBuLCBpOwoJY2hhciB0eXBlOwoJc2NhbmYoIiVkXG4iLCAmbik7CgoJd2hpbGUobi0tKSAKCXsKCQlnZXRzKEEpOwoJCWludCBsZW4gPSBzdHJsZW4oQSk7CgoJCXVuc2lnbmVkIHNob3J0IGhhc2ggPSAwLCBwX3BvdyA9IDA7CgkJaWYgKEFbMF0gPT0gJysnKSAKCQl7CgkJCWZvcihpID0gMSwgbGVuLS07IGkgPCBsZW47IGkrKykgCgkJCXsKCQkJCWhhc2ggKz0gKEFbaV0gLSAnYScpIDw8IHBfcG93OwoJCQkJcF9wb3cgKz0gMjsKCQkJCVNbaV1baGFzaF0rKzsKCQkJfQoJCX0gCgkJZWxzZSAKCQl7CgkJCWZvcihpID0gMTsgaSA8IGxlbjsgaSsrKSAKCQkJewoJCQkJaGFzaCArPSAoQVtpXSAtICdhJykgPDwgcF9wb3c7CgkJCQlwX3BvdyArPSAyOwoJCQl9CgkJCXByaW50ZigiJWRcbiIsIChpbnQpU1tsZW4gLSAxXVtoYXNoXSk7CgkJfQoJfQp9