#include <bits/stdc++.h>
using namespace std;
const long long int maxn = 2e5 + 100, bghs = 1e9 + 7, inf = 1e9 + 100;
long long int sum;
int n, m;
pair<pair<int, int>, int> r[maxn];
int w[maxn], c[maxn];
int lab[maxn];
int s;
vector<pair<int, int> > a[maxn];
int f[maxn][19], d[maxn][19], dep[maxn];
bool used[maxn];
bool cmp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
  return w[a.second] < w[b.second];
}
int root(int x) {
  while (lab[x] > 0) x = lab[x];
  return x;
}
void uni(int x, int y) {
  if (lab[x] > lab[y]) swap(x, y);
  lab[x] += lab[y];
  lab[y] = x;
}
void dfs(int x) {
  for (int i = (0), _b = (a[x].size() - 1); i <= _b; i++) {
    int y = a[x][i].first;
    int id = a[x][i].second;
    if (y != f[x][0]) {
      f[y][0] = x;
      d[y][0] = id;
      dep[y] = dep[x] + 1;
      for (int i = (1), _b = (18); i <= _b; i++)
        if (f[y][i - 1] != 0) {
          f[y][i] = f[f[y][i - 1]][i - 1];
          if (w[d[y][i - 1]] > w[d[f[y][i - 1]][i - 1]]) {
            d[y][i] = d[y][i - 1];
          } else
            d[y][i] = d[f[y][i - 1]][i - 1];
        }
      dfs(y);
    }
  }
}
int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  int id = 0;
  for (int i = (18), _a = (0); i >= _a; i--)
    if (f[x][i] != 0 && dep[f[x][i]] >= dep[y]) {
      if (w[id] < w[d[x][i]]) {
        id = d[x][i];
      }
      x = f[x][i];
    }
  for (int i = (18), _a = (0); i >= _a; i--)
    if (f[x][i] != f[y][i]) {
      if (w[id] < w[d[x][i]]) id = d[x][i];
      if (w[id] < w[d[y][i]]) id = d[y][i];
      x = f[x][i];
      y = f[y][i];
    }
  if (x != y) {
    if (w[id] < w[d[x][0]]) id = d[x][0];
    if (w[id] < w[d[y][0]]) id = d[y][0];
    x = f[x][0];
    y = f[y][0];
  }
  return id;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (1), _b = (n); i <= _b; i++) lab[i] = -1;
  for (int i = (1), _b = (m); i <= _b; i++) scanf("%d", &w[i]);
  w[0] = -inf;
  for (int i = (1), _b = (m); i <= _b; i++) scanf("%d", &c[i]);
  for (int i = (1), _b = (m); i <= _b; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    r[i] = make_pair(make_pair(x, y), i);
  }
  scanf("%d", &s);
  sort(r + 1, r + 1 + m, cmp);
  for (int i = (1), _b = (m); i <= _b; i++) {
    int x = r[i].first.first;
    int y = r[i].first.second;
    int u = root(x);
    int v = root(y);
    if (u != v) {
      uni(u, v);
      sum += w[r[i].second];
      a[x].push_back(make_pair(y, r[i].second));
      a[y].push_back(make_pair(x, r[i].second));
      used[r[i].second] = true;
    }
  }
  dfs(1);
  long long int res = (long long int)1e18;
  int add = 0;
  int del = 0;
  for (int i = (1), _b = (m); i <= _b; i++) {
    int x = r[i].first.first;
    int y = r[i].first.second;
    int id = r[i].second;
    int ts = w[id] - s / c[id];
    int id2 = lca(x, y);
    if (res > sum - w[id2] + ts) {
      res = sum - w[id2] + ts;
      add = id;
      del = id2;
    }
  }
  cout << res << endl;
  for (int i = (1), _b = (m); i <= _b; i++)
    if (used[i] && i != del) {
      printf("%d %d\n", i, w[i]);
    }
  printf("%d %d\n", add, w[add] - (s / c[add]));
}
