#include <bits/stdc++.h>
using namespace std;
const int MX = 200010;
const int MXL = 20;
class Disjoint_Set {
 public:
  int sz[MX], P[MX];
  int comp;
  void init(int N) {
    for (int j = 1; j <= N; j++) sz[j] = 1, P[j] = j;
    comp = N;
  }
  int find_(int x) {
    if (x != P[x]) P[x] = find_(P[x]);
    return P[x];
  }
  bool merge_(int x, int y) {
    int px = find_(x), py = find_(y);
    if (px == py) return false;
    if (sz[px] < sz[py]) swap(px, py);
    P[py] = px;
    comp--;
    sz[px] += sz[py];
    return true;
  }
} dsu;
vector<pair<long long int, long long int> > v[MX];
vector<pair<pair<long long int, long long int>,
            pair<long long int, long long int> > >
    edges;
long long int w[MX];
long long int c[MX];
long long int s;
int depth[MX];
int par[MXL][MX];
int n;
int mx[MXL][MX];
void Pdfs(int x, int p) {
  int nxt, C, sz = v[x].size();
  for (int j = 0; j < sz; j++) {
    nxt = v[x][j].first;
    if (nxt == p) {
      mx[0][x] = v[x][j].second;
      continue;
    }
    depth[nxt] = depth[x] + 1;
    par[0][nxt] = x;
    Pdfs(nxt, x);
  }
}
void process() {
  for (int j = 1; j < MXL; j++)
    for (int i = 1; i <= n; i++) {
      par[j][i] = par[j - 1][par[j - 1][i]];
      mx[j][i] = mx[j - 1][par[j - 1][i]];
      mx[j][i] = max(mx[j][i], mx[j - 1][i]);
    }
}
int Kth(int x, int K) {
  int node = x;
  for (int j = 0; j < MXL; j++)
    if ((K & (1 << j))) node = par[j][node];
  return node;
}
int LCA_RET(int x, int y) {
  int ret = 0;
  if (depth[x] < depth[y]) swap(x, y);
  int de = depth[x] - depth[y];
  for (int i = MXL - 1; i >= 0; i--) {
    if (de >> i & 1) {
      ret = max(ret, mx[i][x]);
      x = par[i][x];
    }
  }
  if (x == y) return ret;
  for (int i = MXL - 1; i >= 0; i--) {
    if (par[i][x] != par[i][y]) {
      ret = max(ret, max(mx[i][x], mx[i][y]));
      x = par[i][x];
      y = par[i][y];
    }
  }
  ret = max(ret, max(mx[0][x], mx[0][y]));
  return ret;
}
int main() {
  int m;
  cin >> n >> m;
  dsu.init(n);
  for (int i = 0; i < m; i++) scanf("%lld", &w[i]);
  for (int i = 0; i < m; i++) scanf("%lld", &c[i]);
  int idx = 0;
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    edges.push_back({{w[i], i}, {x, y}});
  }
  cin >> s;
  long long int tot = 0;
  sort(edges.begin(), edges.end());
  for (auto e : edges) {
    int x = e.second.first, y = e.second.second;
    if (dsu.merge_(x, y)) {
      tot += e.first.first;
      v[x].push_back({y, e.first.first});
      v[y].push_back({x, e.first.first});
    }
  }
  Pdfs(1, 1);
  process();
  long long int cost = tot;
  int cnt = -1;
  for (auto e : edges) {
    cnt++;
    int x = e.second.first, y = e.second.second;
    long long int mx = LCA_RET(x, y);
    int i = e.first.second;
    long long int cur = w[i] - s / c[i];
    long long int ncost = tot - mx + cur;
    if (cost < ncost) continue;
    if (cost == ncost) idx = cnt;
    if (cost > ncost) {
      cost = ncost;
      idx = cnt;
    }
  }
  int j = edges[idx].first.second;
  edges[idx].first.first = w[j] - s / c[j];
  dsu.init(n);
  tot = 0;
  vector<pair<long long int, long long int> > amid;
  sort(edges.begin(), edges.end());
  for (auto e : edges) {
    int x = e.second.first, y = e.second.second;
    if (dsu.merge_(x, y)) {
      tot += e.first.first;
      amid.push_back({e.first.second + 1, e.first.first});
    }
  }
  sort(amid.begin(), amid.end());
  cout << tot << '\n';
  for (auto p : amid) cout << p.first << " " << p.second << '\n';
}
