Problem: Tanya is now five so all her friends gathered together to celebrate her birthday. There are n children on the celebration, including Tanya.

The celebration is close to its end, and the last planned attraction is gaming machines. There are m machines in the hall, they are numbered 1 through m. Each of the children has a list of machines he wants to play on. Moreover, for each of the machines he knows the exact time he wants to play on it. For every machine, no more than one child can play on this machine at the same time.

It is evening already, so every adult wants to go home. To speed up the process, you can additionally rent second copies of each of the machines. To rent the second copy of the j-th machine, you have to pay pj burles. After you rent a machine, you can use it for as long as you want.

How long it will take to make every child play according to his plan, if you have a budget of b burles for renting additional machines? There is only one copy of each machine, so it's impossible to rent a third machine of the same type.

The children can interrupt the game in any moment and continue it later. If the i-th child wants to play on the j-th machine, it is allowed after you rent the copy of the j-th machine that this child would play some part of the time on the j-th machine and some part of the time on its copy (each of these parts could be empty). The interruptions and changes take no time and can be performed in any integer moment of time. Of course, a child can't play on more than one machine at the same time.

Remember, that it is not needed to save money (no one saves money at the expense of children happiness!), it is needed to minimize the latest moment of time some child ends his game.

Input

The first line contains three integers n, m and b (1 ≤ n ≤ 40, 1 ≤ m ≤ 10, 0 ≤ b ≤ 106) — the number of children, the number of gaming machines and the budget for renting additional machines.

The second line contains m integers p1, p2, ..., pm (1 ≤ pj ≤ 106), where pj is the rent price for the second copy of the j-th machine.

n lines follow, i-th of them describes the wishes of the i-th child. The line starts with an integer ki (0 ≤ ki ≤ m) — the number of machines, the i-th child wants to play on. Then there are ki pairs in the line, the y-th of them is xiy, tiy. It means that, the i-th child wants to play tiy (1 ≤ tiy ≤ 2500) minutes on the xiy-th (1 ≤ xiy ≤ m) machine. In each of these n lines the values xiy are distinct.

Output

In the first line print the minimum time in which all the children can finish their games.

In the second line print a string of length m consisting of zeros and ones. The j-th character is '1', if the copy of j-th machine should be rated, and '0' otherwise.

In the third line print integer g (0 ≤ g ≤ 106) — the total number of time segments of continuous playing for all of the children. Then in g lines print the segments as four integers i, j, s, d, meaning that the i-th child was playing on the j-th machine or its copy from the time moment s (s ≥ 0) for d minutes (d ≥ 1). You can print these lines in arbitrary order.

If there are multiple answers, print any of them.

Examples

Input

2 2 100
3 7
2 1 3 2 1
2 1 3 2 1


Output

4
10
8
1 1 0 1
2 2 0 1
1 1 1 1
2 1 1 1
2 1 2 1
1 1 2 1
1 2 3 1
2 1 3 1


Input

3 2 15
11 7
2 2 10 1 5
1 2 20
2 1 4 2 3


Output

