#include <iostream>
#include <cstdio>
using namespace std;

int eatChar(string &s, int l){
	if (!s.length())
		return 0;
	char c = s[0];
	s = s.substr(1, s.length() - 1);
	if (c == 'p'){
		int t = 0;
		for (int i = 0; i < 4; i++)
			t += eatChar(s, l / 2);
		return t;
	}
	if (c == 'e')
		return 0;
	if (c == 'f')
		return l * l;
}

int findValue(string &s1, string &s2, int l){
	if (!s1.length() && !s2.length())
		return 0;
	char c1 = s1[0];
	char c2 = s2[0];
	if (c1 == 'f' || c2 == 'f'){
		eatChar(s1, l);
		eatChar(s2, l);
		return l * l;
	}
	if (c1 == 'e' || c2 == 'e'){
		int t1 = eatChar(s1, l);
		int t2 = eatChar(s2, l);
		return max(t1, t2);
	}
	int t = 0;
	s1 = s1.substr(1, s1.length() - 1);
	s2 = s2.substr(1, s2.length() - 1);
	for (int i = 0; i < 4; i++)
		t += findValue(s1, s2, l / 2);
	return t;
}

int main(){
	int n;
	scanf("%d", &n);
	string s1, s2;
	while (n--){
		cin >> s1 >> s2;
		printf("There are %d black pixels.\n", findValue(s1, s2, 32));
	}
	return 0;
}
