#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int u, v;
  int c;
  int w;
  int id;
  bool use;
};
bool operator<(const Edge& l, const Edge& r) { return l.w < r.w; }
class Node {
  int depth;
  pair<int, int> w;
  Node* parent;

 public:
  Node() : depth(0), w(0, -1), parent(nullptr) {}
  static pair<int, int> merge(Node* a, Node* b, int W, int id) {
    pair<int, int> mx = {-1, -1};
    while ((a->parent || b->parent) && a != b) {
      if (!b->parent || a->parent && a->depth <= b->depth) {
        mx = max(mx, a->w);
        a = a->parent;
      } else {
        mx = max(mx, b->w);
        b = b->parent;
      }
    }
    if (a == b) return {W - mx.first, mx.second};
    if (a->depth < b->depth) swap(a, b);
    b->parent = a;
    b->w.first = W;
    b->w.second = id;
    a->depth = max(a->depth, b->depth + 1);
    return {0, -id};
  }
};
int main(int argc, const char* argv[]) {
  int N, M;
  std::vector<int> W, C;
  int S;
  scanf("%d%d", &N, &M);
  W.resize(M);
  C.resize(M);
  for (auto&& x : W) scanf("%d", &x);
  for (auto&& x : C) scanf("%d", &x);
  vector<Edge> edges(M);
  for (int i = 0; i < M; i++) {
    Edge& e = edges[i];
    scanf("%d %d", &e.u, &e.v);
    e.u--;
    e.v--;
    e.c = C[i];
    e.w = W[i];
    e.id = i + 1;
  }
  scanf("%d", &S);
  sort((edges).begin(), (edges).end());
  vector<Node> nodes(N);
  int best = 1 << 30;
  int exc = -1;
  const Edge* useE = nullptr;
  long long sumw = 0;
  for (auto&& e : edges) {
    pair<int, int> r = Node::merge(&nodes[e.u], &nodes[e.v], e.w, e.id);
    if (r.second < 0) {
      e.use = true;
      sumw += e.w;
      r.second = -r.second;
    } else {
      e.use = false;
    }
    int bonus = r.first - S / e.c;
    if (bonus < best) {
      best = bonus;
      exc = r.second;
      useE = &e;
    }
  }
  printf(
      "%I64d"
      "\n",
      sumw + best);
  for (auto&& e : edges)
    if (e.use && e.id != exc) printf("%d %d\n", e.id, e.w);
  printf("%d %d\n", useE->id, useE->w - S / useE->c);
  return 0;
}
