#include <bits/stdc++.h>
using namespace std;
long long n, m, t, h[200010], p[200010][30], f[200010], k, num, r;
long long d[200010], dis[200010], cost[200010][30], w[200010], c[200010], pos;
long long ans, s, mic;
struct node {
  long long u;
  long long v;
  long long id;
  long long used;
  long long w;
  long long c;
} ee[400010];
struct ndde {
  long long v;
  long long w;
  long long nex;
} e[400010];
void add(long long u, long long v, long long w) {
  e[++k].v = v;
  e[k].w = w;
  e[k].nex = h[u];
  h[u] = k;
}
long long find(long long x) {
  if (f[x] == x) return x;
  return f[x] = find(f[x]);
}
void kruskal() {
  long long cnt = 0;
  for (long long i = 1; i <= n; i++) f[i] = i;
  for (long long i = 1; i <= m && cnt < n - 1; i++) {
    long long fx = find(ee[i].u), fy = find(ee[i].v);
    if (f[fx] != fy) {
      cnt++;
      f[fx] = fy;
      ee[i].used = 1;
      pos += ee[i].w;
      if (ee[i].c < mic) {
        mic = ee[i].c;
        num = i;
      }
      add(ee[i].u, ee[i].v, ee[i].w);
      add(ee[i].v, ee[i].u, ee[i].w);
    }
  }
}
void dfs(long long u, long long fa) {
  d[u] = d[fa] + 1ll;
  p[u][0] = fa;
  for (long long i = 1; i <= 20; i++) {
    p[u][i] = p[p[u][i - 1]][i - 1];
    cost[u][i] = max(cost[u][i - 1], cost[p[u][i - 1]][i - 1]);
  }
  for (long long i = h[u]; i; i = e[i].nex) {
    long long v = e[i].v;
    long long w = e[i].w;
    if (v == fa) continue;
    dis[v] = dis[u] + e[i].w;
    cost[v][0] = w;
    dfs(v, u);
  }
}
long long lca(long long u, long long v) {
  long long ret = 0;
  if (d[u] > d[v]) swap(u, v);
  for (long long i = 20; i >= 0; i--)
    if (d[u] <= d[v] - (1 << i)) {
      ret = max(ret, cost[v][i]);
      v = p[v][i];
    }
  if (u == v) return ret;
  for (long long i = 20; i >= 0; i--) {
    if (p[u][i] == p[v][i]) continue;
    ret = max(ret, cost[u][i]);
    ret = max(ret, cost[v][i]);
    u = p[u][i];
    v = p[v][i];
  }
  ret = max(ret, cost[u][0]);
  ret = max(ret, cost[v][0]);
  return ret;
}
long long lcat(long long u, long long v) {
  if (d[u] > d[v]) swap(u, v);
  for (long long i = 20; i >= 0; i--)
    if (d[u] <= d[v] - (1 << i)) v = p[v][i];
  if (u == v) return u;
  for (long long i = 20; i >= 0; i--) {
    if (p[u][i] == p[v][i]) continue;
    u = p[u][i];
    v = p[v][i];
  }
  return p[u][0];
}
long long dist(long long u, long long v) {
  return dis[u] + dis[v] - 2ll * dis[lcat(u, v)];
}
long long judge(long long u, long long v, long long x) {
  if (dist(u, x) + dist(v, x) == dist(u, v)) return 1;
  return 0;
}
long long cmp(node xx, node yy) { return xx.w < yy.w; }
int main() {
  scanf("%lld%lld", &n, &m);
  for (long long i = 1; i <= m; i++) scanf("%lld", &w[i]);
  for (long long i = 1; i <= m; i++) scanf("%lld", &c[i]);
  for (long long i = 1; i <= m; i++) {
    long long a, b;
    scanf("%lld%lld", &a, &b);
    ee[i].u = a;
    ee[i].v = b;
    ee[i].w = w[i];
    ee[i].c = c[i];
    ee[i].id = i;
  }
  mic = 1e17;
  scanf("%lld", &s);
  sort(ee + 1, ee + m + 1, cmp);
  kruskal();
  ans = pos - s / mic;
  dfs(1, 0);
  for (long long i = 1; i <= m; i++)
    if (ee[i].c < mic) {
      long long u = ee[i].u, v = ee[i].v;
      long long w = ee[i].w;
      long long tmp = pos + w - lca(u, v);
      tmp -= s / ee[i].c;
      if (tmp < ans) {
        ans = tmp;
        r = i;
      }
    }
  printf("%lld\n", ans);
  if (!r) {
    ee[num].w -= s / ee[num].c;
    for (long long i = 1; i <= m; i++)
      if (ee[i].used) printf("%lld %lld\n", ee[i].id, ee[i].w);
  } else {
    ee[r].w -= s / ee[r].c;
    long long u = ee[r].u, v = ee[r].v;
    long long w = lca(u, v);
    long long flag = 1;
    for (long long i = 1; i <= m; i++) {
      if (i == r) printf("%lld %lld\n", ee[i].id, ee[i].w);
      if (ee[i].used) {
        if (ee[i].w == w && judge(u, v, ee[i].u) && judge(u, v, ee[i].v) &&
            flag) {
          flag = 0;
          continue;
        }
        printf("%lld %lld\n", ee[i].id, ee[i].w);
      }
    }
  }
}
