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 max_n = 42, max_m = 11, max_q = 9, mod = 1000000007, max_log = 20,
          inf = 1011111111;
const long double eps = 1e-7;
int n, m, b, x[max_n][max_m * 2], cost[max_m], sum[2][max_n + max_m * 2], T,
    true_m, used1[max_m], used[max_n + max_m * 2], privet, ptr[max_m * 2];
vector<pair<pair<int, int>, pair<int, int> > > ans;
pair<int, int> p[max_n + max_m * 2];
vector<pair<int, int> > v[max_n + max_m * 2];
void get_T() {
  T = 0;
  for (int i = 0; i < n; ++i) {
    int sm = 0;
    for (int q = 0; q < m; ++q) {
      sm += x[i][q];
    }
    T = max(T, sm);
  }
  for (int i = 0; i < m; ++i) {
    int sm = 0;
    for (int q = 0; q < n; ++q) {
      sm += x[q][i];
    }
    T = max(T, sm);
  }
}
vector<int> is_exist() {
  vector<int> ans;
  int res = 0;
  for (int i = 0; i < n; ++i) {
    int sm = 0;
    for (int q = 0; q < m; ++q) {
      sm += x[i][q];
    }
    if (sm == T) return ans;
  }
  for (int q = 0; q < true_m; ++q)
    if (!used1[q]) {
      int sm = 0;
      for (int i = 0; i < n; ++i) {
        sm += x[i][q];
      }
      if (sm == T) {
        res += cost[q];
        ans.push_back(q);
      }
    }
  if (res <= b) {
    b -= res;
    for (int i = 0; i < ans.size(); ++i) {
      used1[ans[i]] = 1;
    }
    return ans;
  }
  ans.clear();
  return ans;
}
void get_automates() {
  get_T();
  vector<int> adds = is_exist();
  while (adds.size()) {
    for (int i = 0; i < adds.size(); ++i) {
      int razn = sum[1][adds[i]];
      for (int q = v[adds[i]].size() - 1; razn >= v[adds[i]][q].second * 2;
           --q) {
        razn -= v[adds[i]].back().second * 2;
        v[m].push_back(v[adds[i]][q]);
        sum[1][adds[i]] -= v[m].back().second;
        sum[1][m] += v[m].back().second;
        swap(x[v[m].back().first][m], x[v[m].back().first][adds[i]]);
        v[adds[i]].pop_back();
      }
      if (razn > 1) {
        razn /= 2;
        v[m].push_back(make_pair(v[adds[i]].back().first, razn));
        v[adds[i]].back().second -= razn;
        sum[1][adds[i]] -= razn;
        sum[1][m] += razn;
        x[v[m].back().first][m] += razn;
        x[v[m].back().first][adds[i]] -= razn;
      }
      ptr[m] = adds[i];
      m++;
    }
    get_T();
    adds = is_exist();
  }
}
void add_graphs() {
  for (int i = 0; i < n; ++i) {
    if (sum[0][i] != T) {
      v[m + i].push_back(make_pair(i, T - sum[0][i]));
      sum[1][m + i] = T - sum[0][i];
      sum[0][i] = T;
    }
  }
  for (int i = 0; i < m; ++i) {
    if (sum[1][i] != T) {
      v[i].push_back(make_pair(n + i, T - sum[1][i]));
      sum[0][n + i] = T - sum[1][i];
      sum[1][i] = T;
    }
  }
  int i, q;
  i = q = n + m - 1;
  while (i > n - 1 || q > m - 1) {
    if (sum[0][i] == T) {
      i--;
      continue;
    }
    if (sum[1][q] == T) {
      q--;
      continue;
    }
    int razn = T - max(sum[0][i], sum[1][q]);
    sum[0][i] += razn;
    sum[1][q] += razn;
    v[q].push_back(make_pair(i, razn));
  }
}
bool dfs(int x) {
  if (used[x]) return false;
  used[x] = 1;
  for (int i = 0; i < v[x].size(); ++i) {
    int to = v[x][i].first;
    if (p[to].first == -1 || dfs(p[to].first)) {
      p[to] = make_pair(x, i);
      return true;
    }
  }
  return false;
}
void get_pairs() {
  for (int i = 0; i < n + m; ++i) {
    p[i] = make_pair(-1, -1);
  }
  for (int i = 0; i < n + m; ++i) {
    memset(used, 0, sizeof(used));
    dfs(i);
  }
}
bool is_good() {
  for (int i = 0; i < n + m; ++i)
    if (v[i].size()) return true;
  return false;
}
void get_ans() {
  while (is_good()) {
    get_pairs();
    int mn = inf;
    for (int i = 0; i < n + m; ++i) {
      mn = min(mn, v[p[i].first][p[i].second].second);
    }
    for (int i = 0; i < n + m; ++i) {
      if (i < n && p[i].first < m) {
        ans.push_back(
            make_pair(make_pair(i, ptr[p[i].first]), make_pair(privet, mn)));
      }
      v[p[i].first][p[i].second].second -= mn;
      if (v[p[i].first][p[i].second].second == 0) {
        v[p[i].first].erase(v[p[i].first].begin() + p[i].second);
      }
    }
    privet += mn;
  }
}
int main() {
  cin >> n >> m >> b;
  true_m = m;
  for (int i = 0; i < m; ++i) {
    scanf("%d", &cost[i]);
    ptr[i] = i;
  }
  for (int i = 0; i < n; ++i) {
    int k, y, g;
    scanf("%d", &k);
    for (int q = 0; q < k; ++q) {
      scanf("%d%d", &y, &g);
      y--;
      x[i][y] = g;
      v[y].push_back(make_pair(i, g));
      sum[0][i] += g;
      sum[1][y] += g;
    }
  }
  get_automates();
  add_graphs();
  get_ans();
  cout << privet << "\n";
  for (int i = 0; i < true_m; ++i) {
    if (used1[i]) {
      cout << "1";
    } else {
      cout << "0";
    }
  }
  cout << "\n" << ans.size() << "\n";
  for (int i = 0; i < ans.size(); ++i) {
    cout << ans[i].first.first + 1 << " " << ans[i].first.second + 1 << " "
         << ans[i].second.first << " " << ans[i].second.second << "\n";
  }
  return 0;
}