#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <limits>
#include <ctime>
#include <cassert>
#include <map>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <stack>
#include <queue>
#include <numeric>
#include <iterator>
#include <bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)(c).size())
#define ten(x) ((int)1e##x)

template<typename ...> static inline int getchar_unlocked(void) { return getchar(); }
template<typename ...> static inline void putchar_unlocked(int c) { putchar(c); }
#define mygc(c) (c)=getchar_unlocked()
#define mypc(c) putchar_unlocked(c)
void reader(int& x) { int k, m = 0; x = 0; for (;;) { mygc(k); if (k == '-') { m = 1; break; }if ('0' <= k&&k <= '9') { x = k - '0'; break; } }for (;;) { mygc(k); if (k<'0' || k>'9')break; x = x * 10 + k - '0'; }if (m) x = -x; }
void reader(ll& x) { int k, m = 0; x = 0; for (;;) { mygc(k); if (k == '-') { m = 1; break; }if ('0' <= k&&k <= '9') { x = k - '0'; break; } }for (;;) { mygc(k); if (k<'0' || k>'9')break; x = x * 10 + k - '0'; }if (m) x = -x; }
int reader(char c[]) { int i, s = 0; for (;;) { mygc(i); if (i != ' '&&i != '\n'&&i != '\r'&&i != '\t'&&i != EOF) break; }c[s++] = i; for (;;) { mygc(i); if (i == ' ' || i == '\n' || i == '\r' || i == '\t' || i == EOF) break; c[s++] = i; }c[s] = '\0'; return s; }
template <class T, class S> void reader(T& x, S& y) { reader(x); reader(y); }
template <class T, class S, class U> void reader(T& x, S& y, U& z) { reader(x); reader(y); reader(z); }
template <class T, class S, class U, class V> void reader(T& x, S& y, U& z, V & w) { reader(x); reader(y); reader(z); reader(w); }
void writer(int x, char c) { int s = 0, m = 0; char f[10]; if (x<0)m = 1, x = -x; while (x)f[s++] = x % 10, x /= 10; if (!s)f[s++] = 0; if (m)mypc('-'); while (s--)mypc(f[s] + '0'); mypc(c); }
void writer(ll x, char c) { int s = 0, m = 0; char f[20]; if (x<0)m = 1, x = -x; while (x)f[s++] = x % 10, x /= 10; if (!s)f[s++] = 0; if (m)mypc('-'); while (s--)mypc(f[s] + '0'); mypc(c); }
void writer(const char c[]) { int i; for (i = 0; c[i] != '\0'; i++)mypc(c[i]); }
void writer(const char x[], char c) { int i; for (i = 0; x[i] != '\0'; i++)mypc(x[i]); mypc(c); }
template<class T> void writerLn(T x) { writer(x, '\n'); }
template<class T, class S> void writerLn(T x, S y) { writer(x, ' '); writer(y, '\n'); }
template<class T, class S, class U> void writerLn(T x, S y, U z) { writer(x, ' '); writer(y, ' '); writer(z, '\n'); }
template<class T> void writerArr(T x[], int n) { if (!n) { mypc('\n'); return; }FOR(i, n - 1)writer(x[i], ' '); writer(x[n - 1], '\n'); }

ll mod_pow(ll a, ll n, ll mod) { ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; }
template<class T> T extgcd(T a, T b, T& x, T& y) { for (T u = y = 1, v = x = 0; a;) { T q = b / a; swap(x -= q * u, u); swap(y -= q * v, v); swap(b -= q * a, a); } return b; }
template<class T> T mod_inv(T a, T m) { T x, y; extgcd(a, m, x, y); return (m + x % m) % m; }
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

typedef char valT;

struct node {
	valT val; //???????????????
	node *chl, *chr; //{???,???}
	int pri; //?????????
	int cnt; //??¨?????¨????????????
	bool rev; //?????????
	node() {}
	node(valT v) : val(v), pri(rand()), cnt(1), rev(false) {
		chl = chr = NULL;
	}
};
typedef pair<node*, node*> PN;
void push_flip(node *t);

