#include <bits/stdc++.h>
using namespace std;

bool flg[100][100];
int main() {
	int n; cin >> n;
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < n; ++j) {
			char c; cin >> c;
			flg[i][j] = (c == '1');
		}
		flg[i][i] = true;
	}
	for(int k = 0; k < n; ++k) {
		for(int i = 0; i < n; ++i) {
			for(int j = 0; j < n; ++j) {
				flg[i][j] |= (flg[i][k] & flg[k][j]);
			}
		}
	}
	double ans = 0;
	for(int i = 0; i < n; ++i) {
		int cnt = 0;
		for(int j = 0; j < n; ++j) {
			cnt += flg[j][i];
		}
		ans += 1.0 / (double)cnt;
	}
	printf("%.15f\n", ans);
	return 0;
}

/*
                    author         : TAPAN SAVANI 
                    codeforces     : savanitapan2001
                    codechef       : savanitapan17
*/

/*
------------------------------------------------------------------------

░██╗░░░░░░░██╗░█████╗░██████╗░██╗░░██╗  ██╗░░██╗░█████╗░██████╗░██████╗░
░██║░░██╗░░██║██╔══██╗██╔══██╗██║░██╔╝  ██║░░██║██╔══██╗██╔══██╗██╔══██╗
░╚██╗████╗██╔╝██║░░██║██████╔╝█████═╝░  ███████║███████║██████╔╝██║░░██║
░░████╔═████║░██║░░██║██╔══██╗██╔═██╗░  ██╔══██║██╔══██║██╔══██╗██║░░██║
░░╚██╔╝░╚██╔╝░╚█████╔╝██║░░██║██║░╚██╗  ██║░░██║██║░░██║██║░░██║██████╔╝
░░░╚═╝░░░╚═╝░░░╚════╝░╚═╝░░╚═╝╚═╝░░╚═╝  ╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚═╝╚═════╝░
 
------------------------------------------------------------------------
*/

#include <bits/stdc++.h>
using namespace std;

#define HAPPY_CODING              \
    ios_base::sync_with_stdio(0); \
    cin.tie(NULL);                \
    cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define Debug(x) cout << #x " = " << (x) << endl
#define SORT(a) sort(a.begin(), a.end())
#define SORTR(a) sort(a.rbegin(), a.rend())
#define mod 1000000007
#define pi 3.141592653589793238
#define ll long long int
#define ull unsigned long long
#define be begin()
#define en end()
#define FOR(i, a, b) for (long long int i = a; i < b; i++)
#define FORI(i, a, b) for (int i = a; i >= b; i--)

typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;
typedef vector<PI> VPI;

int main()
{
    HAPPY_CODING;

    int n;
    cin >> n;

    string s;
    cin >> s;

    int q, swapq = 0;
    cin >> q;

    while (q--)
    {
        int t, a, b;
        cin >> t >> a >> b;

        a--, b--;

        if (t == 1)
        {
            if (swapq % 2 == 0)
            {
                char x = s[a];
                s[a] = s[b];
                s[b] = x;
            }
            else
            {
                if (a >= n)
                    a -= n;
                else
                    a += n;

                if (b >= n)
                    b -= n;
                else
                    b += n;

                char x = s[a];
                s[a] = s[b];
                s[b] = x;
            }
        }
        else
        {
            swapq++;
        }
    }
    if (swapq % 2 == 1)
    {
        string s1 = s.substr(0, n);
        string s2 = s.substr(n);

        s = s2 + s1;
    }

    cout << s << "\n";

    return 0;
}
