#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int ddx[] = {1, 0};
int ddy[] = {1, 1};
int n, m;
vector<long long int> vec[100001], vec2[100001];
long long int c[100001];
int vis[100001];
stack<int> tempo;
vector<long long int> aa;
void dfs(int x) {
  vis[x] = 1;
  for (int i = 0; i < int(vec[x].size()); i++) {
    int u = vec[x][i];
    if (!vis[u]) dfs(u);
  }
  tempo.push(x);
}
void dfs2(int x) {
  vis[x] = 1;
  aa.push_back(c[x]);
  for (int i = 0; i < int(vec2[x].size()); i++) {
    int u = vec2[x][i];
    if (!vis[u]) dfs2(u);
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%lld", &c[i]);
  cin >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    vec[a].push_back(b);
    vec2[b].push_back(a);
  }
  for (int i = 1; i <= n; i++)
    if (!vis[i]) dfs(i);
  memset(vis, 0, sizeof vis);
  long long int ans = 0, ans2 = 1;
  while (int(tempo.size())) {
    int u = tempo.top();
    tempo.pop();
    if (vis[u]) continue;
    dfs2(u);
    int aux2 = 0;
    long long int cc = 99999999999999999;
    for (int i = 0; i < int(aa.size()); i++)
      if (aa[i] < cc) cc = aa[i];
    for (int i = 0; i < int(aa.size()); i++)
      if (aa[i] == cc) aux2++;
    ans += cc;
    ans2 = (ans2 * aux2) % 1000000007;
    aa.clear();
  }
  printf("%lld %lld\n", ans, ans2);
  return 0;
}
