#3704. 买咖啡 (coffee)

买咖啡 (coffee)

时间限制:1000 ms;空间限制:512 MB。

题目描述

学校每周使用相同的课程表:周一至周五每天上 88 节课,周六、周日不上课。mc 每上一节数学课,都要买一杯咖啡。

给定周一至周五的课程表、学期持续的天数以及学期第一天是星期几,求 mc 整个学期需要买多少杯咖啡。

输入格式

在文件 coffee.in 中读入。

第一行是一个正整数 TT,表示测试数据的组数。

接下来依次输入 TT 组测试数据。对于每组测试数据:

前五行分别表示周一至周五每天的 88 节课。每节课是 chinese、math、english、science 中的一种,同行的课程名称以空格分隔。

第六行有两个正整数 n,mn,m,分别表示学期的天数和学期第一天是星期几。m=1,2,…,7m=1,2,\ldots,7 依次表示周一至周日。

输出格式

在文件 coffee.out 中输出。

输出 TT 行,每行一个非负整数。第 ii 行表示第 ii 组数据的答案。

样例

样例输入 #1

2
math math math math math math math math
math math math math math math math math
math math math math math math math math
math math math math math math math math
math math math math math math math math
35 1
chinese math english science chinese math english science
chinese math english science chinese math english science
chinese math english science chinese math english science
chinese math english science chinese math english science
chinese math english science chinese math english science
36 6

样例输出 #1

200
50

数据范围

对于所有数据,1≤T≤10001\le T\le1000,1≤n≤1091\le n\le10^9,1≤m≤71\le m\le7。

本题共 2020 个测试点,每点 55 分。

测试点编号 额外限制
1∼41\sim4 每组 n≤1000n\le1000
5∼205\sim20 无额外限制