#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define rep2(i,n) for(ll i=1;i<=(n);++i)
#define rep3(i,i0,n) for(ll i=i0;i<(n);++i)
#define rrep(i,n) for(ll i=((n)-1); i>=0; --i)
#define rrep2(i,n) for(ll i=(n); i>0; --i)
#define pb push_back
#define mod 998244353
#define fi first
#define se second
#define len(x) ((ll)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
using Pi = pair< ll, ll >;
using vl = vector<ll>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vp = vector<Pi>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

const ll INF = 1LL << 60;
const ld PI = 3.1415926535897932385;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mp make_pair
void printb(ll N,ll d=16){
    rep(i,d){
        cout<<(N/(1<<(d-i-1)))%2;
    }
    cout<<endl;
    
}
void printv(vector<ll>a){
    rep(i,a.size()){
        if(i==a.size()-1){
            cout<<a[i]<<endl;
        }else{
            cout<<a[i]<<" ";
        }
    }
}
bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


//const vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1};
//const vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1};
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};
long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
class UnionFind {
    public:
        UnionFind() : _n(0) {}
        UnionFind(ll n) : _n(n), parent_or_size(n, -1) {}
        ll merge(ll a, ll b) {
            assert(0 <= a && a < _n);
            assert(0 <= b && b < _n);
            ll x = leader(a), y = leader(b);
            if (x == y) return x;
            if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y);
            parent_or_size[x] += parent_or_size[y];
            parent_or_size[y] = x;
            return x;
        }
        bool same(ll a, ll b) {
            assert(0 <= a && a < _n);
            assert(0 <= b && b < _n);
            return leader(a) == leader(b);
        }
        ll leader(ll a) {
            assert(0 <= a && a < _n);
            if (parent_or_size[a] < 0) return a;
            return parent_or_size[a] = leader(parent_or_size[a]);
        }
        ll size(ll a) {
            assert(0 <= a && a < _n);
            return -parent_or_size[leader(a)];
        }
        vvl groups() {
            vl leader_buf(_n), group_size(_n);
            rep (i, _n) {
                leader_buf[i] = leader(i);
                group_size[leader_buf[i]]++;
            }
            vvl result(_n);
            rep (i, _n) result[i].reserve(group_size[i]);
            rep (i, _n) result[leader_buf[i]].pb(i);
            result.erase(
            remove_if(all(result), [&](const vl& v) { return v.empty(); }), result.end());
            return result;
        }
    private:
        ll _n;
        // root node: -1 * component size
        // otherwise: parent
        std::vector<ll> parent_or_size;
};
int main() {
    ll N;
    cin>>N;

    UnionFind uf(N);

    rep(i,N){
        ll f;
        cin>>f;
        f--;
        if(!uf.same(i,f)){
            uf.merge(i,f);
        }
    }

    ll M=len(uf.groups());
    ll ans=(modpow(2,M)-1+mod)%mod;

    cout<<ans<<endl;
    
    return 0;
    

}
// とりあえず，
// a[i] = x[i], b[i] = y[i], c[i] = x[i] + 1, d[i] = y[i] + 1
// として，面積 1 の正方形で囲むことにする。
// まずは入力形式の確認。

#include <bits/stdc++.h>

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int _i=(first);_i<(last);++_i){cout<<#a<<"["<<_i<<"] = "<<(a)[_i]<<endl;}
#define PRINTI(a,i)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl;
#define dprintf(...) printf(__VA_ARGS__)
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#define PRINTI(a,i)
#define dprintf(...)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

using namespace std;

using ll = long long;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

template <class T, class U>
std::ostream& operator<<(std::ostream &os, const std::pair<T, U> &p) {
	os << "(" << p.first << ", " << p.second << ")";
	return os;
}
 
template <class T>
std::ostream& operator<<(std::ostream &os, const std::vector<T> &v) {
    os << "[";
	for (int i = 0; i < v.size(); ++i) {
        if (i) {
            if (i % 5 == 0) {
                os << ",\n ";
            } else {
                os << ", ";
            }
        }
		os << v[i];
	}
	os << "]";
	return os;
}

const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

enum {
    DOWN,
    RIGHT,
    UP,
    LEFT,
};


int n;
vector<int> x, y, r;
vector<int> a, b, c, d;
vector<int> a_best, b_best, c_best, d_best;

void read_input() {
    cin >> n;
    x.resize(n);
    y.resize(n);
    r.resize(n);
    REP(i, n) cin >> x[i] >> y[i] >> r[i];

    a.resize(n);
    b.resize(n);
    c.resize(n);
    d.resize(n);
    a_best.resize(n);
    b_best.resize(n);
    c_best.resize(n);
    d_best.resize(n);
}

void write_answer() {
    REP(i, n) {
        cout << a_best[i] << " "
             << b_best[i] << " "
             << c_best[i] << " "
             << d_best[i] << "\n";
    }
    cout << flush;
}

void solve1() {
    REP(i, n) {
        a_best[i] = x[i];
        b_best[i] = y[i];
        c_best[i] = x[i] + 1;
        d_best[i] = y[i] + 1;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    read_input();
    solve1();
    write_answer();

    return 0;
}
