#include <bits/stdc++.h>
using namespace std;
class sp {
 public:
  int q;
  sp *w;
  sp(int q1, sp *w1) {
    q = q1;
    w = w1;
  }
};
sp *a[100000];
int d[100000], f[100000];
int k(int q) {
  if (f[f[q]] != f[q]) f[q] = k(f[q]);
  return f[q];
}
void l(int q, int w) {
  d[q] = w;
  sp *c;
  for (c = a[q]; c; c = c->w)
    if (d[c->q] == 0) {
      l(c->q, w + 1);
      if ((d[k(c->q)] > 0) && (d[k(q)] > d[k(c->q)])) f[k(q)] = k(c->q);
    } else if ((d[k(c->q)] > 0) && (d[k(q)] > d[k(c->q)]))
      f[k(q)] = k(c->q);
  d[q] = -1;
}
int main() {
  int q, w, e, r;
  long long s[100000], s1[100000], *s2 = new long long[100000], t = 0, y = 1;
  scanf("%d", &q);
  for (w = 0; w < q; w++) {
    scanf("%d", &e);
    s[w] = e;
    s1[w] = 0;
    s2[w] = 2000000000;
    d[w] = 0;
    f[w] = w;
  }
  scanf("%d", &w);
  for (; w; w--) {
    scanf("%d%d", &e, &r);
    e--;
    r--;
    a[e] = new sp(r, a[e]);
  }
  for (w = 0; w < q; w++)
    if (d[w] == 0) l(w, 1);
  for (w = 0; w < q; w++)
    if (s2[k(w)] > s[w]) {
      s2[k(w)] = s[w];
      s1[k(w)] = 1;
    } else if (s2[k(w)] == s[w])
      s1[k(w)]++;
  for (w = 0; w < q; w++)
    if (w == k(w)) {
      t += s2[w];
      y = (y * s1[w]) % 1000000007;
    }
  cout << t << " " << y;
  return 0;
}
