#include <bits/stdc++.h>
using namespace std;
const int maxn = 200009;
struct Edge {
  int c, w;
  int u, v;
  int ind;
} e[maxn];
bool comp(Edge a, Edge b) { return a.w < b.w; }
int dsu_par[maxn];
int dsu_find(int v) {
  if (v == dsu_par[v]) return v;
  return dsu_par[v] = dsu_find(dsu_par[v]);
}
bool dsu_merge(int u, int v) {
  if (dsu_find(u) == dsu_find(v)) return false;
  dsu_par[dsu_find(u)] = dsu_find(v);
  return true;
}
vector<pair<int, int>> neigh[maxn];
int depth[maxn];
int par[20][maxn];
int maxEdge[20][maxn];
void dfs(int v, int p) {
  par[0][v] = p;
  for (auto ee : neigh[v]) {
    int u = ee.first;
    if (u == p) continue;
    maxEdge[0][u] = ee.second;
    depth[u] = depth[v] + 1;
    dfs(u, v);
  }
}
void precalc(int n) {
  for (int i = 0; i < 19; i++) {
    for (int v = 1; v <= n; v++) {
      maxEdge[i + 1][v] = max(maxEdge[i][par[i][v]], maxEdge[i][v]);
      par[i + 1][v] = par[i][par[i][v]];
    }
  }
}
int findMaxEdge(int u, int v) {
  if (depth[u] < depth[v]) swap(u, v);
  int val = 0;
  for (int i = 19; i >= 0; i--) {
    if (depth[par[i][u]] >= depth[v]) {
      val = max(val, maxEdge[i][u]);
      u = par[i][u];
    }
  }
  for (int i = 19; i >= 0; i--) {
    if (par[i][u] != par[i][v]) {
      val = max(val, maxEdge[i][v]);
      val = max(val, maxEdge[i][u]);
      u = par[i][u];
      v = par[i][v];
    }
  }
  if (u != v) {
    val = max(val, maxEdge[0][u]);
    val = max(val, maxEdge[0][v]);
  }
  return val;
}
int main() {
  int n, m, S;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) scanf("%d", &e[i].w);
  for (int i = 1; i <= m; i++) scanf("%d", &e[i].c);
  for (int i = 1; i <= m; i++) scanf("%d %d", &e[i].u, &e[i].v);
  for (int i = 1; i <= m; i++) e[i].ind = i;
  scanf("%d", &S);
  sort(e + 1, e + 1 + m, comp);
  for (int v = 1; v <= n; v++) dsu_par[v] = v;
  long long defaultVal = 0;
  for (int i = 1; i <= m; i++) {
    if (dsu_merge(e[i].u, e[i].v)) {
      defaultVal += e[i].w;
      neigh[e[i].u].push_back(make_pair(e[i].v, e[i].w));
      neigh[e[i].v].push_back(make_pair(e[i].u, e[i].w));
    }
  }
  dfs(1, 1);
  precalc(n);
  long long ans = defaultVal;
  int to = 0;
  for (int i = 1; i <= m; i++) {
    int mx = findMaxEdge(e[i].u, e[i].v);
    long long newAns = defaultVal + e[i].w - mx - (S / e[i].c);
    if (newAns <= ans) {
      ans = newAns;
      to = i;
    }
  }
  printf("%I64d\n", ans);
  for (int v = 1; v <= n; v++) dsu_par[v] = v;
  dsu_merge(e[to].u, e[to].v);
  printf("%d %d\n", e[to].ind, e[to].w - S / e[to].c);
  for (int i = 1; i <= m; i++) {
    if (dsu_merge(e[i].u, e[i].v)) {
      printf("%d %d\n", e[i].ind, e[i].w);
    }
  }
}
