#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
using namespace std;

struct Info{
	Info(){
		reg_open = reg_close = cur_open = cur_close = sq_open = sq_close = dot_num = 0;
	}
	int reg_open,reg_close,cur_open,cur_close,sq_open,sq_close,dot_num;
};

struct RCS{
	RCS(){
		R = C = S = -1;
	}
	int R,C,S;
};

int sample_line,do_line;

Info parseLine(char buf[]){
	Info data;

	for(int i = 0; buf[i] == '.'; i++)data.dot_num++;

	for(int i = 0;buf[i] != '\0'; i++){
		switch(buf[i]){
		case '.':
			//Do nothing
			break;
		case '(':
			data.reg_open++;
			break;
		case ')':
			data.reg_close++;
			break;
		case '{':
			data.cur_open++;
			break;
		case '}':
			data.cur_close++;
			break;
		case '[':
			data.sq_open++;
			break;
		case ']':
			data.sq_close++;
			break;
		}
	}
	return data;
}

void func(){
	Info info[sample_line];
	Info tmp;

	char buf[100];

	scanf("%s",buf);

	tmp = parseLine(buf);

	info[0].reg_open += tmp.reg_open;
	info[0].reg_close += tmp.reg_close;
	info[0].cur_open += tmp.cur_open;
	info[0].cur_close += tmp.cur_close;
	info[0].sq_open += tmp.sq_open;
	info[0].sq_close += tmp.sq_close;

	for(int i = 1; i < sample_line;i++){
		scanf("%s",buf);

		tmp = parseLine(buf);
		info[i].dot_num = tmp.dot_num;

		info[i].reg_open = info[i-1].reg_open + tmp.reg_open;
		info[i].reg_close = info[i-1].reg_close + tmp.reg_close;
		info[i].cur_open = info[i-1].cur_open+tmp.cur_open;
		info[i].cur_close = info[i-1].cur_close + tmp.cur_close;
		info[i].sq_open = info[i-1].sq_open + tmp.sq_open;
		info[i].sq_close = info[i-1].sq_close + tmp.sq_close;
	}

	RCS candidate[8001];
	int index = 0;
	bool FLG;

	for(int r = 1; r <= 20; r++){
		for(int c = 1; c <= 20; c++){
			for(int s = 1; s <= 20; s++){
				FLG = true;
				for(int line = 1; line <= sample_line-1; line++){
					if(info[line].dot_num != r*(info[line-1].reg_open-info[line-1].reg_close)+c*(info[line-1].cur_open-info[line-1].cur_close)
							+s*(info[line-1].sq_open-info[line-1].sq_close)){
						FLG = false;
						break;
					}
				}
				if(FLG){
					candidate[index].R = r;
					candidate[index].C = c;
					candidate[index].S = s;
					index++;
				}
			}
		}
	}

	int line_ans,tmp_ans;
	Info new_info;

	scanf("%s",buf);

	new_info = parseLine(buf);

	printf("0");

	for(int i = 1; i < do_line; i++){
		line_ans = BIG_NUM;
		for(int k = 0; k < index; k++){
			tmp_ans = candidate[k].R*(new_info.reg_open-new_info.reg_close) + candidate[k].C*(new_info.cur_open-new_info.cur_close)
					+candidate[k].S*(new_info.sq_open-new_info.sq_close);
			if(line_ans == BIG_NUM || line_ans == tmp_ans){
				line_ans = tmp_ans;
			}else{
				line_ans = -1;
			}
		}
		if(line_ans == BIG_NUM)line_ans = -1;
		printf(" %d",line_ans);

		scanf("%s",buf);

		tmp = parseLine(buf);

		new_info.reg_open += tmp.reg_open;
		new_info.reg_close += tmp.reg_close;
		new_info.cur_open += tmp.cur_open;
		new_info.cur_close += tmp.cur_close;
		new_info.sq_open += tmp.sq_open;
		new_info.sq_close += tmp.sq_close;
	}
	printf("\n");
}

int main(){

	while(true){
		scanf("%d %d",&sample_line,&do_line);
		if(sample_line == 0 && do_line == 0)break;

		func();
	}

	return 0;
}

Measured memory_bytes: 2676