#include <iostream>
#include <vector>

const int MAXSIZE = 37;

int convert_num(){
    int n;
    std::cin >> n;
    std::vector<std::vector<int>> arr(MAXSIZE, std::vector<int> (MAXSIZE, 0));
    std::string line;
    std::getline(std::cin, line);
    int startj = 1;
    for(size_t i = 1; i<=n; i++){
        std::getline(std::cin, line);
        for(size_t j = 1; j<=line.size(); j++){
            if(line[j-1] == '#'){
                arr[i][j] = 1;
                if(i == 1) startj = j;
                continue;
            }
        }
    }

    int num1 = 1;
    int curj = startj;
    for(size_t i = 1; i<=n; i++){
        if(arr[i+1][curj-1] == 1){
            num1 = num1*2 + 1;
            curj--;
        }
        if(arr[i+1][curj+1] == 1){
            num1 = num1*2;
            curj++;
        }
    }
    return num1;
}

int main() {

    int num1 = convert_num();
    int num2 = convert_num();
    int sum = num1 + num2;

    int L = 0, R = 0, curpos = 0, curnum = sum;
    int cnt = 0;
    while(curnum > 1){
        if(curnum % 2 != 0){
            curpos--;
            L = std::min(L, curpos);
        }
        else{
            curpos++;
            R = std::max(R, curpos);
        }
        curnum/=2;
        cnt++;
    }

    char res[MAXSIZE][MAXSIZE];
    cnt++;
    std::cout << cnt << '\n';
    int pos = -L, n = R-L+1, nextpos = -1;
    int i = 0;
    while(sum >= 1){
        for(int j = 0; j<n; j++){
           if(j == pos){
               res[i][j] = '#';

               if(sum % 2 != 0) nextpos = pos-1;
               else nextpos = pos+1;

               sum/=2;
           }
           else res[i][j] = '.';

        }
        pos = nextpos;
        i++;
        //if(sum != 0) std::cout << '\n';
    }

    for(int i = cnt-1; i>=0; i--){
        for(int j = n-1; j>=0; j--){
            std::cout << res[i][j];
        }
        if(i!=0)std::cout << '\n';
    }

    return 0;
}
