#include <bits/stdc++.h>
using namespace std;
long long n, m, s;
struct tree {
  long long w, id;
  tree operator+(const tree &a) const {
    tree c;
    if (a.w > w)
      c.w = a.w, c.id = a.id;
    else
      c.w = w, c.id = id;
    return c;
  }
} TR[1000005];
struct Node {
  long long u, v, w, id, tag, nex;
} Edge[400005], Edge_inv[200005];
bool cmp(Node a, Node b) { return a.w < b.w; }
long long h[200005], stot;
void add(long long u, long long v, long long w, long long id) {
  Edge[++stot] = (Node){u, v, w, id, 0, h[u]};
  h[u] = stot;
}
long long stot_inv;
void add_inv(long long u, long long v, long long w, long long id) {
  Edge_inv[++stot_inv] = (Node){u, v, w, id, 0, 0};
}
long long fa[200005], dep[200005], siz[200005], son[200005], sw[200005],
    sid[200005];
void dfs1(long long u, long long f) {
  fa[u] = f;
  dep[u] = dep[f] + 1;
  siz[u] = 1;
  for (long long i = h[u]; i; i = Edge[i].nex) {
    long long v = Edge[i].v;
    if (v == f) continue;
    dfs1(v, u);
    siz[u] += siz[v];
    if (siz[v] > siz[son[u]])
      son[u] = v, sw[u] = Edge[i].w, sid[u] = Edge[i].id;
  }
}
long long top[200005], seq[200005], seq1[200005], in[200005], idc;
void dfs2(long long u, long long t, long long w, long long id) {
  top[u] = t;
  seq[++idc] = w;
  seq1[idc] = id, in[u] = idc;
  if (son[u]) dfs2(son[u], t, sw[u], sid[u]);
  for (long long i = h[u]; i; i = Edge[i].nex) {
    long long v = Edge[i].v;
    if (v == fa[u] || v == son[u]) continue;
    dfs2(v, v, Edge[i].w, Edge[i].id);
  }
}
void update(long long nd) { TR[nd] = TR[nd << 1] + TR[nd << 1 | 1]; }
void build(long long nd, long long l, long long r) {
  if (l == r) {
    TR[nd].w = seq[l];
    TR[nd].id = seq1[l];
    return;
  }
  long long mid = (l + r) >> 1;
  build(nd << 1, l, mid);
  build(nd << 1 | 1, mid + 1, r);
  update(nd);
}
tree query(long long nd, long long l, long long r, long long L, long long R) {
  if (l >= L && r <= R) return TR[nd];
  long long mid = (l + r) >> 1;
  tree ans;
  ans.w = -0x3f3f3f3f, ans.id = 0;
  if (L <= mid) ans = ans + query(nd << 1, l, mid, L, R);
  if (R > mid) ans = ans + query(nd << 1 | 1, mid + 1, r, L, R);
  return ans;
}
tree query(long long u, long long v) {
  tree ans;
  ans.w = -0x3f3f3f3f, ans.id = 0;
  while (top[u] != top[v]) {
    if (dep[top[u]] < dep[top[v]]) swap(u, v);
    ans = ans + query(1, 1, n, in[top[u]], in[u]);
    u = fa[top[u]];
  }
  if (dep[u] < dep[v]) swap(u, v);
  ans = ans + query(1, 1, n, in[v] + 1, in[u]);
  return ans;
}
long long f[200005];
long long find(long long x) {
  if (x != f[x]) f[x] = find(f[x]);
  return f[x];
}
long long w[200005], c[200005], tot, ans1, ans2;
void Kruskal() {
  sort(Edge_inv + 1, Edge_inv + 1 + m, cmp);
  for (long long i = 1; i <= n; i++) f[i] = i;
  for (long long i = 1; i <= m; i++) {
    long long u = Edge_inv[i].u, v = Edge_inv[i].v, id = Edge_inv[i].id;
    long long uu = find(u), vv = find(v);
    if (uu != vv) {
      Edge_inv[i].tag = 1;
      f[uu] = vv;
      add(u, v, w[id], id);
      add(v, u, w[id], id);
      tot += w[id];
      if (c[id] < c[ans1]) ans1 = id;
    }
  }
}
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]);
  c[0] = 0x3f3f3f3f;
  for (long long i = 1; i <= m; i++) {
    long long u, v;
    scanf("%lld%lld", &u, &v);
    add_inv(u, v, w[i], i);
  }
  scanf("%lld", &s);
  Kruskal();
  ans2 = tot - s / c[ans1];
  dfs1(1, 0);
  dfs2(1, 0, -0x3f3f3f3f, 0);
  build(1, 1, n);
  long long flag = 0;
  for (long long i = 1; i <= m; i++) {
    if (!Edge_inv[i].tag) {
      long long u = Edge_inv[i].u, v = Edge_inv[i].v, id = Edge_inv[i].id;
      tree a = query(u, v);
      long long tmp = tot - a.w + w[id] - s / c[id];
      if (tmp < ans2) ans1 = id, ans2 = tmp, flag = a.id;
    }
  }
  printf("%lld\n", ans2);
  for (long long i = 1; i <= m; i++) {
    long long id = Edge_inv[i].id;
    if (ans1 == id) {
      printf("%lld %lld\n", id, w[id] - s / c[id]);
    } else if (Edge_inv[i].tag) {
      if (flag != id) {
        printf("%lld %lld\n", id, w[id]);
      }
    }
  }
  return 0;
}
