#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (!a) return b;
  return gcd(b % a, a);
}
long long mpower(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) {
      res = (res * x) % p;
    }
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long power(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = res * x;
    y = y >> 1;
    x = x * x;
  }
  return res;
}
long long aa[5000000];
long long root(long long x) {
  while (aa[x] != x) {
    aa[x] = aa[aa[x]];
    x = aa[x];
  }
  return x;
}
void union1(long long x, long long y) {
  long long a = root(x);
  long long b = root(y);
  aa[a] = b;
}
bool find(long long x, long long y) {
  long long a = root(x);
  long long b = root(y);
  return a == b;
}
long long upper(long long k) { return ceil((-1.0 + sqrt(1 + 8 * k)) / 2.0); }
void precal() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
stack<long long> s;
bool visited[100005];
vector<long long> adj[100005];
vector<long long> adj1[100005];
vector<long long> temp;
vector<pair<long long, long long> > ans;
void dfs(long long x) {
  visited[x] = true;
  for (long long i = 0; i < adj[x].size(); i++) {
    long long adjver = adj[x][i];
    if (!visited[adjver]) {
      dfs(adjver);
    }
  }
  s.push(x);
}
void dfs1(long long x) {
  visited[x] = true;
  for (long long i = 0; i < adj1[x].size(); i++) {
    long long adjver = adj1[x][i];
    if (!visited[adjver]) {
      dfs1(adjver);
    }
  }
  temp.push_back(x);
}
int main() {
  precal();
  long long n;
  cin >> n;
  long long a[n + 5];
  for (long long i = 1; i < n + 1; i++) {
    cin >> a[i];
  }
  long long m;
  cin >> m;
  for (long long i = 0; i < m; i++) {
    long long u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj1[v].push_back(u);
  }
  for (long long i = 1; i < n + 1; i++) {
    if (!visited[i]) {
      dfs(i);
    }
  }
  memset(visited, 0, sizeof visited);
  while (!s.empty()) {
    long long x = s.top();
    s.pop();
    if (!visited[x]) {
      temp.clear();
      dfs1(x);
      long long mn = LONG_LONG_MAX;
      for (long long i = 0; i < temp.size(); i++) {
        mn = min(mn, a[temp[i]]);
      }
      long long cnt = 0;
      for (long long i = 0; i < temp.size(); i++) {
        if (a[temp[i]] == mn) {
          cnt++;
        }
      }
      ans.push_back(make_pair(mn, cnt));
    }
  }
  long long sum = 0;
  long long mul = 1;
  for (long long i = 0; i < ans.size(); i++) {
    sum += ans[i].first;
    mul = (mul * ans[i].second) % 1000000007;
  }
  cout << sum << " " << mul << endl;
  return 0;
}
