#include<cstdio>
#include<cctype>
#include<queue>
#include<cmath>
#include<cstring>
#include<algorithm>
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define ren for(int i=first[x];i;i=next[i])
using namespace std;
inline int read() {
int x=0,f=1;char c=getchar();
for(;!isdigit(c);c=getchar()) if(c==‘-‘) f=-1;
for(;isdigit(c);c=getchar()) x=x*10+c-‘0‘;
return x*f;
}
const int maxn=55;
const int maxm=2005;
const int maxp=105;
const int inf=1e9;
char ch[12];
int n,m,first[maxn],next[maxm*10],to[maxm*10],dis[maxm*10],in[maxn],e;
void AddEdge(int u,int v,int w) {
dis[++e]=w;to[e]=v;next[e]=first[u];first[u]=e;in[v]++;
}
int f[maxn][maxp][maxm],g[maxn][maxm],p[maxn],c[maxn],s[maxn];
void dp(int x) {
if(!first[x]) {
s[x]=min(s[x],m/c[x]);//QAQ,打成m/p[x]了2333
rep(i,0,s[x]) rep(j,i,s[x]) f[x][i][j*c[x]]=(j-i)*p[x];
return;
}
s[x]=inf;
for(int i=first[x];i;i=next[i]) {
dp(to[i]);
s[x]=min(s[x],s[to[i]]/dis[i]);
c[x]+=c[to[i]]*dis[i];
}
s[x]=min(s[x],m/c[x]);
memset(g,-0x3f3f3f3f,sizeof(g));g[0][0]=0;
dwn(y,s[x],0) {
int cnt=0;
for(int i=first[x];i;i=next[i]) {
cnt++;
dwn(j,m,0) rep(k,0,j) g[cnt][j]=max(g[cnt][j],g[cnt-1][j-k]+f[to[i]][y*dis[i]][k]);
}
rep(j,0,y) rep(k,0,m) f[x][j][k]=max(f[x][j][k],g[cnt][k]+p[x]*(y-j));
}
}
int main() {
memset(f,-0x3f3f3f3f,sizeof(f));
n=read();m=read();
rep(i,1,n) {
p[i]=read();scanf("%s",ch);
if(ch[0]==‘A‘) {
int k=read(),v,w;
while(k--) v=read(),w=read(),AddEdge(i,v,w);
}
else c[i]=read(),s[i]=read();
}
int ans=0;
rep(i,1,n) if(!in[i]) {
dp(i);rep(j,0,m) ans=max(ans,f[i][0][j]);
}
printf("%d\n",ans);
return 0;
}