#include <bits/stdc++.h>
int n, m;
int a, b;
int kolor;
int mod = 1000000007;
long long int suma, sposoby = 1;
std::vector<int> kolejnosc;
int sp[100003];
int tab[100003];
bool odw[100003];
std::pair<int, int> ile[100003];
std::vector<int> graf[100003];
std::vector<int> odwr[100003];
void DFS(int x) {
  odw[x] = true;
  for (int i = 0; i < (int)graf[x].size(); i++)
    if (odw[graf[x][i]] == false) DFS(graf[x][i]);
  kolejnosc.push_back(x);
}
void SCC(int x, int kol) {
  sp[x] = kol;
  for (int i = 0; i < (int)odwr[x].size(); i++)
    if (sp[odwr[x][i]] == 0) SCC(odwr[x][i], kol);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &tab[i]);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &a, &b);
    graf[a].push_back(b);
    odwr[b].push_back(a);
  }
  for (int i = 1; i <= n; i++)
    if (odw[i] == false) DFS(i);
  for (int i = (int)kolejnosc.size() - 1; i >= 0; i--)
    if (sp[kolejnosc[i]] == 0) SCC(kolejnosc[i], ++kolor);
  for (int i = 1; i <= n; i++) ile[sp[i]] = {tab[i], 0};
  for (int i = 1; i <= n; i++) {
    if (ile[sp[i]].first > tab[i]) ile[sp[i]] = {tab[i], 0};
    if (ile[sp[i]].first == tab[i]) ile[sp[i]].second++;
  }
  for (int i = 1; i <= kolor; i++) {
    suma += ile[i].first;
    sposoby = (sposoby * ile[i].second) % mod;
  }
  printf("%lld %lld\n", suma, sposoby);
}
