#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds; 

#define int         long long
#define ull         unsigned long long
#define ll          long long
#define M           998244353
#define pb          push_back
#define p_q         priority_queue
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mp          make_pair
#define lb          lower_bound
#define ub          upper_bound
#define F           first
#define S           second
#define rep(i, begin, end) for (int i=begin;i<end;i++)
#define repd(i, begin, end) for (int i=end-1;i>=begin;i--)
#define ini(a,n,b)  for(ll int i=0;i<n;i++) a[i]=0;
#define cset(a)     __builtin_popcountll(a)
#define hell        1000000007
#define re          resize
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update >
const int INF=1e18;
const int N=3e5+5;

int powm(int a,int b,int mod)
{
  int res=1;
  while(b)
  {
    if(b&1) 
    res=(res*a)%mod;
      a=(a*a)%mod;
      b>>=1;
  }
 
  return res;
}

int pow(int a,int b)
{
  int res=1;
  while(b)
  {
    if(b&1) 
    res=(res*a);
      a=(a*a);
      b>>=1;
  }
 
  return res;
}


vi par(N,1),siz(N,1);

void init(int n)
{
   for(int i=1;i<=n;i++) par[i]=i;
}
int find(int x)
{
   if(par[x]==x) return x;
   return par[x]=find(par[x]);
}
void merge(int x,int y)
{
   x=find(x);
   y=find(y);
   if(x==y) return;
   if(siz[x]<siz[y]) swap(x,y);
   par[y]=x;
   siz[x]+=siz[y];
}

signed main(void)
{ios
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);freopen("answer.txt", "w", stdout);
    #endif

      
    int tests=1;
    // cin>>tests;
    while(tests--)
    {  
      int n;
      cin>>n;
      vi a(n+1);
      rep(i,1,n+1) cin>>a[i];
      int ans=0;
      vi vis(n+1,0);
      init(n);

      rep(i,1,n+1)
      {
         merge(i,a[i]);
      }

      rep(i,1,n+1)
      {
         if(par[i]==i) ans++;
      }
      ans=powm(2,ans,M);
      ans=(ans-1+M)%M;
      cout<<ans<<endl;
    }

                      
}





#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

template <typename T1, typename T2>
inline void chmin(T1 &a, T2 b) {
    if (a > b) a = b;
}

template <typename T>
struct BIT {
    int n;
    vector<T> dat;

    BIT(int n) : n(n), dat(n + 1, 0) {}

    T sum(int idx) {  // 1-indexed
        T res(0);
        for (int i = idx; i > 0; i -= i & -i) res += dat[i];
        return res;
    }

    T sum(int l, int r) {  // 0-indexed
        return sum(r) - sum(l);
    }

    void add(int idx, T x) {  // 0-indexed
        idx++;
        for (int i = idx; i <= n; i += i & -i) dat[i] += x;
    }

    int lower_bound(T x) {
        if (x <= 0) return T(0);
        int res = 0, r = 1;
        while (r < n) r <<= 1;
        for (; r > 0; r >>= 1) {
            if (res + r <= n && dat[res + r] < x) {
                x -= dat[res + r];
                res += r;
            }
        }
        return res + 1;
    }

    void print() {
        for (int i = 0; i < n; i++) cout << sum(i, i + 1) << " ";
        cout << endl;
    }
};

signed main() {
    int h, w, m;
    cin >> h >> w >> m;
    int mnx[w], mny[h];
    fill(mnx, mnx + w, h);
    fill(mny, mny + h, w);
    vector<int> vy[h];
    int x, y;
    rep(i, m) {
        cin >> x >> y;
        x--;
        y--;
        chmin(mnx[y], x);
        chmin(mny[x], y);
        vy[x].emplace_back(y);
    }
    ll ans = 0;
    rep(y, w) {
        if (mnx[y] == 0) break;
        ans += mnx[y];
    }
    BIT<int> bit(w);
    rep(x, h) {
        if (mny[x] == 0) break;
        ans += bit.sum(0, mny[x]);
        if (x == 0) {
            for (int y = mny[x]; y < w; y++) {
                bit.add(y, 1);
            }
            continue;
        }
        for (int y : vy[x]) {
            if (bit.sum(y, y + 1) == 0) bit.add(y, 1);
        }
    }
    cout << ans << endl;
    return 0;
}