#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#define FOR(i,a,b) for(i=(a);i<=(b);i++)
#define ROF(i,a,b) for(i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define N 200010
using namespace std;
typedef long long LL;
typedef long double LD;
int ans=-1e9,nc[N],nr[N],dp[52][102][2010],tmp[2010],len=0,pre[N],last[N],e[N],lim[N],w[N],m,p[N],num[N],n;
void add(int x,int y){nc[x]=1;nr[y]=1;pre[++len]=last[x];last[x]=len;e[len]=y;}
void up(int &x,int y){x=y>x?y:x;}
void dn(int &x,int y){x=y<x?y:x;}
void Dp(int x)
{
int i,j,k;
if (!nc[x])
{
dn(lim[x],m/w[x]);
FOR(i,0,lim[x]) FOR(j,i,lim[x]) up(dp[x][i][j*w[x]],(j-i)*p[x]);
return;
}
for(int pt=last[x];pt;pt=pre[pt])
{int y=e[pt];Dp(y);dn(lim[x],lim[y]/num[y]);}
FOR(i,0,lim[x]) dp[x][i][0]=0;
FOR(i,0,lim[x]) for(int pt=last[x];pt;pt=pre[pt])
{
int y=e[pt];int v=i*num[y];
memcpy(tmp,dp[x][i],sizeof(tmp));
memset(dp[x][i],0xff,sizeof(dp[x][i]));
ROF(j,m,0) ROF(k,j,0)
{
if (~tmp[j-k]&&~dp[y][v][k])
{
up(dp[x][i][j],tmp[j-k]+dp[y][v][k]);
up(ans,dp[x][i][j]);
}
}
}
FOR(i,0,lim[x]-1) ROF(j,lim[x],i+1) ROF(k,m,0)
if (~dp[x][j][k])
{
up(dp[x][i][k],dp[x][j][k]+p[x]*(j-i));
up(ans,dp[x][i][k]);
}
}
int main()
{
ios::sync_with_stdio(false);
scanf("%d%d",&n,&m);
int i,j;FOR(i,1,n) lim[i]=2000;
char s[2];
FOR(i,1,n)
{
scanf("%d",&p[i]);
scanf("%s",s);
if (s[0]=='A')
{
int ert,ery;scanf("%d",&ert);
FOR(j,1,ert) {scanf("%d",&ery);scanf("%d",&num[ery]);add(i,ery);}
}else
{
scanf("%d%d",&w[i],&lim[i]);
}
}
memset(dp,0xff,sizeof(dp));
FOR(i,1,n) if (!nr[i]) Dp(i);
printf("%d\n",ans);
return 0;
}