#include<iostream>
#define ll long long
#include<vector>
#include<algorithm>
using namespace std;
void solve() {
string s;
ll n, m;
cin >> n >> m;
ll x, y;
cin >> x >> y;
for (int i = 0; i < n; i++)
{
vector<char> v(m);
for (int i = 0; i < m; i++)
{
cin >> v[i];
}
ll countF = 0, countP = 0;
for (int i = 0; i < m; i++)
{
if (v[i] == 'P')
countP++;
if (v[i] == 'F')
countF++;
}
if (countF >= x)
s += "1";
else if (countF == x - 1 && countP >= y)
s += "1";
else
s += "0";
}
cout << s << "
";
}
int main()
{
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}