#include
"cstdio"
#include
"cstring"
#include
"iostream"
#include
"cmath"
#include
"cstring"
#include
"cstring"
#include
"cstdio"
#pragma
warning(disable:4996)
const
int
len
=
32;//边长
const
int
maxn
=
1024
+
10;
char
s[maxn];
int
buf[len][len],
cnt;//指针
//
s是读入的字符串序列,p当前正在读的字符串的下标,r是纵坐标,c是横坐标,w是当前块的大小,从len开始,深度+1,w/=2.
void
draw(const
char*
s,
int&
p,
int
r,
int
c,
int
w)
{
char
ch
=
s[p++];
if
(ch
==
'p')
{//灰色,读取子树
draw(s,
p,
r,
c
+
w
/
2,
w
/
2); //块1
draw(s,
p,
r,
c,
w
/
2); //块2
draw(s,
p,
r
+
w
/
2,
c,
w
/
2); //块3
draw(s,
p,
r
+
w
/
2,
c
+
w
/
2,
w
/
2);//块4
}
else
if
(ch
==
'f')
{//黑色
for
(int
i
=
r;
i
<
r
+
w;
i++)
{
for
(int
j
=
c;
j
<
c
+
w;
j++)
{
if
(buf[i][j]
==
0)
{
buf[i][j]
=
1;
cnt++;//黑块计数
}
}
}
}
}
int
main()
{
int
T;
scanf("%d",
&T);
while
(T--)
{
memset(buf,
0,
sizeof(buf));
cnt
=
0;
for
(int
i
=
0;
i
<
2;
i++)
{//读取两棵树,操作同一个buf,达到合并的目的
scanf("%s",
s);
int
p
=
0;
draw(s,
p,
0,
0,
len);
}
printf("%d",
cnt);
}
return
0;
}