node *node_allocator(valT val) {
	static node arr[ten(7)];
	static int cnt = 0;
	arr[cnt++] = node(val);
	return &arr[cnt - 1];
}
int count(const node* t) { return t ? t->cnt : 0; }
node* update(node *t) {
	t->cnt = count(t->chl) + count(t->chr) + 1;
	return t;
}
node *merge(node *l, node *r) {
	if (!l || !r) return l ? l : r;
	push_flip(l); push_flip(r);
	if (l->pri > r->pri) { //????????¨?????¨?????????????????????????????????
		l->chr = merge(l->chr, r); //?????¨?????¨?????????????????????????????????
		return update(l);
	} else {
		r->chl = merge(l, r->chl); //?????¨?????¨?????????????????????????????????
		return update(r);
	}
}
PN split(node* t, int k) { //[0,k),[k,n)
	if (!t) return PN(NULL, NULL);
	push_flip(t);
	if (k <= count(t->chl)) {
		PN s = split(t->chl, k);
		t->chl = s.second;
		return PN(s.first, update(t));
	} else {
		PN s = split(t->chr, k - count(t->chl) - 1);
		t->chr = s.first;
		return PN(update(t), s.second);
	}
}
node* insert(node* t, int k, valT val) {
	push_flip(t);
	PN s = split(t, k);
	return merge(merge(s.first, node_allocator(val)), s.second);
}
node *erase(node *t, int k) {
	push_flip(t);
	PN sl = split(t, k);
	PN sr = split(sl.second, 1);
	return merge(sl.first, sr.second);
}
static node LAST('\0');
node *kth(node *t, int k) {
	// assert(t != NULL);
	if (t == NULL) return &LAST;
	push_flip(t);
	if (k < count(t->chl)) return kth(t->chl, k);
	else if (k == count(t->chl)) return t;
	else return kth(t->chr, k - count(t->chl) - 1);
}
void push_flip(node *t) {
	if (t && t->rev) {
		swap(t->chl, t->chr);
		if (t->chl) t->chl->rev ^= true;
		if (t->chr) t->chr->rev ^= true;
		t->rev = false;
	}
}
node *flip(node *t, int l, int r) { //[l,r)
	PN sl = split(t, l);
	PN sr = split(sl.second, r - l);
	node *a = sl.first, *b = sr.first, *c = sr.second;
	b->rev ^= true;
	return merge(merge(a, b), c);
}

//void test() {
//	node *root = NULL;
//	FOR(i, 10) {
//		root = insert(root, 0, Pii(0, i));
//	}
//	//current : 9 8 7 6 5 4 3 2 1 0
//	flip(root, 0, 10);
//	//current : 0 1 2 3 4 5 6 7 8 9
//	flip(root, 1, 9);
//	//current : 0 8 7 6 5 4 3 2 1 9
//	FOR(i, 10) {
//		node* t = kth(root, i);
//		cout << t->val.second << endl;
//	}
//}

void print(vector<node*>& v) {
	FOR(i, sz(v)) {
		auto root = v[i];
		int idx = 0;
		char c;
		while ((c = kth(v[i], idx)->val) != 0) putchar(c), idx++;
		puts("");
	}
}

int main() {
	int n, q; reader(n, q);
	vector<node*> v;
	FOR(i, n) {
		string s; cin >> s;
		node* root = NULL;
		FOR(j, sz(s)) root = insert(root, j, s[j]);
		v.push_back(root);
	}
	FOR(i, q) {
		int t; reader(t);
		if (t == 1) {
			int a, b, c, d; reader(a, b, c, d);
			a--; b--; c--; d--;
			auto& S1 = v[a];
			auto& S2 = v[c];
			node* x, *y, *z, *w;
			tie(x, y) = split(S1, b);
			tie(z, w) = split(S2, d);
			S1 = merge(x, w);
			S2 = merge(z, y);
		} else {
			int a, b; char _c[2]; reader(a, b, _c); char  c = _c[0];
			a--; b--;
			kth(v[a], b)->val = c;
		}
	}

	print(v);

	return 0;
}

Measured memory_bytes: 82988