#include <iostream>
#include <string>
using namespace std;

struct node{
    int key;
    node *p,*l,*r;
};

int n;
node *N;

void tree_insert(node *z){
    node *y=NULL;
    node *x=N;
    while(x!=NULL){
        y=x;
        if(x->key>z->key)x=x->l;
        else if(x->key<z->key)x=x->r;
    }
    z->p=y;
    if(y==NULL)N=z;
    else if(y->key<z->key)y->r=z;
    else y->l=z;
}

node *find_num(int num){
    node *x=N;
    while(x!=NULL){
        if(x->key==num){
            return x;
        }
        if(x->key>num)x=x->l;
        else x=x->r;
    }
    return x;
}

void tree_find(int num){
    node *x=find_num(num);
    if(x!=NULL)cout<<"yes"<<endl;
    else cout<<"no"<<endl;
}

void in(node *x){
    if(x->l!=NULL)in(x->l);
    cout<<" "<<x->key;
    if(x->r!=NULL)in(x->r);
}

void pre(node *x){
    cout<<" "<<x->key;
    if(x->l!=NULL)pre(x->l);
    if(x->r!=NULL)pre(x->r);
}

node* successor(node *z){
    node *x;
    x=z->r;
    while(x->l!=NULL)x=x->l;
    return x;
}

void tree_delete(node *z){
    node *y;
    if(z->l==NULL||z->r==NULL)y=z;
    else y=successor(z);
    node *x;
    if(y->l!=NULL)x=y->l;
    else x=y->r;
    if(x!=NULL)x->p=y->p;

    if(y->p==NULL) N=x;
    else if(y==y->p->l)y->p->l=x;
    else y->p->r=x;

    if(y!=z) z->key=y->key;
    delete(y);
}

void print(){
    node *x=N;
    in(x);
    cout<<endl;
    pre(x);
    cout<<endl;
}

int main()
{
    N=NULL;
    cin>>n;
    int i;
    for(i=0;i<n;i++){
        string s;
        cin>>s;
        if(s=="insert"){
            int num;
            cin>>num;
            node *z=new node();
            z->key=num;z->l=z->r=z->p=NULL;
            tree_insert(z);
        }
        if(s=="find"){
            int num;
            cin>>num;
            tree_find(num);
        }
        if(s=="print"){
            print();
        }
        if(s=="delete"){
            int num;
            cin>>num;
            node *z=find_num(num);
            tree_delete(z);
        }
    }
    return 0;
}
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()

void dout() { cerr << '\n'; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << " " << H;
    dout(T...);
}

#ifdef LOCAL
    #define dbg(...) cerr << #__VA_ARGS__, dout(__VA_ARGS__)
#else
    #define dbg(...) ;
#endif

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;

const int N = 1003;
char ans[4][7][7], m[N][N];
string arr[4] = {"adeeadffbbghccgh",
"adf..adf..beehhb.giiccgjj",
"adgg..adhh..beii..be..jjcf..kkcf..ll",
"adg....adg....be.ii..be.jj..cff..llc.h..mm..hkknn"
};

void parse(int r) {
    int a = 4 + r;
    for (int i = 0; i < a; i++) {
        for (int j = 0; j < a; j++) {
            ans[r][i][j] = arr[r][i * a + j];
        }
    }
}

void spread(int x, int r) {
    int a = 4 + r;
    for (int i = x; i < x + a; i++) {
        for (int j = x; j < x + a; j++) {
            m[i][j] = ans[r][i - x][j - x];
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false), cin.tie(NULL);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif

    for (int i = 0; i < 4; i++) {
        parse(i);
    }

    int n;
    cin >> n;
    if (n <= 2) {
        cout << -1;
        return 0;
    }
    if (n == 3) {
        cout << "acc\na.d\nbbd";
        return 0;
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            m[i][j] = '.';
        }
    }
    int rem = n % 4;
    spread(0, rem);
    int times = (n - (4 + rem)) / 4, cur = 4 + rem;
    while (times--) {
        spread(cur, 0);
        cur += 4;
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cout << m[i][j];
        }
        cout << '\n';
    }
}
