#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
struct edge {
  int u, v, w, c, id;
  bool operator<(const edge& op) const { return w < op.w; }
} ed[N], se[N];
int n, m, S, ce, de, choose[N], sub, depth[N], pa[N], sz[N];
vector<int> MST[N];
long long ans = 0;
pair<int, int> f[N][20];
int get(int u) {
  if (u != pa[u]) u = get(pa[u]);
  return pa[u];
}
bool unite(int a, int b) {
  a = get(a);
  b = get(b);
  if (a == b) return false;
  if (sz[a] < sz[b]) swap(a, b);
  pa[b] = a;
  sz[a] += sz[b];
  return true;
}
int get_max(int i, int j) {
  if (ed[i].w > ed[j].w)
    return i;
  else
    return j;
}
void dfs(int u, int p, int id) {
  f[u][0].second = id;
  f[u][0].first = p;
  depth[u] = depth[p] + 1;
  for (int i = 1; i < 20; i++)
    f[u][i].second =
        get_max(f[u][i - 1].second, f[f[u][i - 1].first][i - 1].second),
    f[u][i].first = f[f[u][i - 1].first][i - 1].first;
  for (int i : MST[u]) {
    if (ed[i].u + ed[i].v - u == p) continue;
    dfs(ed[i].u + ed[i].v - u, u, i);
  }
}
int max_edge(int u, int v) {
  int res = 0;
  if (depth[u] < depth[v]) swap(u, v);
  for (int i = 19; i >= 0; i--) {
    if (depth[f[u][i].first] >= depth[v]) {
      res = get_max(res, f[u][i].second);
      u = f[u][i].first;
    }
  }
  if (u == v) return res;
  for (int i = 19; i >= 0; i--) {
    if (f[u][i].first != f[v][i].first) {
      res = get_max(res, f[u][i].second);
      res = get_max(res, f[v][i].second);
      u = f[u][i].first;
      v = f[v][i].first;
    }
  }
  res = get_max(res, f[u][0].second);
  res = get_max(res, f[v][0].second);
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  cin >> n >> m;
  for (int i = 1; i <= m; i++) cin >> ed[i].w;
  for (int i = 1; i <= m; i++) cin >> ed[i].c;
  for (int i = 1; i <= m; i++) cin >> ed[i].u >> ed[i].v, ed[i].id = i;
  cin >> S;
  for (int i = 1; i <= m; i++) se[i] = ed[i];
  sort(se + 1, se + 1 + m);
  for (int i = 1; i <= n; i++) pa[i] = i, sz[i] = 1;
  for (int i = 1; i <= m; i++) {
    if (unite(se[i].u, se[i].v)) {
      choose[se[i].id] = 1;
      ans += se[i].w;
      MST[se[i].u].push_back(se[i].id);
      MST[se[i].v].push_back(se[i].id);
    }
  }
  dfs(1, 0, 0);
  for (int i = 1; i <= m; i++) {
    int e = max_edge(ed[i].u, ed[i].v);
    int op = ed[i].w - ed[e].w - S / ed[i].c;
    if (op < sub) {
      sub = op;
      ce = i;
      de = e;
    }
  }
  ans += sub;
  choose[de] = false;
  choose[ce] = true;
  cout << ans << endl;
  int cnt = 0;
  for (int i = 1; i <= m; i++) {
    if (!choose[i]) continue;
    cnt++;
    cout << i << " ";
    if (i == ce)
      cout << ed[i].w - S / ed[i].c << endl;
    else
      cout << ed[i].w << endl;
  }
  return 0;
}
