#include <bits/stdc++.h>
using namespace std;
const int iinf = 1e9 + 7;
const long long linf = 1ll << 60;
const double dinf = 1e10;
template <typename T>
inline void scf(T &x) {
  bool f = 0;
  x = 0;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-') c = getchar();
  if (c == '-') {
    f = 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  if (f) x = -x;
  return;
}
template <typename T1, typename T2>
void scf(T1 &x, T2 &y) {
  scf(x);
  return scf(y);
}
template <typename T1, typename T2, typename T3>
void scf(T1 &x, T2 &y, T3 &z) {
  scf(x);
  scf(y);
  return scf(z);
}
const int N = 2e5 + 100;
const int lgN = 20;
struct edge {
  int u, v, id;
  long long w, c;
  edge() {}
  edge(int U, int V, long long W, long long C, int i) {
    u = U;
    v = V;
    w = W;
    c = C;
    id = i;
    return;
  }
} e[N];
bool operator<(const edge &e1, const edge &e2) { return e1.w < e2.w; }
int n, m, mnrem;
long long ans2 = linf;
int rem;
long long MN = linf, ans, S;
set<int> has[N];
int par[N];
long long W[N], C[N];
vector<pair<int, pair<long long, int> > > g[N];
bool used[N];
int fa[N][lgN];
pair<long long, int> mn[N][lgN];
int dep[N];
inline int find(int i) { return par[i] == i ? i : par[i] = find(par[i]); }
inline void SWAP(int &u, int &v) {
  u ^= v;
  v ^= u;
  u ^= v;
  return;
}
inline void dfs(int u = 1, int par = 0,
                pair<long long, int> d = make_pair(-1, -1)) {
  dep[u] = dep[par] + 1;
  fa[u][0] = par;
  mn[u][0] = d;
  for (int i = 0; i < (lgN - 1); i++) {
    fa[u][i + 1] = fa[fa[u][i]][i];
    mn[u][i + 1] = max(mn[u][i], mn[fa[u][i]][i]);
  }
  for (auto e : g[u]) {
    int v = e.first;
    if (v != par) dfs(v, u, e.second);
  }
  return;
}
inline pair<long long, int> query(int u, int v) {
  if (dep[u] < dep[v]) SWAP(u, v);
  int dlt = dep[u] - dep[v];
  pair<long long, int> ret = make_pair(-1, -1);
  for (int i = 0; i < (lgN); i++)
    if ((dlt >> i) & 1) ret = max(ret, mn[u][i]), u = fa[u][i];
  if (u == v) return ret;
  for (int i = (lgN - 1); i >= (0); i--)
    if (fa[u][i] != fa[v][i]) {
      ret = max(ret, max(mn[u][i], mn[v][i]));
      u = fa[u][i];
      v = fa[v][i];
    }
  ret = max(ret, max(mn[u][0], mn[v][0]));
  return ret;
}
int main() {
  scf(n, m);
  for (int i = 0; i < (m); i++) scf(W[i]);
  for (int i = 0; i < (m); i++) scf(C[i]);
  for (int i = 0; i < (m); i++) {
    int u, v;
    scf(u, v);
    e[i] = edge(u, v, W[i], C[i], i);
  }
  sort(e, e + m);
  for (int i = (1); i <= (n); i++) par[i] = i;
  for (int i = 0; i < (m); i++) {
    int u = e[i].u, v = e[i].v;
    u = find(u);
    v = find(v);
    if (u == v) continue;
    if (e[i].c < MN) MN = e[i].c, mnrem = i;
    ans += e[i].w;
    used[i] = 1;
    par[u] = v;
    g[e[i].u].push_back(make_pair(e[i].v, make_pair(e[i].w, i)));
    g[e[i].v].push_back(make_pair(e[i].u, make_pair(e[i].w, i)));
  }
  scf(S);
  for (int i = 0; i < (lgN); i++) mn[0][i] = make_pair(-1, -1);
  dfs();
  for (int i = 0; i < (m); i++)
    if (!used[i]) {
      pair<long long, int> t = query(e[i].u, e[i].v);
      long long calc = ans - t.first + e[i].w - S / e[i].c;
      if (calc < ans2) ans2 = calc, rem = i;
    }
  ans -= (S / MN);
  if (ans2 < ans) {
    printf("%I64d\n", ans2);
    pair<long long, int> t = query(e[rem].u, e[rem].v);
    int pos = t.second;
    for (int i = 0; i < (m); i++)
      if (used[i] && i != pos) printf("%d %I64d\n", e[i].id + 1, e[i].w);
    e[rem].w -= (S / e[rem].c);
    printf("%d %I64d\n", e[rem].id + 1, e[rem].w);
  } else {
    printf("%I64d\n", ans);
    for (int i = 0; i < (m); i++)
      if (used[i] && i != mnrem) printf("%d %I64d\n", e[i].id + 1, e[i].w);
    e[mnrem].w -= (S / e[mnrem].c);
    printf("%d %I64d\n", e[mnrem].id + 1, e[mnrem].w);
  }
  return 0;
}
