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

struct treap{
    static const int INF=INT_MAX;

    struct node{
        int val,mini,cnt,pri;
        node *lch,*rch;

        node(int val,int pri):val(val),pri(pri),cnt(1),mini(val){
            lch=rch=NULL;
        }
    };

    node *root;
    treap():root(NULL){srand(time(NULL));}

    int count(node *t){return !t?0:t->cnt;}
    int mini(node *t){return !t?INF:t->mini;}

    node *update(node *t){
        if(!t)return t;
        t->cnt=count(t->lch)+count(t->rch)+1;
        t->mini=min(min(mini(t->lch),mini(t->rch)),t->val);
        return t;
    }

    node *merge(node *l,node *r){
        if(!l||!r)return l?l:r;
        if(l->pri>r->pri){
            l->rch=merge(l->rch,r);
            return update(l);
        }
        r->lch=merge(l,r->lch);
        return update(r);
    }

    pair<node *,node *>split(node *t,int k){
        if(!t)return make_pair((node *)NULL,(node *)NULL);
        if(count(t->lch)>=k){
            pair<node *,node *>s=split(t->lch,k);
            t->lch=s.second;
            return make_pair(s.first,update(t));
        }
        pair<node *,node *>s=split(t->rch,k-count(t->lch)-1);
        t->rch=s.first;
        return make_pair(update(t),s.second);
    }

    node *insert(node *t,int k,int val,int pri){
        pair<node *,node *>s=split(t,k);
        t=merge(s.first,new node(val,pri));
        t=merge(t,s.second);
        return update(t);
    }

    node *erase(node *t,int k){
        pair<node *,node *>s1,s2;
        s2=split(t,k+1);
        s1=split(s2.first,k);
        return update((t=merge(s1.first,s2.second)));
    }


    void insert(int k,int val){
        root=insert(root,k,val,rand());
    }

    void erase(int k){
        root=erase(root,k);
    }

    int rangeMinimumQuery(node *t,int l,int r){
        if(!t)return INF;
        int sz=count(t);
        if(sz<=l||r<=0)return INF;
        if(l<=0&&sz<=r)return mini(t);

        int cnt=count(t->lch);

        int vl=rangeMinimumQuery(t->lch,l,r);
        int vr=rangeMinimumQuery(t->rch,l-cnt-1,r-cnt-1);

        int res=min(vl,vr);
        if(l<=cnt&&cnt<r)res=min(res,t->val);
        return res;
    }

    int rangeMinimumQuery(int l,int r){
        return rangeMinimumQuery(root,l,r);
    }



    void updateNode(int k,int val){
        erase(k);
        insert(k,val);

    }

    void Debug(node *t){
        if(!t)return;
        Debug(t->lch);
        cout<<t->val<<" ";
        Debug(t->rch);
    }

    void Debug(){
        Debug(root);
        cout<<endl;
    }

    void query1(treap &t,int b,int d){
        pair<node *,node *>s1,s2;
        s1=split(root,b);
        s2=t.split(t.root,d);
        root=merge(s1.first,s2.second);
        t.root=merge(s2.first,s1.second);
    }

    void output(node *t){
        if(!t)return;
        output(t->lch);
        printf("%c",t->val+'a');
        output(t->rch);
    }
    void output(){
        output(root);
        puts("");
    }
};

vector<treap>v;
char latte[2000001];
int main(){
    int n,q;
    scanf("%d%d",&n,&q);

    v.resize(n);
    for(int i=0;i<n;i++){
        scanf("%s",latte);
        for(int j=0;latte[j];j++){
            v[i].insert(j,latte[j]-'a');
        }
    }

    while(q--){
        int type;
        scanf("%d",&type);
        if(type==1){
            int a,b,c,d;
            scanf("%d%d%d%d",&a,&b,&c,&d);
            a--;b--;c--;d--;
            v[a].query1(v[c],b,d);
        }
        else{
            int a,b;
            char c;
            scanf("%d%d %c",&a,&b,&c);
            a--;b--;
            v[a].updateNode(b,c-'a');
        }
    }

    for(int i=0;i<n;i++)v[i].output();
    return 0;
}

Measured memory_bytes: 100600