20
01
17
2 2 0 4
2 2 4 1
1 1 5 2
2 2 5 2
1 2 7 5
2 2 7 5
2 2 12 1
1 2 12 1
3 1 13 4
2 2 13 4
1 2 13 4
1 1 17 2
3 2 17 2
2 2 17 2
1 1 19 1
2 2 19 1
3 2 19 1

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int N = 505;
int n, m, B, ans;
int co[N], sx[N], sy[N];
int mp[N][N], id[N], fl[N];
int mat[N], to[N];
bool vis[N], Mat[N];
bool dfs(int x) {
  for (int i = (int)(1); i <= (int)(n + m); i++)
    if (mp[x][i] && !vis[i]) {
      vis[i] = 1;
      if (!mat[i] || dfs(mat[i])) return mat[i] = x, to[x] = i, 1;
    }
  return 0;
}
struct node {
  int x, y, st, T;
} Ans[5000005];
int ans_top;
const int OUT_BUF = 100000000;
char out[OUT_BUF];
int out_top;
void write(int x) {
  if (!x) {
    out[out_top++] = '0';
    return;
  }
  static int a[15], top;
  for (top = 0; x; a[++top] = x % 10, x /= 10)
    ;
  for (; top; out[out_top++] = a[top--] + '0')
    ;
}
void writespace(int x) {
  write(x);
  out[out_top++] = ' ';
}
void writeln(int x) {
  write(x);
  out[out_top++] = '\n';
}
int main() {
  scanf("%d%d%d", &n, &m, &B);
  for (int i = (int)(1); i <= (int)(m); i++) scanf("%d", &co[i]);
  for (int i = (int)(1); i <= (int)(m); i++) id[i] = i;
  for (int i = (int)(1); i <= (int)(n); i++) {
    int cnt, x, y;
    scanf("%d", &cnt);
    while (cnt--) {
      scanf("%d%d", &x, &y);
      mp[i][x] = y;
      sx[i] += y;
      sy[x] += y;
    }
  }
  for (int i = (int)(1); i <= (int)(m); i++)
    for (int j = (int)(i + 1); j <= (int)(m); j++)
      if (sy[id[i]] > sy[id[j]]) swap(id[i], id[j]);
  int p = m;
  for (; p && B >= co[id[p]]; B -= co[id[p]], --p)
    ;
  for (int i = (int)(1); i <= (int)(n); i++) ans = max(ans, sx[i]);
  for (int i = (int)(1); i <= (int)(p); i++) ans = max(ans, sy[id[i]]);
  for (int i = (int)(p + 1); i <= (int)(m); i++)
    ans = max(ans, (sy[id[i]] + 1) / 2);
  for (int i = (int)(p + 1); i <= (int)(m); i++) {
    sy[id[i]] = 0;
    fl[id[i]] = 1;
    for (int j = (int)(1); j <= (int)(n); j++) {
      int x = id[i], y = x + m, v = mp[j][x];
      mp[j][x] = mp[j][y] = v / 2;
      if (v & 1) mp[j][sy[x] < sy[y] ? x : y]++;
      sy[x] += mp[j][x];
      sy[y] += mp[j][y];
    }
  }
  writeln(ans);
  for (int i = (int)(1); i <= (int)(m); i++) write(fl[i]);
  out[out_top++] = '\n';
  m *= 2;
  for (int i = (int)(1); i <= (int)(n); i++)
    for (int j = (int)(1); j <= (int)(n); j++) {
      mp[i][j + m] = ans - max(sx[i], sy[j + m]);
      sx[i] += mp[i][j + m];
      sy[j + m] += mp[i][j + m];
    }
  for (int i = (int)(1); i <= (int)(m); i++)
    for (int j = (int)(1); j <= (int)(m); j++) {
      mp[i + n][j] = ans - max(sx[i + n], sy[j]);
      sx[i + n] += mp[i + n][j];
      sy[j] += mp[i + n][j];
    }
  for (int i = (int)(1); i <= (int)(m); i++)
    for (int j = (int)(1); j <= (int)(n); j++) {
      mp[i + n][j + m] = ans - max(sx[i + n], sy[j + m]);
      sx[i + n] += mp[i + n][j + m];
      sy[j + m] += mp[i + n][j + m];
    }
  for (int i = (int)(1); i <= (int)(n + m); i++) Mat[i] = 1;
  for (int T = 0; T < ans;) {
    for (int i = (int)(1); i <= (int)(n + m); i++)
      if (Mat[i]) {
        memset(vis, 0, sizeof(vis));
        dfs(i);
        Mat[i] = 0;
      }
    int mn = 1e9;
    for (int i = (int)(1); i <= (int)(n + m); i++)
      if (to[i]) mn = min(mn, mp[i][to[i]]);
    for (int i = (int)(1); i <= (int)(n + m); i++)
      if (to[i]) {
        if (i <= n && to[i] <= m) Ans[++ans_top] = (node){i, to[i], T, mn};
        if (!(mp[i][to[i]] -= mn)) Mat[i] = 1, mat[to[i]] = 0;
      }
    T += mn;
  }
  writeln(ans_top);
  for (int i = (int)(1); i <= (int)(ans_top); i++) {
    writespace(Ans[i].x);
    writespace((Ans[i].y - 1) % (m / 2) + 1);
    writespace(Ans[i].st);
    writeln(Ans[i].T);
  }
  fwrite(out, 1, out_top, stdout);
}