#include <utility>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdint>
#include <limits>
#include <iostream>
namespace lc {
template <class T>
struct SumTraits {
	typedef T value_type;
	value_type operator()(const value_type &a, const value_type &b) const {
		return a + b;
	}
};
}
namespace lc {
inline unsigned int xorshift128(){
	static uint32_t x = 192479812;
	static uint32_t y = 784892731;
	static uint32_t z = 427398108;
	static uint32_t w = 48382934; 
	const uint32_t t = x ^ (x << 11);
	x = y; y = z; z = w;
	w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); 
	return w;
}
}
namespace lc {
template <class Traits>
class TreapList {
public:
	typedef typename Traits::value_type value_type;
private:
	struct node_type {
		value_type value;
		value_type cache;
		unsigned int priority;
		size_t size;
		node_type *children[2];
	};
	Traits m_traits;
	node_type *m_root;
	void initialize_node(node_type *p, const value_type &v){
		p->value = p->cache = v;
		p->priority = xorshift128();
		p->size = 1;
		p->children[0] = p->children[1] = nullptr;
	}
	void destroy(node_type *p) const {
		if(p == nullptr){ return; }
		destroy(p->children[0]);
		destroy(p->children[1]);
		delete p;
	}
	size_t size(const node_type *p) const {
		if(p == nullptr){ return 0; }
		return p->size;
	}
	node_type *kth(node_type *p, size_t k) const {
		if(k >= size(p)){ return nullptr; }
		if(k < size(p->children[0])){ return kth(p->children[0], k); }
		if(k == size(p->children[0])){ return p; }
		return kth(p->children[1], k - 1 - size(p->children[0]));
	}
	node_type *refresh(node_type *p) const {
		if(p == nullptr){ return nullptr; }
		p->cache = p->value;
		if(p->children[0] != nullptr){
			p->cache = m_traits(p->children[0]->cache, p->cache);
		}
		if(p->children[1] != nullptr){
			p->cache = m_traits(p->cache, p->children[1]->cache);
		}
		p->size = 1 + size(p->children[0]) + size(p->children[1]);
		return p;
	}
	node_type *merge(node_type *l, node_type *r) const {
		if(l == nullptr){ return r; }
		if(r == nullptr){ return l; }
		if(l->priority > r->priority){
			l->children[1] = merge(l->children[1], r);
			return refresh(l);
		}else{
			r->children[0] = merge(l, r->children[0]);
			return refresh(r);
		}
	}
	std::pair<node_type *, node_type *> split(node_type *t, size_t k) const {
		if(t == nullptr){ return std::make_pair(nullptr, nullptr); }
		if(k <= size(t->children[0])){
			const auto s = split(t->children[0], k);
			t->children[0] = s.second;
			return std::make_pair(s.first, refresh(t));
		}else{
			const auto s = split(t->children[1], k - size(t->children[0]) - 1);
			t->children[1] = s.first;
			return std::make_pair(refresh(t), s.second);
		}
	}
public:
	explicit TreapList(const Traits &traits = Traits())
		: m_traits(traits)
		, m_root(nullptr)
	{ }
	TreapList(TreapList<Traits> &&x)
		: m_traits(x.m_traits)
		, m_root(x.m_root)
	{
		x.m_root = nullptr;
	}
	~TreapList(){ destroy(m_root); }
	size_t size() const { return size(m_root); }
	const value_type &operator[](size_t k) const {
		return kth(m_root, k)->value;
	}
	void insert(size_t k, const value_type &x){
		const auto p = split(m_root, k);
		node_type *node = new node_type();
		initialize_node(node, x);
		m_root = merge(merge(p.first, node), p.second);
	}
	void erase(size_t k){
		const auto p = split(m_root, k);
		const auto q = split(p.second, 1);
		delete q.first;
		m_root = merge(p.first, q.second);
	}
	void update(size_t k, const value_type &x){
		erase(k);
		insert(k, x);
	}
	void merge(TreapList<Traits> &&t){
		m_root = merge(m_root, t.m_root);
		t.m_root = nullptr;
	}
	TreapList<Traits> split(size_t k){
		TreapList<Traits> result(m_traits);
		const auto p = split(m_root, k);
		m_root = p.first;
		result.m_root = p.second;
		return result;
	}
};
}
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	int n, q;
	cin >> n >> q;
	vector<lc::TreapList<lc::SumTraits<char>>> strings(n);
	for(int i = 0; i < n; ++i){
		string s;
		cin >> s;
		const int m = s.size();
		for(int j = 0; j < m; ++j){ strings[i].insert(j, s[j]); }
	}
	for(int i = 0; i < q; ++i){
		int t;
		cin >> t;
		if(t == 1){
			int a, b, c, d;
			cin >> a >> b >> c >> d;
			--a; --b; --c; --d;
			auto x = strings[a].split(b);
			auto y = strings[c].split(d);
			strings[a].merge(std::move(y));
			strings[c].merge(std::move(x));
		}else if(t == 2){
			int a, b;
			string c;
			cin >> a >> b >> c;
			--a; --b;
			strings[a].update(b, c[0]);
		}
	}
	for(int i = 0; i < n; ++i){
		const int len = strings[i].size();
		string s(len, ' ');
		for(int j = 0; j < len; ++j){ s[j] = strings[i][j]; }
		cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 97424