#include <bits/stdc++.h>
using namespace std;
long long int pr[200005], par[200005][25], maxi[200005][25], store[200005][25],
    cost[200005], dis[200005];
vector<pair<long long int, long long int> > v[200005];
long long int h[200005], endp1[200005], endp2[200005];
vector<pair<long long int, long long int> > edge;
long long int money, present[200005];
long long int find(long long int x) {
  if (pr[x] == x) return x;
  return pr[x] = find(pr[x]);
}
void dfs(long long int cur, long long int p) {
  if (p != -1) h[cur] = h[p] + 1;
  par[cur][0] = p;
  for (int i = 1; i < 20; i++) {
    if (par[cur][i - 1] != -1) par[cur][i] = par[par[cur][i - 1]][i - 1];
  }
  for (int i = 0; i < v[cur].size(); i++) {
    int x = v[cur][i].first;
    if (x == p) continue;
    dfs(x, cur);
  }
}
int lca(int v, int u) {
  if (h[v] < h[u]) swap(v, u);
  for (int i = 20 - 1; i >= 0; i--) {
    if (par[v][i] != -1 && h[par[v][i]] >= h[u]) {
      v = par[v][i];
    }
  }
  if (v == u) return u;
  for (int i = 20 - 1; i >= 0; i--) {
    if (par[v][i] - par[u][i]) v = par[v][i], u = par[u][i];
  }
  return par[v][0];
}
void make(long long int cur, long long int p, long long int wt,
          long long int id) {
  maxi[cur][0] = wt;
  store[cur][0] = id;
  for (int i = 1; i < 20; i++) {
    if (par[cur][i - 1] == -1) continue;
    maxi[cur][i] = max(maxi[cur][i - 1], maxi[par[cur][i - 1]][i - 1]);
    if (maxi[cur][i] == maxi[cur][i - 1])
      store[cur][i] = store[cur][i - 1];
    else
      store[cur][i] = store[par[cur][i - 1]][i - 1];
  }
  for (int i = 0; i < v[cur].size(); i++) {
    int x = v[cur][i].first;
    if (x == p) continue;
    make(x, cur, dis[v[cur][i].second], v[cur][i].second);
  }
}
pair<long long int, long long int> query_up(long long int x, long long int y) {
  if (x == y) return make_pair(0, 0);
  long long int ans = -1000000000000000000;
  long long int id = 0;
  for (int i = 20; i >= 0; i--) {
    if (par[x][i] == -1 || h[par[x][i]] < h[y]) continue;
    if (maxi[x][i] > ans) {
      ans = maxi[x][i];
      id = store[x][i];
    }
    x = par[x][i];
  }
  assert(x == y);
  return make_pair(ans, id);
}
pair<long long int, long long int> query(long long int x, long long int y) {
  long long int lc = lca(x, y);
  pair<long long int, long long int> p1 = query_up(x, lc);
  pair<long long int, long long int> p2 = query_up(y, lc);
  if (p1.first > p2.first)
    return p1;
  else
    return p2;
}
int main() {
  memset(par, -1, sizeof par);
  ios::sync_with_stdio(false);
  ;
  cin.tie(0);
  ;
  long long int i, j, n, m, temp, x, y, xp, yp,
      added = 0, removed = 0, tot = 0, ans = 1000000000000000000, pos, f = 0,
      id;
  cin >> n >> m;
  for (i = 1; i <= m; i++) cin >> dis[i];
  for (i = 1; i <= m; i++) cin >> cost[i];
  for (i = 1; i <= m; i++) {
    cin >> endp1[i] >> endp2[i];
    edge.push_back(make_pair(dis[i], i));
  }
  cin >> money;
  sort(edge.begin(), edge.end());
  for (i = 1; i <= n; i++) pr[i] = i;
  for (i = 0; i < edge.size(); i++) {
    id = edge[i].second;
    x = endp1[id];
    y = endp2[id];
    xp = find(x);
    yp = find(y);
    if (xp == yp) continue;
    pr[xp] = yp;
    present[id] = 1;
    tot += edge[i].first;
    v[x].push_back(make_pair(y, id));
    v[y].push_back(make_pair(x, id));
  }
  dfs(1, -1);
  make(1, -1, -1000000000000000000, 0);
  for (i = 0; i < edge.size(); i++) {
    id = edge[i].second;
    if (!present[id]) continue;
    temp = tot;
    temp -= edge[i].first;
    temp = temp + (edge[i].first - (money / cost[id]));
    if (ans > temp) {
      ans = temp;
      pos = i;
    }
  }
  for (i = 0; i < edge.size(); i++) {
    id = edge[i].second;
    if (present[id]) continue;
    x = endp1[id];
    y = endp2[id];
    temp = tot;
    pair<long long int, long long int> p = query(x, y);
    temp = temp - p.first;
    temp = temp + (edge[i].first - (money / cost[id]));
    if (ans > temp) {
      f = 1;
      ans = temp;
      added = id;
      removed = p.second;
      assert(present[removed] == 1);
    }
  }
  cout << ans << endl;
  if (!f) {
    for (i = 0; i < edge.size(); i++) {
      id = edge[i].second;
      if (!present[id]) continue;
      if (i != pos)
        cout << id << " " << dis[id] << endl;
      else
        cout << id << " " << dis[id] - money / cost[id] << endl;
    }
  } else {
    for (i = 0; i < edge.size(); i++) {
      id = edge[i].second;
      if (!present[id] || id == removed) continue;
      cout << id << " " << dis[id] << endl;
    }
    cout << added << " " << dis[added] - money / cost[added] << endl;
  }
  return 0;
}
