#include <iostream>
#include <string>
#include <fstream>
#include <map>
#include <vector>
using namespace std;
#define min(a, b) (a) < (b) ? (a) : (b)
#define max(a, b) (a) > (b) ? (a) : (b)
int ans = 0;
void dfs(int cnt, const vector<int> &v, const vector<vector<string> > &str, int n, int m, int l, int s, map<string, bool> map1, int dep, int nandu, int max1, int min1)
{
if(cnt == m)
{
if(max1 - min1 >= s && nandu <= l)
ans++;
return;
}
if(dep >= n)
return;
for(int i=dep; i<n; i++)
{
bool ok = true;
int j = 0;
for(j=0; j<str[i].size(); j++)
{
if(map1[str[i][j]])
{
ok = false;
break;
}
map1[str[i][j]] = true;
}
if(ok && nandu+v[i] <= l)
{
int premin1 = min1;
int premax1 = max1;
max1 = max(max1, v[i]);
min1 = min(min1, v[i]);
dfs(cnt+1, v, str, n, m, l, s, map1, i+1, nandu+v[i], max1, min1);
min1 = premin1;
max1 = premax1;
}
for(j=0; j<str[i].size(); j++)
{
map1[str[i][j]] = false;
}
}
}
int main()
{
//ifstream cin;
//cin.open("3.txt");
int t;
cin >> t;
while(t--)
{
ans = 0;
int n, m, l, s;
cin >> n >> m >> l >> s;
vector<int> v(n);
vector<vector<string> > str(n);
string tmp;
int mm;
for(int i=0; i<n; i++)
{
cin >> v[i];
cin >> mm;
for(int j=0; j<mm; j++)
{
cin >> tmp;
str[i].push_back(tmp);
}
}
vector<int> tans;
map<string, bool> map1;
dfs(0, v, str, n, m, l, s, map1, 0, 0, v[0], v[0]);
cout << ans << endl;
}
return 0;
}
#include <iostream>
#include <string>
#include <fstream>
#include <map>
#include <vector>
using namespace std;
#define min(a, b) (a) < (b) ? (a) : (b)
#define max(a, b) (a) > (b) ? (a) : (b)
int ans = 0;
void dfs(int cnt, const vector<int> &v, const vector<vector<string> > &str, int n, int m, int l, int s, map<string, bool> map1, int dep, int nandu, int max1, int min1)
{
if(cnt == m)
{
if(max1 - min1 >= s && nandu <= l)
ans++;
return;
}
if(dep >= n)
return;
dfs(cnt, v, str, n, m, l, s, map1, dep+1, nandu, max1, min1);
bool ok = true;
int j;
for(j=0; j<str[dep].size(); j++)
{
if(map1[str[dep][j]])
{
ok = false;
break;
}
map1[str[dep][j]] = true;
}
if(ok && nandu+v[dep] <= l)
{
int premin1 = min1;
int premax1 = max1;
max1 = max(max1, v[dep]);
min1 = min(min1, v[dep]);
dfs(cnt+1, v, str, n, m, l, s, map1, dep+1, nandu+v[dep], max1, min1);
min1 = premin1;
max1 = premax1;
}
for(j=0; j<str[dep].size(); j++)
{
map1[str[dep][j]] = false;
}
}
int main()
{
//ifstream cin;
//cin.open("3.txt");
int t;
cin >> t;
while(t--)
{
ans = 0;
int n, m, l, s;
cin >> n >> m >> l >> s;
vector<int> v(n);
vector<vector<string> > str(n);
string tmp;
int mm;
for(int i=0; i<n; i++)
{
cin >> v[i];
cin >> mm;
for(int j=0; j<mm; j++)
{
cin >> tmp;
str[i].push_back(tmp);
}
}
vector<int> tans;
map<string, bool> map1;
dfs(0, v, str, n, m, l, s, map1, 0, 0, v[0], v[0]);
cout << ans << endl;
}
return 0;
}