#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const long long mod = 1e9 + 7;
const long long maxn = 2e5 + 10;
const long long K = 755;
long long n, m;
long long p[maxn], h[maxn], par[maxn][22], s[maxn][22], w[maxn];
vector<pair<long long, long long>> g[maxn];
void dfs(long long u) {
  s[u][0] = w[u];
  par[u][0] = p[u];
  for (long long i = 1; (1 << i) <= h[u]; i++) {
    par[u][i] = par[par[u][i - 1]][i - 1];
    s[u][i] = max(s[par[u][i - 1]][i - 1], s[u][i - 1]);
  }
  for (long long i = 0; i < g[u].size(); i++)
    if (g[u][i].first != p[u]) {
      h[g[u][i].first] = h[u] + 1;
      p[g[u][i].first] = u;
      w[g[u][i].first] = g[u][i].second;
      dfs(g[u][i].first);
    }
}
long long get_par(long long u, long long he) {
  if (he == 0) return u;
  if (he == 1) return par[u][0];
  long long x = log2(he);
  return get_par(par[u][x], he - (1 << x));
}
long long get_max(long long u, long long he) {
  if (he == 0) return 0;
  if (he == 1) return s[u][0];
  long long x = log2(he);
  return max(get_max(par[u][x], he - (1 << x)), s[u][x]);
}
long long get_lca(long long u, long long v) {
  long long ans = 0;
  if (h[v] < h[u]) swap(u, v);
  long long he = h[v] - h[u];
  ans = max(ans, get_max(v, he));
  v = get_par(v, he);
  if (u == v) return ans;
  if (p[v] == p[u]) return max(ans, max(w[u], w[v]));
  long long x = 0;
  while (par[u][x] != par[v][x]) x++;
  x--;
  ans = max(ans, max(s[u][x], s[v][x]));
  u = par[u][x];
  v = par[v][x];
  return max(get_lca(u, v), ans);
}
long long siz[maxn], dsu_par[maxn];
long long dsu_get_par(long long u) {
  while (dsu_par[u] != u) u = dsu_par[u];
  return u;
}
void dsu(long long u, long long v) {
  u = dsu_get_par(u);
  v = dsu_get_par(v);
  if (siz[v] < siz[u]) swap(u, v);
  dsu_par[u] = v;
  siz[v] += siz[u];
}
vector<pair<long long, pair<long long, long long>>> edge, edge1;
long long ww[maxn];
long long c[maxn];
int main() {
  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  cin >> n >> m;
  for (long long i = 0; i < m; i++) cin >> ww[i];
  for (long long i = 0; i < m; i++) cin >> c[i];
  for (long long i = 0; i < m; i++) {
    long long u, v;
    cin >> u >> v;
    edge.push_back({ww[i], {u, v}});
    edge1.push_back({ww[i], {u, v}});
  }
  sort(edge.begin(), edge.end());
  for (long long i = 1; i <= n; i++) {
    dsu_par[i] = i;
    siz[i] = 1;
  }
  long long bud;
  cin >> bud;
  long long mst = 0;
  for (long long i = 0; i < m; i++) {
    long long u = edge[i].second.first;
    long long v = edge[i].second.second;
    long long w2 = edge[i].first;
    if (dsu_get_par(u) != dsu_get_par(v)) {
      dsu(u, v);
      mst += w2;
      g[v].push_back({u, w2});
      g[u].push_back({v, w2});
    }
  }
  dfs(1);
  long long ans = 1e18, road, haz;
  for (long long i = 0; i < m; i++) {
    long long u = edge1[i].second.first;
    long long v = edge1[i].second.second;
    long long w2 = edge1[i].first;
    long long x = get_lca(u, v);
    long long me = mst - x + w2;
    long long S = bud / c[i];
    if (me - S < ans) {
      ans = me - S;
      road = i;
      haz = ww[i] - S;
    }
  }
  vector<pair<pair<long long, long long>, pair<long long, long long>>> ve;
  for (long long i = 0; i < edge1.size(); i++) {
    long long u = edge1[i].second.first;
    long long v = edge1[i].second.second;
    long long w2 = edge1[i].first;
    ve.push_back({{w2, i}, {u, v}});
  }
  sort(ve.begin(), ve.end());
  for (long long i = 1; i <= n; i++) {
    siz[i] = 1;
    dsu_par[i] = i;
  }
  vector<long long> mstt;
  dsu(edge1[road].second.first, edge1[road].second.second);
  mstt.push_back(road);
  for (long long i = 0; i < m; i++) {
    long long u = ve[i].second.first;
    long long v = ve[i].second.second;
    long long w2 = ve[i].first.first;
    if (dsu_get_par(u) != dsu_get_par(v)) {
      mstt.push_back(ve[i].first.second);
      dsu(u, v);
    }
  }
  cout << ans << "\n";
  sort(mstt.begin(), mstt.end());
  for (long long i = 0; i < mstt.size(); i++) {
    if (mstt[i] == road)
      cout << mstt[i] + 1 << " " << haz << "\n";
    else
      cout << mstt[i] + 1 << " " << ww[mstt[i]] << "\n";
  }
}
