import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Div1_516E {

	static int N;
	static char[][] grid;
	static int[] tar;
	static int[] st;

	public static void main(String[] args) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter printer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		N = Integer.parseInt(reader.readLine());
		tar = new int[N];
		st = new int[N];

		StringTokenizer inputData = new StringTokenizer(reader.readLine());
		for (int i = 0; i < N; i++) {
			tar[i] = Integer.parseInt(inputData.nextToken()) - 1;
			st[tar[i]] = i;
		}
		boolean perf = true;
		for (int i = 0; i < N; i++) {
			if (tar[i] != i) {
				perf = false;
				break;
			}
		}

		if (perf) {
			printer.println(N);
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < N; j++) {
					printer.print('.');
				}
				printer.println();
			}
			printer.close();
			return;
		}

		grid = new char[N][N];
		for (int i = 0; i < N; i++) {
			Arrays.fill(grid[i], '.');
		}

		visited = new boolean[N];

		cycle = new ArrayList<>();
		fCycle(st[N - 1]);
		ArrayList<Integer> pLast = cycle;

		int cH = 0;
		for (int i = 0; i < N; i++) {
			if (!visited[i]) {
				cycle = new ArrayList<>();
				fCycle(i);
				if (cycle.size() == 1) {
					continue;
				}

				if (cycle.get(0) != N - 1) {
					grid[cH][N - 1] = '/';
				}
				for (int j = 0; j < cycle.size() - 1; j++) {
					int cSt = cycle.get(j);
					if (cSt == N - 1) {
						continue;
					}
					int cTar = tar[cSt];
					if (cTar < cSt) {
						grid[cH][cTar] = '\\';
						grid[cH][cSt] = '\\';
					} else {
						grid[cH][cSt] = '/';
						grid[cH][cTar] = '/';
					}
					cH++;
				}
				if (cycle.get(cycle.size() - 1) != N - 1 && cycle.get(cycle.size() - 2) != N - 1) {
					grid[cH][N - 1] = '\\';
					grid[cH][cycle.get(cycle.size() - 2)] = '\\';
					cH++;
				}
			}
		}
		if (pLast != null) {
			cycle = pLast;
			if (cycle.get(0) != N - 1) {
				grid[cH][N - 1] = '/';
			}
			for (int j = 0; j < cycle.size() - 1; j++) {
				int cSt = cycle.get(j);
				if (cSt == N - 1) {
					continue;
				}
				int cTar = tar[cSt];
				if (cTar < cSt) {
					grid[cH][cTar] = '\\';
					grid[cH][cSt] = '\\';
				} else {
					grid[cH][cSt] = '/';
					grid[cH][cTar] = '/';
				}
				cH++;
			}
			if (cycle.get(cycle.size() - 1) != N - 1 && cycle.get(cycle.size() - 2) != N - 1) {
				grid[cH][N - 1] = '\\';
				grid[cH][cycle.get(cycle.size() - 2)] = '\\';
				cH++;
			}
		}

		printer.println(N - 1);
		for (int i = N - 1; i >= 0; i--) {
			for (int j = 0; j < N; j++) {
				printer.print(grid[i][j]);
			}
			printer.println();
		}
		printer.close();
	}

	static boolean[] visited;

	static ArrayList<Integer> cycle;

	static void fCycle(int i) {
		visited[i] = true;
		cycle.add(i);

		int nxt = st[i];
		if (!visited[nxt]) {
			fCycle(nxt);
		}
	}

}


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 5;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); }
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int n, a[MAXN];
char ans[MAXN][MAXN];
int main() {
	read(n);
	bool all = true;
	for (int i = 1; i <= n; i++) {
		read(a[i]);
		if (a[i] != i) all = false;
		for (int j = 1; j <= n; j++)
			ans[i][j] = '.';
	}
	if (all) {
		printf("%d\n", n);
		for (int i = 1; i <= n; i++)
			printf("%s\n", ans[i] + 1);
		return 0;
	}
	int token = 1, pos = 0;
	for (int i = 1; i <= n; i++)
		if (a[i] == 1) pos = i;
	for (int i = n; i >= 1; i--) {
		if (token == pos) {
			int dest = 0;
			for (int j = 1; j <= n; j++)
				if (a[j] < j) dest = j;
			if (dest == 0) continue;
			ans[i][dest] = ans[i][a[dest]] = ans[i][pos] = '\\';
			int x = dest, y = a[dest];
			swap(a[x], a[y]), swap(a[pos], a[x]), pos = x;
		} else {
			int dest = 0;
			for (int j = 1; j <= n; j++)
				if (a[j] == pos) dest = j;
			if (dest > pos) ans[i][dest] = ans[i][pos] = '\\';
			else ans[i][dest] = ans[i][pos] = '/';
			swap(a[pos], a[dest]), pos = dest;
		}
	}
	printf("%d\n", n - 1);
	for (int i = 1; i <= n; i++)
		printf("%s\n", ans[i] + 1);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 5;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); }
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int n, a[MAXN];
char ans[MAXN][MAXN];
int main() {
	read(n);
	bool all = true;
	for (int i = 1; i <= n; i++) {
		read(a[i]);
		if (a[i] != i) all = false;
		for (int j = 1; j <= n; j++)
			ans[i][j] = '.';
	}
	if (all) {
		printf("%d\n", n);
		for (int i = 1; i <= n; i++)
			printf("%s\n", ans[i] + 1);
		return 0;
	}
	int token = a[1], pos = 1;
	for (int i = 1; i <= n; i++) {
		if (token == pos) {
			int dest = 0;
			for (int j = 1; j <= n; j++)
				if (a[j] != pos) dest = j;
			if (dest == 0) continue;
			if (dest > pos) ans[i][dest] = ans[i][pos] = '/';
			else ans[i][dest] = ans[i][pos] = '\\';
			swap(a[pos], a[dest]), pos = dest;
		} else {
			int dest = 0;
			for (int j = 1; j <= n; j++)
				if (a[j] == pos) dest = j;
			if (dest > pos) ans[i][dest] = ans[i][pos] = '/';
			else ans[i][dest] = ans[i][pos] = '\\';
			swap(a[pos], a[dest]), pos = dest;
		}
	}
	printf("%d\n", n - 1);
	for (int i = 1; i <= n; i++)
		printf("%s\n", ans[i] + 1);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 5;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); }
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int n, a[MAXN];
char ans[MAXN][MAXN];
int main() {
	read(n);
	bool all = true;
	for (int i = 1; i <= n; i++) {
		read(a[i]);
		if (a[i] != i) all = false;
		for (int j = 1; j <= n; j++)
			ans[i][j] = '.';
	}
	if (all) {
		printf("%d\n", n);
		for (int i = 1; i <= n; i++)
			printf("%s\n", ans[i] + 1);
		return 0;
	}
	int token = a[1], pos = 1, i = n;
	/*for (i = i; i >= 1; i -= 2) {
		static bool vis[MAXN];
		memset(vis, false, sizeof(vis));
		for (int j = 1; !vis[j]; j = a[j])
			vis[j] = true;
		int x = 0, y = 0;
		for (int j = 1; j <= n; j++)
			if (!vis[j] && a[j] != j) x = j, y = a[j];
		if (x == 0) break;
		swap(a[x], a[y]);
		ans[i][1] = ans[i][x] = ans[i][y] = '\\';
		ans[i - 1][1] = ans[i - 1][max(x, y)] = '/';
	}*/
	for (i = i; i >= 1; i--) {
		if (token == pos) {
			int dest = 0;
			for (int j = 1; j <= n; j++)
				if (a[j] != j) dest = j;
			if (dest == 0) continue;
			if (dest > pos) ans[i][dest] = ans[i][pos] = '\\';
			else ans[i][dest] = ans[i][pos] = '/';
			swap(a[pos], a[dest]), pos = dest;
		} else {
			int dest = 0;
			for (int j = 1; j <= n; j++)
				if (a[j] == pos) dest = j;
			if (dest > pos) ans[i][dest] = ans[i][pos] = '\\';
			else ans[i][dest] = ans[i][pos] = '/';
			swap(a[pos], a[dest]), pos = dest;
		}
	}
	printf("%d\n", n - 1);
	for (int i = 1; i <= n; i++)
		printf("%s\n", ans[i] + 1);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 5;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); }
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int n, a[MAXN];
char ans[MAXN][MAXN];
int main() {
	read(n);
	bool all = true;
	for (int i = 1; i <= n; i++) {
		read(a[i]);
		if (a[i] != i) all = false;
		for (int j = 1; j <= n; j++)
			ans[i][j] = '.';
	}
	if (all) {
		printf("%d\n", n);
		for (int i = 1; i <= n; i++)
			printf("%s\n", ans[i] + 1);
		return 0;
	}
	int token = a[1], pos = 1, i = n;
	for (i = i; i >= 1; i -= 2) {
		static bool vis[MAXN];
		memset(vis, false, sizeof(vis));
		for (int j = 1; !vis[j]; j = a[j])
			vis[j] = true;
		int x = 0, y = 0;
		for (int j = 1; j <= n; j++)
			if (!vis[j] && a[j] != j) x = j, y = a[j];
		if (x == 0) break;
		swap(a[x], a[y]);
		ans[i][1] = ans[i][x] = ans[i][y] = '\\';
		ans[i - 1][1] = ans[i - 1][max(x, y)] = '/';
	}
	for (i = i; i >= 1; i--) {
		if (token == pos) {
			int dest = 0;
			for (int j = 1; j <= n; j++)
				if (a[j] != j) dest = j;
			if (dest == 0) continue;
			if (dest > pos) ans[i][dest] = ans[i][pos] = '\\';
			else ans[i][dest] = ans[i][pos] = '/';
			swap(a[pos], a[dest]), pos = dest;
		} else {
			int dest = 0;
			for (int j = 1; j <= n; j++)
				if (a[j] == pos) dest = j;
			if (dest > pos) ans[i][dest] = ans[i][pos] = '\\';
			else ans[i][dest] = ans[i][pos] = '/';
			swap(a[pos], a[dest]), pos = dest;
		}
	}
	printf("%d\n", n - 1);
	for (int i = 1; i <= n; i++)
		printf("%s\n", ans[i] + 1);
	return 0;
}


#include <bits/stdc++.h>

using std::pair;
using std::vector;
using std::string;

typedef long long ll;
typedef pair<int, int> pii;

#define fst first
#define snd second
#define pb(a) push_back(a)
#define mp(a, b) std::make_pair(a, b)
#define debug(...) fprintf(stderr, __VA_ARGS__)

template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }

const int oo = 0x3f3f3f3f;

string procStatus() {
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}

template <typename T> T read(T& x) {
    int f = 1; x = 0;
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    return x *= f;
}

const int N = 2000;

int n;
bool vis[N + 5];

int lst[N + 5];
int Lst[N + 5];
int ans[N + 5][N + 5];
int a[N + 5], from[N + 5];

void chk() {
    for(int i = 1; i <= n; ++i) if(a[i] != i) { return; }
    printf("%d\n", n);
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= n; ++j) {
            putchar('.');
        }
        puts("");
    }
    exit(0);
}

int main() {
#ifdef Wearry
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    scanf("%d", &n);
    for(int i = 1; i <= n; ++i) scanf("%d", a + i), from[a[i]] = i;

    chk();

    int cur = 0;
    for(int i = 1; i <= n; ++i) if(a[i] != i) { cur = i; break; }
    for(int i = from[cur]; i != cur; i = from[i]) vis[i] = true;

    int c = n, dir;

    for(int i = cur + 1; i <= n; ++i) if(a[i] != i && !vis[i]) {
        dir = 1;
        vis[i] = true;
        ans[c][i] = ans[c][cur] = 1;

        for(int j = from[i]; j != i; j = from[j]) {

            vis[j] = true;
            if(a[j] < j) {
                c -= (dir == 2);
                dir = ans[c][a[j]] = ans[c][j] = 1;
            } else {
                c -= (dir == 1);
                dir = ans[c][a[j]] = ans[c][j] = 2;
            }
        }
        -- c;
        ans[c][cur] = ans[c][a[i]] = 2;
        -- c;
    }

    dir = 1;
    for(int i = from[cur]; i != cur; i = from[i]) {
        if(a[i] < i) {
            c -= (dir == 2);
            dir = ans[c][a[i]] = ans[c][i] = 1;
        } else {
            c -= (dir == 1);
            dir = ans[c][a[i]] = ans[c][i] = 2;
        }
    }

    //std::cout << count() << std::endl;

    printf("%d\n", n - 1);
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= n; ++j) {
            printf("%c", ans[i][j] == 0 ? '.' : (ans[i][j] == 1 ? '\\' : '/'));
        }
        puts("");
    }

    return 0;
}


#include <bits/stdc++.h>

using std::pair;
using std::vector;
using std::string;

typedef long long ll;
typedef pair<int, int> pii;

#define fst first
#define snd second
#define pb(a) push_back(a)
#define mp(a, b) std::make_pair(a, b)
#define debug(...) fprintf(stderr, __VA_ARGS__)

template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }

const int oo = 0x3f3f3f3f;

string procStatus() {
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}

template <typename T> T read(T& x) {
    int f = 1; x = 0;
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    return x *= f;
}

const int N = 2000;

int n;
bool vis[N + 5];

int lst[N + 5];
int Lst[N + 5];
int ans[N + 5][N + 5];
int a[N + 5], from[N + 5];

void chk() {
    for(int i = 1; i <= n; ++i) if(a[i] != i) {
        return;
    }
    printf("%d\n", n);
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= n; ++j) {
            putchar('.');
        }
        puts("");
    }
    exit(0);
}

int main() {
#ifdef Wearry
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    scanf("%d", &n);
    for(int i = 1; i <= n; ++i) scanf("%d", a + i), from[a[i]] = i;

    chk();

    int cur = 0;
    for(int i = 1; i <= n; ++i) if(a[i] != i) {
        cur = i;
        break;
    }

    int c = n, dir = 1;
    for(int i = from[cur]; i != cur; i = from[i]) {
        vis[i] = true;
        debug("%d\n", i);

        if(a[i] < i) {
            c -= (dir == 2);
            dir = ans[c][a[i]] = ans[c][i] = 1;
        } else {
            c -= (dir == 1);
            dir = ans[c][a[i]] = ans[c][i] = 2;
        }
    }

    int l = c;
    c = n;

    for(int i = cur + 1; i <= n; ++i) if(a[i] != i && !vis[i]) {
        bool x = (a[i] > i), y = (from[i] > i);

        if(x && y) {
            lst[a[i]] = ++ c;
            ans[c][cur] = ans[c][i] = ans[c][a[i]] = 2;
            Lst[from[i]] = ++ c;
            ans[c][cur] = ans[c][from[i]] = 1;
        }
        if(x && !y) { ans[lst[i]][a[i]] = 2; }
        if(!x && y) { ans[Lst[i]][from[i]] = 1; }
    }

    printf("%d\n", n - 1);
    for(int i = l; i <= l + n - 1; ++i) {
        for(int j = 1; j <= n; ++j) {
            printf("%c", ans[i][j] == 0 ? '.' : (ans[i][j] == 1 ? '\\' : '/'));
        }
        puts("");
    }

    return 0;
}


#include <bits/stdc++.h>

using std::pair;
using std::vector;
using std::string;

typedef long long ll;
typedef pair<int, int> pii;

#define fst first
#define snd second
#define pb(a) push_back(a)
#define mp(a, b) std::make_pair(a, b)
#define debug(...) fprintf(stderr, __VA_ARGS__)

template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }

const int oo = 0x3f3f3f3f;

string procStatus() {
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}

template <typename T> T read(T& x) {
    int f = 1; x = 0;
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    return x *= f;
}

const int N = 1000;

int n;
int lst[N + 5];
int Lst[N + 5];
int ans[N + 5][N + 5];
int a[N + 5], from[N + 5];

void chk() {
    for(int i = 1; i <= n; ++i) if(a[i] != i) {
        return;
    }
    printf("%d\n", n);
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= n; ++j) {
            putchar('.');
        }
        puts("");
    }
    exit(0);
}

int main() {
#ifdef Wearry
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    scanf("%d", &n);
    for(int i = 1; i <= n; ++i) scanf("%d", a + i), from[a[i]] = i;

    chk();

    int cur = 0;
    for(int i = 1; i <= n; ++i) if(a[i] != i) {
        cur = i;
        break;
    }

    int c = 0;
    for(int i = cur + 1; i <= n; ++i) if(a[i] != i) {
        if(a[i] == cur) {
            ++ c;
            ans[c][cur] = ans[c][i] = 1;

            if(from[i] > i) {
                ans[c][from[i]] = 1;
            }
        } else {
            bool x = (a[i] > i), y = (from[i] > i);

            if(x && y) {
                lst[a[i]] = ++ c;
                ans[c][cur] = ans[c][i] = ans[c][a[i]] = 2;
                Lst[from[i]] = ++ c;
                ans[c][cur] = ans[c][from[i]] = 1;
            }
            if(x && !y) { ans[lst[i]][a[i]] = 2; }
            if(!x && y) { ans[Lst[i]][from[i]] = 1; }
        }
    }

    printf("%d\n", n - 1);
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= n; ++j) {
            printf("%c", ans[i][j] == 0 ? '.' : (ans[i][j] == 1 ? '\\' : '/'));
        }
        puts("");
    }

    return 0;
}


#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<utility>
#include<functional>
#include<iomanip>
#include<sstream>
#include<ctime>
#include<cassert>
using namespace std;
#define y0 y0z
#define y1 y1z
#define yn ynz
#define j0 j0z
#define j1 j1z
#define jn jnz
#define tm tmz
#define buli(x) (__builtin_popcountll(x))
#define bur0(x) (__builtin_ctzll(x))
#define bul2(x) (63-__builtin_clzll(x))
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define fil(a,b) memset((a),(b),sizeof(a))
#define cl(a) fil(a,0)
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)
#define rep(i,a,b) for (int i=(a),_ed=(b);i<_ed;i++)
#define per(i,a,b) for (int i=(b)-1,_ed=(a);i>=_ed;i--)
#define forg(i,gu) for (int i=gu;~i;i=e[i].next)
#define pw(x) ((ll(1))<<(x))
#define upmo(a,b) (((a)=((a)+(b))%mo)<0?(a)+=mo:(a))
#define mmo(a,b) (((a)=1ll*(a)*(b)%mo)<0?(a)+=mo:(a))
void getre(){int x=0;printf("%d\n",1/x);}
void gettle(){int res=1;while(1)res<<=1;printf("%d\n",res);}
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
template<typename T,typename S>inline bool upmin(T&a,const S&b){return a>b?a=b,1:0;}
template<typename T,typename S>inline bool upmax(T&a,const S&b){return a<b?a=b,1:0;}
template<typename N,typename PN>inline N flo(N a,PN b){return a>=0?a/b:-((-a-1)/b)-1;}
template<typename N,typename PN>inline N cei(N a,PN b){return a>0?(a-1)/b+1:-(-a/b);}
template<typename N>N gcd(N a,N b){return b?gcd(b,a%b):a;}
template<typename N>inline int sgn(N a){return a>0?1:(a<0?-1:0);}
#if ( ( _WIN32 || __WIN32__ ) && __cplusplus < 201103L)
#define lld "%I64d"
#else
#define lld "%lld"
#endif
inline void gn(long long&x){
	int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');
	c=='-'?(sg=-1,x=0):(x=c-'0');
	while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;
}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
inline void gn(double&x){double t;scanf("%lf",&t);x=t;}
inline void gn(long double&x){double t;scanf("%lf",&t);x=t;}
inline void gs(char *s){scanf("%s",s);}
inline void gc(char &c){while((c=getchar())>126 || c<33);}
inline void pc(char c){putchar(c);}
#ifdef JCVB
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
typedef long long ll;
typedef double db;
inline ll sqr(ll a){return a*a;}
inline db sqrf(db a){return a*a;}
const int inf=0x3f3f3f3f;
//const ll inf=0x3f3f3f3f3f3f3f3fll;
const db pi=3.14159265358979323846264338327950288L;
const db eps=1e-6;
//const int mo=0;
//int qp(int a,ll b){int n=1;do{if(b&1)n=1ll*n*a%mo;a=1ll*a*a%mo;}while(b>>=1);return n;}

int n;
int per[1111];
int got[1111];

char bd[1111][1111];
int tot=0;
int vis[1111];

int lis[1111];
int main()
{
	cl(bd);
	gn(n);
	rep(i,1,n+1)gn(per[i]);
	int bo=0;
	rep(i,1,n+1)if(per[i]!=i) {
		bo=1;
		break;
	}
	rep(i,1,n+1)got[per[i]]=i;
	if(bo==0) {
		printf("%d\n",n);
		rep(i,1,n+1) {
			rep(j,1,n+1)printf(".");
			printf("\n");
		}
		return 0;
	}
	int left=0;
	rep(i,1,n+1)if(per[i]!=i) {
		left=i;
		break;
	}

	rep(i,1,n+1)if(per[i]!=i) {
		if(vis[i])continue;

		int but = tot+1;
		int len=0;
		lis[++len]=i;
		vis[i]=1;
		int x=got[i];
		while(x!=i) {
			vis[x]=1;
			lis[++len]=x;
			x=got[x];
		}

		if(lis[1]!=left) {
			for (int j=1;j<len;j++) {
				tot++;
				if(lis[j+1]>lis[j]) {
					bd[tot][lis[j]] = bd[tot][lis[j+1]]='\\';
				} else {
					bd[tot][lis[j]]=bd[tot][lis[j+1]]='/';
				}
			}
			tot++;
			bd[tot][lis[len]]=bd[tot][left]='/';
			bd[but][left]=bd[but][lis[1]] = '\\';
		}else {
			for (int j=2;j<=len;j++) {
				tot++;
				int j1 = j+1;
				if(j==len)j1=1;

				if(lis[j1]>lis[j]) {
					bd[tot][lis[j]] = bd[tot][lis[j1]]='\\';
				} else {
					bd[tot][lis[j]]=bd[tot][lis[j1]]='/';
				}
			}
		}
	}
	printf("%d\n",n-1);
	for (int i=n;i>=1;i--) {
		rep(j,1,n+1){
			if(bd[i][j]==0)bd[i][j]='.';
			putchar(bd[i][j]);
		}
		printf("\n");
	}

	return 0;
}


#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cstdlib>

#include <algorithm>
#include <numeric>
#include <limits>
#include <functional>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <queue>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int N = 1010;

int n, cnt;
bool flag = false;
int a[N];
bool vis[N];
char ans[N][N];

vector<vector<int> > cyc;

void link(int r, int u, int v) {
	ans[r][u] = ans[r][v] = (u < v ? '/' : '\\');
}

int main() {
#ifdef LBT
	freopen("test.in", "r", stdin);
	int nol_cl = clock();
#endif

	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);

	memset(ans, '.', sizeof(ans));
	for (int i = 1; i <= n; ++i) {
		if (a[i] == i || vis[i])
			continue;
		vector<int> cur;
		int x = i;
		while (!vis[x]) {
			vis[x] = true;
			cur.push_back(x);
			x = a[x];
		}
		reverse(cur.begin(), cur.end());
		for (int i = 0; i < cur.size(); ++i) {
			vector<int>::iterator it = max_element(cur.begin(), cur.end());
			reverse(cur.begin(), it);
			reverse(it, cur.end());
		}
		cyc.push_back(cur);
	}
	if (cyc.empty())
		printf("%d\n", n);
	else {
		printf("%d\n", n - 1);
		int pos = -1, chose = 0;
		for (int j = 0; j < cyc.size(); ++j) {
			if (pos < cyc[j].back()) {
				pos = cyc[j].back();
				chose = j;
			}
		}
		cnt = n;
		for (int i = cyc[chose].size() - 2; i; --i)
			link(cnt--, cyc[chose][i - 1], cyc[chose][i]);
		link(cnt--, pos, cyc[chose].front());
		for (int j = 0; j < cyc.size(); ++j)
			if (j != chose) {
				ans[cnt][pos] = '/';
				for (int i = cyc[j].size() - 1; i; --i)
					link(cnt--, cyc[j][i - 1], cyc[j][i]);
				link(cnt--, pos, cyc[j].front());
			}
	}
	for (int i = 1; i <= n; ++i) {
		ans[i][n + 1] = 0;
		puts(ans[i] + 1);
	}

#ifdef LBT
	LOG("Time: %dms\n", int((clock() - nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
	return 0;
}


#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cstdlib>

#include <algorithm>
#include <numeric>
#include <limits>
#include <functional>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <queue>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int N = 1010;

int n, cnt;
bool flag = false;
int a[N];
bool vis[N];
char ans[N][N];

int main() {
#ifdef LBT
	freopen("test.in", "r", stdin);
	int nol_cl = clock();
#endif

	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);

	memset(ans, '.', sizeof(ans));
	for (int i = 1; i <= n; ++i) {
		if (a[i] == i || vis[i])
			continue;
		int x = i;
		while (!vis[a[x]]) {
			vis[x] = true;
			++cnt;
			if (x < a[x]) {
				ans[cnt][x] = '/';
				ans[cnt][a[x]] = '/';
			} else {
				ans[cnt][x] = '\\';
				ans[cnt][a[x]] = '\\';
			}
			x = a[x];
		}
		vis[a[x]] = true;
		flag = true;
	}
	if (!flag)
		printf("%d\n", n);
	else {
		printf("%d\n", n - 1);
	}
	for (int i = 1; i <= n; ++i) {
		ans[i][n + 1] = 0;
		puts(ans[i] + 1);
	}

#ifdef LBT
	LOG("Time: %dms\n", int((clock() - nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
	return 0;
}


#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cstdlib>

#include <algorithm>
#include <numeric>
#include <limits>
#include <functional>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <queue>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int N = 1010;

int n, cnt;
bool flag = false;
int a[N];
bool vis[N];
char ans[N][N];

vector<vector<int> > cyc;

void link(int r, int u, int v) {
	ans[r][u] = ans[r][v] = (u < v ? '/' : '\\');
}

int main() {
#ifdef LBT
	freopen("test.in", "r", stdin);
	int nol_cl = clock();
#endif

	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);

	memset(ans, '.', sizeof(ans));
	for (int i = 1; i <= n; ++i) {
		if (a[i] == i || vis[i])
			continue;
		vector<int> cur;
		int x = i;
		while (!vis[x]) {
			vis[x] = true;
			cur.push_back(x);
			x = a[x];
		}
		reverse(cur.begin(), cur.end());
		vector<int>::iterator it = max_element(cur.begin(), cur.end());
		reverse(cur.begin(), it);
		reverse(it, cur.end());
		cyc.push_back(cur);
	}
	if (cyc.empty())
		printf("%d\n", n);
	else {
		printf("%d\n", n - 1);
		int pos = -1, chose = 0;
		for (int j = 0; j < cyc.size(); ++j) {
			if (pos < cyc[j].back()) {
				pos = cyc[j].back();
				chose = j;
			}
		}
		cnt = n;
		for (int i = cyc[chose].size() - 2; i; --i)
			link(cnt--, cyc[chose][i - 1], cyc[chose][i]);
		link(cnt--, pos, cyc[chose].front());
		for (int j = 0; j < cyc.size(); ++j)
			if (j != chose) {
				ans[cnt][pos] = '/';
				for (int i = cyc[j].size() - 1; i; --i)
					link(cnt--, cyc[j][i - 1], cyc[j][i]);
				link(cnt--, pos, cyc[j].front());
			}
	}
	for (int i = 1; i <= n; ++i) {
		ans[i][n + 1] = 0;
		puts(ans[i] + 1);
	}

#ifdef LBT
	LOG("Time: %dms\n", int((clock() - nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
	return 0;
}


/*
ЗАПУСКАЕМ
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░
 */
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>

using namespace std;
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const pair<T, U> &_p) { _out << _p.first << ' ' << _p.second; return _out; }
template<typename T, typename U> inline istream &operator>> (istream &_in, pair<T, U> &_p) { _in >> _p.first >> _p.second; return _in; }
template<typename T> inline ostream &operator<< (ostream &_out, const vector<T> &_v) { if (_v.empty()) { return _out; } _out << _v.front(); for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline istream &operator>> (istream &_in, vector<T> &_v) { for (auto &_i : _v) { _in >> _i; } return _in; }
template<typename T> inline ostream &operator<< (ostream &_out, const set<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const multiset<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const unordered_set<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const unordered_multiset<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const map<T, U> &_m) { if (_m.empty()) { return _out; } _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { _out << ", (" << _it->first << ": " << _it->second << ')'; } return _out; }
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const unordered_map<T, U> &_m) { if (_m.empty()) { return _out; } _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { _out << ", (" << _it->first << ": " << _it->second << ')'; } return _out; }
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define left left228
#define right right228
#define next next228
#define rank rank228
#define prev prev228
#define y1 y1228
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define files(FILENAME) read(FILENAME), write(FILENAME)
#define pb push_back
const string FILENAME = "input";
const int MAXN = 1005;

int n;
int a[MAXN];
bool used[MAXN];
int st = -1;
int uk;
vector<int> cs[MAXN];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //read(FILENAME);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
    }
    bool ok = true;
    for (int i = 0; i < n; i++) {
        if (a[i] != i) {
            ok = false;
        }
    }
    if (ok) {
        cout << n << endl;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                cout << '.';
            }
            cout << '\n';
        }
        return 0;
    }
    for (int i = 0; i < n; i++) {
        if (i == a[i]) {
            continue;
        }
        if (used[i]) {
            continue;
        }
        if (st == -1) {
            st = i;
        }
        for (int j = i; !used[j]; cs[uk].pb(j), used[j] = true, j = a[j]);
        if (!uk) {
            cs[0].erase(cs[0].begin());
            cs[0].pb(i);
        }
        uk++;
    }
    //cout << sz(cs[0]) << endl;
    cout << n - 1 << '\n';
    int cnt = 0;
    for (int k = 0; k < uk; k++) {
      //  cout << k << endl;
        for (int i = 0; i < sz(cs[k]) - 1; i++) {
        //    cout << k << ' ' << i << endl;
            char e = (cs[k][i + 1] < cs[k][i] ? '\\': '/');
            for (int j = 0; j < n; j++) {
                cout << (j == cs[k][i + 1] || j == cs[k][i] || !i && k && j == st ? e: '.');
            }
            cout << '\n';
            cnt++;
        }
        for (int j = 0; j < n; j++) {
            cout << (j == st || j == cs[k].back() ? '\\': '.');
        }
        cout << '\n';
        cnt++;
    }
    for (int i = cnt; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cout << '.';
        }
        cout << '\n';
    }
    return 0;
}


/*
ЗАПУСКАЕМ
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░
 */
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>

using namespace std;
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const pair<T, U> &_p) { _out << _p.first << ' ' << _p.second; return _out; }
template<typename T, typename U> inline istream &operator>> (istream &_in, pair<T, U> &_p) { _in >> _p.first >> _p.second; return _in; }
template<typename T> inline ostream &operator<< (ostream &_out, const vector<T> &_v) { if (_v.empty()) { return _out; } _out << _v.front(); for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline istream &operator>> (istream &_in, vector<T> &_v) { for (auto &_i : _v) { _in >> _i; } return _in; }
template<typename T> inline ostream &operator<< (ostream &_out, const set<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const multiset<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const unordered_set<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const unordered_multiset<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const map<T, U> &_m) { if (_m.empty()) { return _out; } _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { _out << ", (" << _it->first << ": " << _it->second << ')'; } return _out; }
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const unordered_map<T, U> &_m) { if (_m.empty()) { return _out; } _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { _out << ", (" << _it->first << ": " << _it->second << ')'; } return _out; }
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define left left228
#define right right228
#define next next228
#define rank rank228
#define prev prev228
#define y1 y1228
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define files(FILENAME) read(FILENAME), write(FILENAME)
#define pb push_back
const string FILENAME = "input";
const int MAXN = 1005;

int n;
int a[MAXN];
bool used[MAXN];
int st = -1;
int uk;
vector<int> cs[MAXN];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //read(FILENAME);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
    }
    bool ok = true;
    for (int i = 0; i < n; i++) {
        if (a[i] != i) {
            ok = false;
        }
    }
    if (ok) {
        cout << n << endl;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                cout << '.';
            }
            cout << '\n';
        }
        return 0;
    }
    for (int i = 0; i < n; i++) {
        if (i == a[i]) {
            continue;
        }
        if (used[i]) {
            continue;
        }
        if (st == -1) {
            st = i;
        }
        for (int j = i; !used[j]; cs[uk].pb(j), used[j] = true, j = a[j]);
        if (!uk) {
            cs[0].erase(cs[0].begin());
            cs[0].pb(i);
        }
        uk++;
    }
    //cout << sz(cs[0]) << endl;
    cout << n - 1 << '\n';
    int cnt = 0;
    for (int k = 0; k < uk; k++) {
      //  cout << k << endl;
        for (int i = 0; i < sz(cs[k]) - 1; i++) {
        //    cout << k << ' ' << i << endl;
            char e = (cs[k][i + 1] < cs[k][i] ? '\\': '/');
            for (int j = 0; j < n; j++) {
                cout << (j == cs[k][i + 1] || cs[k][i] || !i && k && j == st ? e: '.');
            }
            cout << '\n';
            cnt++;
        }
        for (int j = 0; j < n; j++) {
            cout << (j == st || j == cs[k].back() ? '\\': '.');
        }
        cout << '\n';
        cnt++;
    }
    for (int i = cnt; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cout << '.';
        }
        cout << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ll long long
#define pii pair<int,int>
#define mp make_pair
#define xx first
#define yy second
#define pb push_back

const int N = 1005;
int obj[N],state[N];
char grid[N][N];

int main() {
    IOS;
	int n; cin >> n;
	for (int i=1;i<=n;i++) {
		cin >> obj[i];
		fill(grid[i]+1,grid[i]+n+1,'.');
	}
	bool lefry = false;
	for (int i=1;i<=n;i++) if (obj[i]!=i)
	{ lefry = true; break; }
	if (!!!!!lefry) {
		cout << n << '\n';
	} else {
	int vide = n;
	cout << n-1 << '\n';
	for (int i=1;i<n;i++) state[i] = i;
	int row = n;
	while (row>0) {
		if (lefry) { // going ry
			int x; // column
			for (x=1;x<vide;x++)
				if (x!=obj[state[x]]) break;
			if (x==vide) break;
			grid[row][x] = '/';
			grid[row][obj[state[x]]] = '/';
			grid[row][vide] = '/';
			state[vide] = state[obj[state[x]]];
			state[obj[state[x]]]  =  state[x];
			state[x] = 0;
			vide = x;
			row--; lefry = false;
		} else { // going lef
			int x; // column
			for (x=n;x>vide;x--)
				if (x!=obj[state[x]]) break;
			if (x==vide) break;
			grid[row][x] = '\\';
			grid[row][obj[state[x]]] = '\\';
			grid[row][vide] = '\\';
			state[vide] = state[obj[state[x]]];
			state[obj[state[x]]]  =  state[x];
			state[x] = 0;
			vide = x;
			row--; lefry = true;
		}
	} }
	for (int i=1;i<=n;i++) {
		for (int j=1;j<=n;j++) cout << grid[i][j];
		cout << '\n';
	}
}


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

const int mxN=1e3;
int n, a[mxN], a1;
bool vis[mxN];
vector<array<int, 2>> tp;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> n;
	for(int i=0; i<n; ++i)
		cin >> a[i], --a[i];
	for(int i=0; i<n; ++i) {
		if(vis[i]||a[i]==i)
			continue;
		vis[i]=1;
		for(int j=i; !vis[a[j]]; tp.push_back({j, a[j]}), vis[a[j]]=1, j=a[j]);
		++a1;
	}
	while(tp.size()<n)
		tp.push_back({-1, -1});
	cout << n-a1 << "\n";
	for(int i=0; i<n; ++i) {
		char e=tp[i][0]<tp[i][1]?'/':'\\';
		for(int j=0; j<n; ++j)
			cout << (j==tp[i][0]||j==tp[i][1]?e:'.');
		cout << "\n";
	}
}


#include <algorithm>
#include <iostream>
#include <vector>

#include <cmath>
#include <cstring>

using namespace std;

const int N = 1010;
int n, a[N + 1], pos[N + 1];
bool v[N + 1];
char map[N + 1][N + 1];

int main(int argc, char *argv[]) {
#ifdef KANARI
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 1; i <= n; ++i)
	    cin >> a[i];
	for (int i = 1; i <= n; ++i)
	    fill(map[i] + 1, map[i] + n + 1, '.');

	// make a its inverse
	for (int i = 1; i <= n; ++i)
	    pos[a[i]] = i;
	memcpy(a, pos, sizeof pos);

	int ans = 0;
	for (int i = 1; i <= n; ++i) {
	    if (v[i]) continue;
	    vector<int> loop;
	    v[i] = true, loop.push_back(i);
	    for (int x = a[i]; x != i; x = a[x])
	        v[x] = true, loop.push_back(x);
	    ans += max(1, static_cast<int>(loop.size()) - 1);
	    for (int j = static_cast<int>(loop.size() - 2); j >= 0; --j) {
	        int r = ans - j;
	        int x = loop[j], y = loop[j + 1];
	        map[r][x] = map[r][y] = (x < y) ? '\\' : '/';
	    }
	}

	printf("%d\n", ans);
	for (int i = 1; i <= n; ++i)
	    printf("%s\n", map[i] + 1);

	fclose(stdin);
	fclose(stdout);
	return 0;
}


#include <algorithm>
#include <iostream>
#include <vector>

#include <cmath>

using namespace std;

const int N = 1010;
int n, a[N + 1];
bool v[N + 1];
char map[N + 1][N + 1];

int main(int argc, char *argv[]) {
#ifdef KANARI
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 1; i <= n; ++i)
	    cin >> a[i];
	for (int i = 1; i <= n; ++i)
	    fill(map[i] + 1, map[i] + n + 1, '.');

	int ans = 0;
	for (int i = 1; i <= n; ++i) {
	    if (v[i]) continue;
	    vector<int> loop;
	    v[i] = true, loop.push_back(i);
	    for (int x = a[i]; x != i; x = a[x])
	        v[x] = true, loop.push_back(x);
	    ans += max(1, static_cast<int>(loop.size()) - 1);
	    for (int j = static_cast<int>(loop.size() - 2); j >= 0; --j) {
	        int r = ans - j;
	        int x = loop[j], y = loop[j + 1];
	        map[r][x] = map[r][y] = (x < y) ? '\\' : '/';
	    }
	}

	printf("%d\n", ans);
	for (int i = 1; i <= n; ++i)
	    printf("%s\n", map[i] + 1);

	fclose(stdin);
	fclose(stdout);
	return 0;
}


#include <algorithm>
#include <iostream>
#include <vector>

#include <cmath>
#include <cstring>

using namespace std;

const int N = 1010;
int n, a[N + 1], pos[N + 1];
bool v[N + 1];
char map[N + 1][N + 1];

int main(int argc, char *argv[]) {
#ifdef KANARI
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 1; i <= n; ++i)
	    cin >> a[i];
	for (int i = 1; i <= n; ++i)
	    fill(map[i] + 1, map[i] + n + 1, '.');

	// make a its inverse
	for (int i = 1; i <= n; ++i)
	    pos[a[i]] = i;
	memcpy(a, pos, sizeof pos);

	// find last non identity loop
	int turn_idx = -1, ans = 0;
	for (int i = n; i > 0; --i)
	    if (a[i] != i) {
	        turn_idx = i;
	        break;
	    }
    if (turn_idx == -1) {
        ans = n;
    } else {
        ans = n - 1;
        int cnt = 0;
        for (int i = n; i > 0; --i) {
            if (v[i]) continue;
            vector<int> loop;
            for (int x = a[i]; x != i; x = a[x])
                v[x] = true, loop.push_back(x);
            v[i] = true, loop.push_back(i);
            if (i == turn_idx) cnt = n;
            else cnt += loop.size() - 1;
            for (int j = static_cast<int>(loop.size() - 2); j >= 0; --j) {
                int r = cnt - j;
                int x = loop[j], y = loop[j + 1];
                map[r][x] = map[r][y] = (x < y) ? '\\' : '/';
            }
            if (i == turn_idx) cnt = 0;
            else {
                map[cnt - loop.size()][turn_idx] = '\\';
                ++cnt;
                map[cnt][turn_idx] = map[cnt][a[i]] = '/';
            }
        }
    }

	printf("%d\n", ans);
	for (int i = 1; i <= n; ++i)
	    printf("%s\n", map[i] + 1);

	fclose(stdin);
	fclose(stdout);
	return 0;
}


#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

const int N = 1010;
int n, a[N + 1], pos[N + 1];
bool v[N + 1];
char map[N + 1][N + 1];

int main(int argc, char *argv[]) {
#ifdef KANARI
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    ios::sync_with_stdio(false);
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    for (int i = 1; i <= n; ++i)
        fill(map[i] + 1, map[i] + n + 1, '.');

    // make a its inverse
    for (int i = 1; i <= n; ++i)
        pos[a[i]] = i;
    memcpy(a, pos, sizeof pos);

    // find last non identity loop
    int turn_idx = -1, ans = 0;
    for (int i = n; i > 0; --i)
        if (a[i] != i) {
            turn_idx = i;
            break;
        }
    if (turn_idx == -1) {
        ans = n;
    } else {
        ans = n - 1;
        int cnt = 0;
        for (int i = n; i > 0; --i) {
            if (v[i]) continue;
            vector<int> loop;
            for (int x = a[i]; x != i; x = a[x])
                v[x] = true, loop.push_back(x);
            v[i] = true, loop.push_back(i);
            if (loop.size() == 1) continue;
            if (i == turn_idx) cnt = n;
            else cnt += loop.size() - 1;
            for (int j = static_cast<int>(loop.size() - 2); j >= 0; --j) {
                int r = cnt - j;
                int x = loop[j], y = loop[j + 1];
                map[r][x] = map[r][y] = (x < y) ? '\\' : '/';
            }
            if (i == turn_idx) cnt = 0;
            else {
                map[cnt - loop.size()][turn_idx] = '\\';
                ++cnt;
                map[cnt][turn_idx] = map[cnt][a[i]] = '/';
            }
        }
    }

    printf("%d\n", ans);
    for (int i = 1; i <= n; ++i)
        printf("%s\n", map[i] + 1);

    fclose(stdin);
    fclose(stdout);
    return 0;
}


#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

const int N = 1010;
int n, a[N + 1], pos[N + 1];
bool v[N + 1];
char map[N + 1][N + 1];

int main(int argc, char *argv[]) {
#ifdef KANARI
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    ios::sync_with_stdio(false);
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    for (int i = 1; i <= n; ++i)
        fill(map[i] + 1, map[i] + n + 1, '.');

    // make a its inverse
    for (int i = 1; i <= n; ++i)
        pos[a[i]] = i;
    memcpy(a, pos, sizeof pos);

    // find last non identity loop
    int turn_idx = -1, ans = 0;
    for (int i = n; i > 0; --i)
        if (a[i] != i) {
            turn_idx = i;
            break;
        }
    if (turn_idx == -1) {
        ans = n;
    } else {
        ans = n - 1;
        int cnt = 0;
        for (int i = n; i > 0; --i) {
            if (v[i]) continue;
            vector<int> loop;
            for (int x = a[i]; x != i; x = a[x])
                v[x] = true, loop.push_back(x);
            v[i] = true, loop.push_back(i);
            if (loop.size() == 1) continue;
            if (i == turn_idx) cnt = n;
            else cnt += loop.size() - 1;
            for (int j = static_cast<int>(loop.size() - 2); j >= 0; --j) {
                int r = cnt - j;
                int x = loop[j], y = loop[j + 1];
                map[r][x] = map[r][y] = (x < y) ? '\\' : '/';
            }
            if (i == turn_idx) cnt = 0;
            else {
                map[cnt - (loop.size() - 2)][turn_idx] = '\\';
                ++cnt;
                map[cnt][turn_idx] = map[cnt][a[i]] = '/';
            }
        }
    }

    printf("%d\n", ans);
    for (int i = 1; i <= n; ++i)
        printf("%s\n", map[i] + 1);

    fclose(stdin);
    fclose(stdout);
    return 0;
}


#include <algorithm>
#include <iostream>
#include <vector>

#include <cmath>
#include <cstring>

using namespace std;

const int N = 1010;
int n, a[N + 1], pos[N + 1];
bool v[N + 1];
char map[N + 1][N + 1];

int main(int argc, char *argv[]) {
#ifdef KANARI
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 1; i <= n; ++i)
	    cin >> a[i];
	for (int i = 1; i <= n; ++i)
	    fill(map[i] + 1, map[i] + n + 1, '.');

	// make a its inverse
	for (int i = 1; i <= n; ++i)
	    pos[a[i]] = i;
	memcpy(a, pos, sizeof pos);

	// find last non identity loop
	int turn_idx = -1, ans = 0;
	for (int i = n; i > 0; --i)
	    if (a[i] != i) {
	        turn_idx = i;
	        break;
	    }
    if (turn_idx == -1) {
        ans = n;
    } else {
        ans = n - 1;
        int cnt = 0;
        for (int i = n; i > 0; --i) {
            if (v[i]) continue;
            vector<int> loop;
            for (int x = a[i]; x != i; x = a[x])
                v[x] = true, loop.push_back(x);
            v[i] = true, loop.push_back(i);
            if (loop.size() == 1) continue;
            if (i == turn_idx) cnt = n;
            else cnt += loop.size();
            for (int j = static_cast<int>(loop.size() - 2); j >= 0; --j) {
                int r = cnt - j;
                int x = loop[j], y = loop[j + 1];
                map[r][x] = map[r][y] = (x < y) ? '\\' : '/';
            }
            if (i == turn_idx) cnt = 0;
            else {
                map[cnt - loop.size() + 2][turn_idx] = '\\';
                ++cnt;
                map[cnt][turn_idx] = map[cnt][a[i]] = '/';
            }
        }
    }

	printf("%d\n", ans);
	for (int i = 1; i <= n; ++i)
	    printf("%s\n", map[i] + 1);

	fclose(stdin);
	fclose(stdout);
	return 0;
}


/*
 * Bad Move
 */
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma comment(linker, "/STACK:1024000000,1024000000")

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

#define S second
#define F first
#define pb push_back

using ii = pair<int, int>;
using ll = long long;
using db = long double;
using PT = pair<ll, ll>;

const int N = 1e5 + 5, K = 305, MOD = 1e9 + 7;
const ll MX = 1e15;
int n;
int p[1005];
char grid[1005][1005];
bool vis[1005];
bool isIdentity() {
	for (int i = 0; i < n; i++)
		if (p[i] != i)
			return false;
	return true;
}
int to[N];
void readInput() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> p[i];
		--p[i];
	}
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			grid[i][j] = '.';
}

void solveGrid() {
	bool f = false;
	int cnt = 0;
	for (int i = n - 1; ~i; --i) {
		if (vis[i])
			continue;
		if (p[i] == i) {
			vis[i] = true;
			continue;
		}
		int fail;
		int cur = i;
		if (!f)
			cur = p[cur];
		int b4 = cnt;
		while (!vis[p[cur]]) {
			if (cur < p[cur]) {
				grid[cnt][cur] = '/';
				grid[cnt][p[cur]] = '/';
				cnt++;
			} else if (cur > p[cur]) {
				grid[cnt][cur] = '\\';
				grid[cnt][p[cur]] = '\\';
				cnt++;
			}
			vis[cur] = true;
			cur = p[cur];
		}
		if (!f) {
			f = true;
			vis[cur] = true;
			fail = f;
		} else {
			grid[cnt][cur] = '/';
			grid[cnt][fail] = '/';
			grid[b4][fail] = '\\';
			cnt++;
			vis[cur] = true;
		}
	}
}
void printGrid(int ans) {
	cout << ans << '\n';
	for (int i = 0; i < n; i++, cout << '\n')
		for (int j = 0; j < n; j++)
			cout << grid[i][j];
}

int main() {
#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#endif
	readInput();
	if (isIdentity()) {
		printGrid(n);
	} else {
		solveGrid();
		printGrid(n - 1);
	}

	return 0;
}


/*
 * Bad Move
 */
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma comment(linker, "/STACK:1024000000,1024000000")

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

#define S second
#define F first
#define pb push_back

using ii = pair<int, int>;
using ll = long long;
using db = long double;
using PT = pair<ll, ll>;

const int N = 1e5 + 5, K = 305, MOD = 1e9 + 7;
const ll MX = 1e15;
int n;
int p[1005];
char grid[1005][1005];
bool vis[1005];
bool isIdentity() {
	for (int i = 0; i < n; i++)
		if (p[i] != i)
			return false;
	return true;
}
int to[N];
void readInput() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> p[i];
		--p[i];
	}
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			grid[i][j] = '.';
}

void solveGrid() {
	int fail = -1;
	int cnt = 0;
	for (int i = n - 1; ~i; --i) {
		if (vis[i])
			continue;
		if (p[i] == i) {
			vis[i] = true;
			continue;
		}
		int cur = i;
		if (fail == -1)
			cur = p[cur];
		int b4 = cnt;
		while (!vis[p[cur]]) {
			if (cur < p[cur]) {
				grid[cnt][cur] = '/';
				grid[cnt][p[cur]] = '/';
				cnt++;
			} else if (cur > p[cur]) {
				grid[cnt][cur] = '\\';
				grid[cnt][p[cur]] = '\\';
				cnt++;
			}
			vis[cur] = true;
			cur = p[cur];
		}
		if (~fail) {
			grid[cnt][cur] = '/';
			grid[cnt][fail] = '/';
			grid[b4][fail] = '\\';
			cnt++;
		} else {
			fail = cur;
		}
		vis[cur] = true;
	}
}
void printGrid(int ans) {
	cout << ans << '\n';
	for (int i = 0; i < n; i++, cout << '\n')
		for (int j = 0; j < n; j++)
			cout << grid[i][j];
}

int main() {
#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#endif
	readInput();
	if (isIdentity()) {
		printGrid(n);
	} else {
		solveGrid();
		printGrid(n - 1);
	}

	return 0;
}


#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include<bits/stdc++.h>
using namespace std;

int n, p[1010], fl, s[1010][1010];
char S[]="./\\";

void out(int x){
  cout<<x<<endl;
  for (int i=1;i<=n;++i,puts(""))
    for (int j=1;j<=n;++j)
      putchar(S[s[i][j]]);
  exit(0);
}

int main(){
  cin>>n;
  for (int i=1;i<=n;++i){
    cin>>p[i];
    if (p[i]!=i) fl=i;
  }
  if (!fl) out(n);
  for (int c=n,ty=1; c>=1; --c,ty^=3){
    int ti=0;
    if (ty==1){
      for (int i=1;i<fl&&!ti;++i)
        if (p[i]>i) ti=i;
    }
    else{
      for (int i=n;i>fl&&!ti;--i)
        if (p[i]<i) ti=i;
    }
    if (!ti) break;
    s[c][ti]=s[c][p[ti]]=s[c][fl]=ty;
    p[fl]=p[p[ti]]; p[p[ti]]=p[ti]; fl=ti;
  }
  out(n-1);
}


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

random_device(rd);
mt19937 rng(rd());
const long long FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();

struct custom_hash
{
	template<class T>
	unsigned long long operator()(T v) const
	{
		unsigned long long x = v;
		x += FIXED_RANDOM; x += 11400714819323198485ull;
		x = (x ^ (x >> 30)) * 13787848793156543929ull;
		x = (x ^ (x >> 27)) * 10723151780598845931ull;
		return x ^ (x >> 31);
	}
};

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T, class U> using hash_table = gp_hash_table<T, U, custom_hash>;

template<class T>
void readi(T &x)
{
	x = 0;
	bool negative = false;
	char c = ' ';
	while (c < '-')
	{
		c = getchar();
	}
	if (c == '-')
	{
		negative = true;
		c = getchar();
	}
	while (c >= '0')
	{
		x = x * 10 + (c - '0');
		c = getchar();
	}
	if (negative)
	{
		x = -x;
	}
}
template<class T>
void printi(T output)
{
	if (output == 0)
	{
		putchar('0');
		return;
	}
	if (output < 0)
	{
		putchar('-');
		output = -output;
	}
	int buf[20], n = 0;
	while(output)
	{
		buf[n] = ((output % 10));
		output /= 10;
		n++;
	}
	for (n--; n >= 0; n--)
	{
		putchar(buf[n] + '0');
	}
	return;
}
template<class T>
void ckmin(T &a, T b)
{
	a = min(a, b);
}
template<class T>
void ckmax(T &a, T b)
{
	a = max(a, b);
}
long long expo(long long a, long long e, long long mod)
{
	return ((e == 0) ? 1 : ((expo(a * a % mod, e >> 1, mod)) * ((e & 1) ? a : 1) % mod));
}
template<class T, class U>
void nmod(T &x, U mod)
{
	if (x >= mod) x -= mod;
}
template<class T>
T gcd(T a, T b)
{
	return (b ? gcd(b, a % b) : a);
}
template<class T>
T randomize(T mod)
{
	return (uniform_int_distribution<T>(0, mod - 1))(rng);
}

#define y0 ___y0
#define y1 ___y1
#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define DBG(x) cerr << #x << " = " << x << endl
#define SZ(x) ((int) (x.size()))
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
#define ALL(x) x.begin(), x.end()

const long double PI = 4.0 * atan(1.0);
const long double EPS = 1e-9;

#define MAGIC 347
#define SINF 10007
#define CO 1000007
#define INF 1000000007
#define BIG 1000000931
#define LARGE 1696969696967ll
#define GIANT 2564008813937411ll
#define LLINF 2696969696969696969ll
#define MAXN 1013

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<pdd> vpd;

int N;
int arr[MAXN];
vector<string> ans;

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	// cout << fixed << setprecision(10);
	// cerr << fixed << setprecision(10);
	// if (fopen("file.in", "r"))
	// {
	// 	freopen ("file.in", "r", stdin);
	// 	freopen ("file.out", "w", stdout);
	// }
	cin >> N;
	bool isid = true;
	FOR(i, 0, N)
	{
		cin >> arr[i]; arr[i]--;
	}
	//you want the first guy where they're not equal
	int lt = 0, rt = N - 1; bool flag = true;
	while(lt < N && arr[lt] == lt) lt++;
	while(rt >= 0 && arr[rt] == rt) rt--;
	//basically like: you can choose a set of #s, and CYCLIC SHIFT them
	if (lt == N)
	{
		cout << N << '\n';
		FOR(i, 0, N)
		{
			FOR(j, 0, N)
			{
				cout << '.';
			}
			cout << '\n';
		}
		return 0;
	}
	while(lt < rt)
	{
		string row; FOR(i, 0, N) row += '.';
		vi nums;
		if (flag)
		{
			int u = lt;
			while(arr[u] > u)
			{
				nums.PB(u);
				u = arr[u];
			}
			nums.PB(u);
			arr[rt] = arr[nums.back()];
			for (int x : nums)
			{
				row[x] = '\\';
				arr[x] = x;
			}
			row[rt] = '\\';
			flag = false;
			while(rt >= 0 && arr[rt] == rt) rt--;
		}
		else
		{
			int u = rt;
			while(arr[u] < u)
			{
				nums.PB(u);
				u = arr[u];
			}
			nums.PB(u);
			arr[lt] = arr[nums.back()];
			for (int x : nums)
			{
				row[x] = '/';
				arr[x] = x;
			}
			row[lt] = '/';
			flag = true;
			while(lt < N && arr[lt] == lt) lt++;
		}
		ans.PB(row);
	}
	cout << N - 1 << '\n';
	for (string s : ans)
	{
		cout << s << '\n';
	}
	FOR(i, 0, N - SZ(ans))
	{
		FOR(j, 0, N)
		{
			cout << '.';
		}
		cout << '\n';
	}
	//anyway, you have like this pivot column
	// cerr << "time elapsed = " << (clock() / (CLOCKS_PER_SEC / 1000)) << " ms" << endl;
	return 0;
}
/* READ READ READ
* int overflow, maxn too small, special cases (n=1?, two distinct?), cin.tie() interactive
* reread the problem, try small cases
* do smth instead of nothing
*/


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

random_device(rd);
mt19937 rng(rd());
const long long FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();

struct custom_hash
{
	template<class T>
	unsigned long long operator()(T v) const
	{
		unsigned long long x = v;
		x += FIXED_RANDOM; x += 11400714819323198485ull;
		x = (x ^ (x >> 30)) * 13787848793156543929ull;
		x = (x ^ (x >> 27)) * 10723151780598845931ull;
		return x ^ (x >> 31);
	}
};

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T, class U> using hash_table = gp_hash_table<T, U, custom_hash>;

template<class T>
void readi(T &x)
{
	x = 0;
	bool negative = false;
	char c = ' ';
	while (c < '-')
	{
		c = getchar();
	}
	if (c == '-')
	{
		negative = true;
		c = getchar();
	}
	while (c >= '0')
	{
		x = x * 10 + (c - '0');
		c = getchar();
	}
	if (negative)
	{
		x = -x;
	}
}
template<class T>
void printi(T output)
{
	if (output == 0)
	{
		putchar('0');
		return;
	}
	if (output < 0)
	{
		putchar('-');
		output = -output;
	}
	int buf[20], n = 0;
	while(output)
	{
		buf[n] = ((output % 10));
		output /= 10;
		n++;
	}
	for (n--; n >= 0; n--)
	{
		putchar(buf[n] + '0');
	}
	return;
}
template<class T>
void ckmin(T &a, T b)
{
	a = min(a, b);
}
template<class T>
void ckmax(T &a, T b)
{
	a = max(a, b);
}
long long expo(long long a, long long e, long long mod)
{
	return ((e == 0) ? 1 : ((expo(a * a % mod, e >> 1, mod)) * ((e & 1) ? a : 1) % mod));
}
template<class T, class U>
void nmod(T &x, U mod)
{
	if (x >= mod) x -= mod;
}
template<class T>
T gcd(T a, T b)
{
	return (b ? gcd(b, a % b) : a);
}
template<class T>
T randomize(T mod)
{
	return (uniform_int_distribution<T>(0, mod - 1))(rng);
}

#define y0 ___y0
#define y1 ___y1
#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define DBG(x) cerr << #x << " = " << x << endl
#define SZ(x) ((int) (x.size()))
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
#define ALL(x) x.begin(), x.end()

const long double PI = 4.0 * atan(1.0);
const long double EPS = 1e-9;

#define MAGIC 347
#define SINF 10007
#define CO 1000007
#define INF 1000000007
#define BIG 1000000931
#define LARGE 1696969696967ll
#define GIANT 2564008813937411ll
#define LLINF 2696969696969696969ll
#define MAXN 1013

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<pdd> vpd;

int N;
int arr[MAXN];
vector<string> ans;

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	// cout << fixed << setprecision(10);
	// cerr << fixed << setprecision(10);
	// if (fopen("file.in", "r"))
	// {
	// 	freopen ("file.in", "r", stdin);
	// 	freopen ("file.out", "w", stdout);
	// }
	cin >> N;
	bool isid = true;
	FOR(i, 0, N)
	{
		int x; cin >> x; x--;
		arr[x] = i;
	}
	//you want the first guy where they're not equal
	int lt = 0, rt = N - 1; bool flag = true;
	while(lt < N && arr[lt] == lt) lt++;
	while(rt >= 0 && arr[rt] == rt) rt--;
	//basically like: you can choose a set of #s, and CYCLIC SHIFT them
	if (lt == N)
	{
		cout << N << '\n';
		FOR(i, 0, N)
		{
			FOR(j, 0, N)
			{
				cout << '.';
			}
			cout << '\n';
		}
		return 0;
	}
	while(lt < rt)
	{
		string row; FOR(i, 0, N) row += '.';
		vi nums;
		if (flag)
		{
			int u = lt;
			while(arr[u] > u)
			{
				nums.PB(u);
				u = arr[u];
			}
			nums.PB(u);
			arr[rt] = arr[nums.back()];
			for (int x : nums)
			{
				row[x] = '\\';
				arr[x] = x;
			}
			row[rt] = '\\';
			flag = false;
			while(rt >= 0 && arr[rt] == rt) rt--;
		}
		else
		{
			int u = rt;
			while(arr[u] < u)
			{
				nums.PB(u);
				u = arr[u];
			}
			nums.PB(u);
			arr[lt] = arr[nums.back()];
			for (int x : nums)
			{
				row[x] = '/';
				arr[x] = x;
			}
			row[lt] = '/';
			flag = true;
			while(lt < N && arr[lt] == lt) lt++;
		}
		ans.PB(row);
	}
	cout << N - 1 << '\n';
	for (string s : ans)
	{
		cout << s << '\n';
	}
	FOR(i, 0, N - SZ(ans))
	{
		FOR(j, 0, N)
		{
			cout << '.';
		}
		cout << '\n';
	}
	//anyway, you have like this pivot column
	// cerr << "time elapsed = " << (clock() / (CLOCKS_PER_SEC / 1000)) << " ms" << endl;
	return 0;
}
/* READ READ READ
* int overflow, maxn too small, special cases (n=1?, two distinct?), cin.tie() interactive
* reread the problem, try small cases
* do smth instead of nothing
*/


import java.io.*;
import java.util.*;

public class ProblemF {

    public static InputStream inputStream = System.in;

    public static OutputStream outputStream = System.out;

    public static void main(String[] args) {
        MyScanner scanner = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        int n = scanner.nextInt();
        Graph graph = new Graph(n);
        List<Pair<Integer, Integer>> edges = new ArrayList<>();
        for (int i = 0; i < n - 1; i++) {
            int x = scanner.nextInt();
            int y = scanner.nextInt();
            graph.addEdge(x, y);
            edges.add(new Pair<>(x, y));
        }

        int m = scanner.nextInt();
        List<Pair<Pair<Integer, Integer>, Integer>> list = new ArrayList<>();
        for (int i = 0; i < m; i++) {
            int x = scanner.nextInt();
            int y = scanner.nextInt();
            int w = scanner.nextInt();
            list.add(new Pair<>(new Pair<>(x, y), w));
        }

        Collections.sort(list, (a, b) -> Integer.compare(b.second, a.second));

        boolean can = true;
        for (Pair<Pair<Integer, Integer>, Integer> pair : list) {
            can = can & graph.fillF(pair.first.first, pair.first.second, pair.second);
        }

        if (!can) {
            out.print(-1);
        } else {
            for (Pair<Integer, Integer> edge : edges) {
                int a = Math.min(edge.first, edge.second);
                int b = Math.max(edge.first, edge.second);
                int x = graph.f[a][b];
                if (x == 0) {
                    out.print(1_000_000 + " ");
                } else {
                    out.print(x + " ");
                }
            }
        }

        out.flush();
    }

    private static class Graph {

        private Map<Integer, Node> nodes = new HashMap<>();

        private int[][] f;

        private Graph(int n) {
            for (int i = 1; i <= n; i++) {
                nodes.put(i, new Node(i));
            }
            f = new int[n + 1][n + 1];
        }

        private void addEdge(int x, int y) {
            nodes.get(x).adjacents.add(nodes.get(y));
            nodes.get(y).adjacents.add(nodes.get(x));
        }

        private boolean fillF(int x, int y, int w) {
            for (Node node : nodes.values()) {
                node.clean();
            }

            LinkedList<Node> toVisit = new LinkedList<>();
            toVisit.add(nodes.get(x));
            while (!toVisit.isEmpty()) {
                Node node = toVisit.poll();
                node.visited = true;
                if (node.label == y) {
                    break;
                }
                for (Node adjacent : node.adjacents) {
                    if (!adjacent.visited) {
                        adjacent.from = node;
                        adjacent.visited = true;
                        toVisit.add(adjacent);
                    }
                }
            }

            Node dest = nodes.get(y);
            boolean found = false;
            while (dest.from != null) {
                int a = Math.min(dest.label, dest.from.label);
                int b = Math.max6
                1 2
                1 6
                3 1
                1 5
                4 1
                4
                6 1 3
                3 4 1
                6 5 2
                1 2 5
                (dest.label, dest.from.label);
                if (f[a][b] == 0 || f[a][b] == w) {
                    f[a][b] = w;
                    found = true;
                }
                dest = dest.from;
            }

            return found;
        }
    }

    private static class Node {

        private int label;

        private List<Node> adjacents = new ArrayList<>();

        private boolean visited;

        private Node from;

        private Node(int label) {
            this.label = label;
        }

        private void clean() {
            visited = false;
            from = null;
        }
    }

    private static class MyScanner {
        private BufferedReader bufferedReader;
        private StringTokenizer stringTokenizer;

        private MyScanner(InputStream inputStream) {
            bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        }

        private String next() {
            while (stringTokenizer == null || !stringTokenizer.hasMoreElements()) {
                try {
                    stringTokenizer = new StringTokenizer(bufferedReader.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return stringTokenizer.nextToken();
        }

        private int nextInt() {
            return Integer.parseInt(next());
        }

        private long nextLong() {
            return Long.parseLong(next());
        }

        private double nextDouble() {
            return Double.parseDouble(next());
        }

        private String nextLine() {
            String str = "";
            try {
                str = bufferedReader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    private static class Pair<F, S> {

        private F first;

        private S second;

        public Pair() {}

        public Pair(F first, S second) {
            this.first = first;
            this.second = second;
        }
    }
}


import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.Map;

public class Main {

	private static final String NO = "NO";
	private static final String YES = "YES";
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	private static final long MOD = 1000000007L;

	Map<Integer, Integer> g[];
	int p[];
	int h[];
	int res[];

	void solve() {
		StringBuffer sb = new StringBuffer();
		int N = ni();
		int ans = 0;
		g = new Map[N];
		for (int i = 0; i < N; i++)
			g[i] = new HashMap<Integer, Integer>();
		p = new int[N];
		h = new int[N];
		res = new int[N - 1];
//		Arrays.fill(res, 1000000);
		for (int i = 0; i < N - 1; i++) {
			int u = ni() - 1;
			int v = ni() - 1;
			g[u].put(v, i);
			g[v].put(u, i);
		}
		dfs(0, -1, 0);
		int Q = ni();
		int[][] q = new int[Q][];
		for (int i = 0; i < Q; i++) {
			int u = ni() - 1;
			int v = ni() - 1;
			int b = ni() - 1;
			if (h[u] > h[v]) {
				int tmp = v;
				v = u;
				u = tmp;
			}
			q[i] = new int[] { u, v, b };
			while (h[v] > h[u]) {
				Integer e = g[v].get(p[v]);
				res[e] = Math.max(res[e], b);
				v = p[v];
			}
			while (v != u) {
				int e = g[v].get(p[v]);
				res[e] = Math.max(res[e], b);
				e = g[u].get(p[u]);
				res[e] = Math.max(res[e], b);
				v = p[v];
				u = p[u];
			}
		}
//		tr(p, h, res);
		boolean ok = true;
		out: for (int i = 0; i < Q; i++) {
			int u = q[i][0];
			int v = q[i][1];
			int b = q[i][2];
			int min = Integer.MAX_VALUE;
			while (h[v] > h[u]) {
				Integer e = g[v].get(p[v]);
				min = Math.min(res[e], min);
				v = p[v];
			}
			while (v != u) {
				Integer e = g[v].get(p[v]);
				min = Math.min(res[e], min);
				e = g[u].get(p[u]);
				min = Math.min(res[e], min);
				v = p[v];
				u = p[u];
			}
			if (min != b) {
				ok = false;
				break;
			}
		}

		if (ok) {
			for (int i : res)
				sb.append(i + 1).append(' ');
		} else
			sb.append(-1);
		out.println(sb);
	}

	private void dfs(int u, int pa, int depth) {
		h[u] = depth;
		for (int v : g[u].keySet()) {
			if (v != pa) {
				p[v] = u;
				dfs(v, u, depth + 1);
			}
		}
	}

	long power(long a, long b) {
		long x = 1, y = a;
		while (b > 0) {
			if (b % 2 != 0) {
				x = (x * y) % MOD;
			}
			y = (y * y) % MOD;
			b /= 2;
		}
		return x % MOD;
	}

	private long gcd(long a, long b) {
		while (a != 0) {
			long tmp = b % a;
			b = a;
			a = tmp;
		}
		return b;
	}

	void run() throws Exception {
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		if (!INPUT.isEmpty())
			tr(System.currentTimeMillis() - s + "ms");
	}

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;
	private boolean vis[];

	private int readByte() {
		if (lenbuf == -1)
			throw new InputMismatchException();
		if (ptrbuf >= lenbuf) {
			ptrbuf = 0;
			try {
				lenbuf = is.read(inbuf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (lenbuf <= 0)
				return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) {
		return !(c >= 33 && c <= 126);
	}

	private int skip() {
		int b;
		while ((b = readByte()) != -1 && isSpaceChar(b))
			;
		return b;
	}

	private double nd() {
		return Double.parseDouble(ns());
	}

	private char nc() {
		return (char) skip();
	}

	private String ns() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != '
									// ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n) {
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while (p < n) {
			if (!(isSpaceChar(b)))
				buf[p++] = (char) b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m) {
		char[][] map = new char[n][];
		for (int i = 0; i < n; i++)
			map[i] = ns(m);
		return map;
	}

	private int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

	private Integer[] na2(int n) {
		Integer[] a = new Integer[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

	private int[][] na(int n, int m) {
		int[][] a = new int[n][];
		for (int i = 0; i < n; i++)
			a[i] = na(m);
		return a;
	}

	private Integer[][] na2(int n, int m) {
		Integer[][] a = new Integer[n][];
		for (int i = 0; i < n; i++)
			a[i] = na2(m);
		return a;
	}

	private int ni() {
		int num = 0, b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl() {
		long num = 0;
		int b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private static void tr(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
}


import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.Map;

public class Main {

	private static final String NO = "NO";
	private static final String YES = "YES";
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	private static final long MOD = 1000000007L;

	Map<Integer, Integer> g[];
	int p[];
	int h[];
	int res[];

	void solve() {
		StringBuffer sb = new StringBuffer();
		int N = ni();
		int ans = 0;
		g = new Map[N];
		for (int i = 0; i < N; i++)
			g[i] = new HashMap<Integer, Integer>();
		p = new int[N];
		h = new int[N];
		res = new int[N - 1];
		for (int i = 0; i < N - 1; i++) {
			int u = ni() - 1;
			int v = ni() - 1;
			g[u].put(v, i);
			g[v].put(u, i);
		}
		dfs(0, -1, 0);
		int Q = ni();
		int[][] q = new int[Q][];
		for (int i = 0; i < Q; i++) {
			int u = ni() - 1;
			int v = ni() - 1;
			int b = ni() - 1;
			if (h[u] > h[v]) {
				int tmp = v;
				v = u;
				u = tmp;
			}
			q[i] = new int[] { u, v, b };
			while (h[v] > h[u]) {
				Integer e = g[v].get(p[v]);
				res[e] = Math.max(res[e], b);
				v = p[v];
			}
			while (v != u) {
				int e = g[v].get(p[v]);
				res[e] = Math.max(res[e], b);
				e = g[u].get(p[u]);
				res[e] = Math.max(res[e], b);
				v = p[v];
				u = p[u];
			}
			res[v] = Math.max(res[v], b);
		}
//		tr(p, h, res);
		boolean ok = true;
		out: for (int i = 0; i < Q; i++) {
			int u = q[i][0];
			int v = q[i][1];
			int b = q[i][2];
			int min = Integer.MAX_VALUE;
			while (h[v] > h[u]) {
				Integer e = g[v].get(p[v]);
				min = Math.min(res[e], min);
				v = p[v];
			}
			while (v != u) {
				Integer e = g[v].get(p[v]);
				min = Math.min(res[e], min);
				e = g[u].get(p[u]);
				min = Math.min(res[e], min);
				v = p[v];
				u = p[u];
			}
			if (min != b) {
				ok = false;
				break;
			}
		}

		if (ok) {
			for (int i : res)
				sb.append(i + 1).append(' ');
		} else
			sb.append(-1);
		out.println(sb);
	}

	private void dfs(int u, int pa, int depth) {
		h[u] = depth;
		for (int v : g[u].keySet()) {
			if (v != pa) {
				p[v] = u;
				dfs(v, u, depth + 1);
			}
		}
	}

	long power(long a, long b) {
		long x = 1, y = a;
		while (b > 0) {
			if (b % 2 != 0) {
				x = (x * y) % MOD;
			}
			y = (y * y) % MOD;
			b /= 2;
		}
		return x % MOD;
	}

	private long gcd(long a, long b) {
		while (a != 0) {
			long tmp = b % a;
			b = a;
			a = tmp;
		}
		return b;
	}

	void run() throws Exception {
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		if (!INPUT.isEmpty())
			tr(System.currentTimeMillis() - s + "ms");
	}

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;
	private boolean vis[];

	private int readByte() {
		if (lenbuf == -1)
			throw new InputMismatchException();
		if (ptrbuf >= lenbuf) {
			ptrbuf = 0;
			try {
				lenbuf = is.read(inbuf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (lenbuf <= 0)
				return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) {
		return !(c >= 33 && c <= 126);
	}

	private int skip() {
		int b;
		while ((b = readByte()) != -1 && isSpaceChar(b))
			;
		return b;
	}

	private double nd() {
		return Double.parseDouble(ns());
	}

	private char nc() {
		return (char) skip();
	}

	private String ns() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != '
									// ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n) {
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while (p < n) {
			if (!(isSpaceChar(b)))
				buf[p++] = (char) b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m) {
		char[][] map = new char[n][];
		for (int i = 0; i < n; i++)
			map[i] = ns(m);
		return map;
	}

	private int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

	private Integer[] na2(int n) {
		Integer[] a = new Integer[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

	private int[][] na(int n, int m) {
		int[][] a = new int[n][];
		for (int i = 0; i < n; i++)
			a[i] = na(m);
		return a;
	}

	private Integer[][] na2(int n, int m) {
		Integer[][] a = new Integer[n][];
		for (int i = 0; i < n; i++)
			a[i] = na2(m);
		return a;
	}

	private int ni() {
		int num = 0, b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl() {
		long num = 0;
		int b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private static void tr(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
}


'use strict'

const n = +readline();

const edges = Array.from({ length: n - 1 }, () => readline().split(' ').map(i => +i - 1));
const passengers = Array.from({ length: +readline() }, () => readline().split(' ').map(i => +i)).map(([ a, b, score ]) => [ a - 1, b - 1, score ]);

const rootTree = (graph, n) => {
    // Do a DFS to (arbitrarily) root the tree and record depths
    const parent = [ Infinity, ...Array(n-1).fill(null) ];
    const parentEdge = [ Infinity, ...Array(n-1).fill(null) ];
    const depth = [ 0, ...Array(n-1).fill(null) ];
    const stack = [ 0 ];
    while (stack.length) {
        const node = stack.pop();
        Object.keys(graph[node]).forEach((k) => {
            const edgeId = graph[node][k];
            if (parent[k] !== null) return;
            parent[k] = node;
            parentEdge[k] = edgeId;
            depth[k] = depth[node] + 1;
            stack.unshift(k);
        });
    }
    return { parent, parentEdge, depth };
}

const getLCAEdges = (parent, parentEdge, depth, source, dest) => {
    // Find shortest path by walking both nodes up till their LCA
    // Returns the edge ids in arbitrary order!
    let A = source, B = dest;

    // Start them at the same depth first
    let dA = depth[A], dB = depth[B];
    const r = [];
    while (dA > dB) {
        r.push(parentEdge[A]);
        A = parent[A];
        dA -= 1;
    }
    while (dA < dB) {
        r.push(parentEdge[B]);
        B = parent[B];
        dB -= 1;
    }
    // Walk up both paths until find lca
    while (A !== B) {
        r.push(parentEdge[A]);
        A = parent[A];
        r.push(parentEdge[B]);
        B = parent[B];
    }
    return r;
}

const problem = (n, edges, passengers) => {
    const graph = {}

    edges.forEach(([ x, y ], i) => {
        if (!graph[x]) graph[x] = {};
        if (!graph[y]) graph[y] = {};
        graph[x][y] = i;
        graph[y][x] = i;
    })

    const { parent, parentEdge, depth } = rootTree(graph, n)
    // Sort by score, high to low
    passengers.sort((a, b) => b[2] - a[2]);
    // For each passenger, set any unset edges in their path to their min score
    const scores = Array(n - 1).fill(null);

    for (let i = 0; i < passengers.length; i++) {
        const [ a, b, score ] = passengers[i];
        let numEdges = 0;
        const lca = getLCAEdges(parent, parentEdge, depth, a, b);
        for (let j = 0; j < lca.length; j++) {
            const edgeId = lca[j];
            if (scores[edgeId] === null) {
                numEdges += 1;
                scores[edgeId] = score;
            } else {
                // Since sorted any existing scores must higher or equal
                // Can't overwrite lower because will lower the previous's min score
                if (scores[edgeId] === score) numEdges += 1
            }
        }
        // Need to set at least one edge
        if (numEdges == 0) return -1;
    }

    return scores.map(i => i || 1).join(' ');
}

print(problem(n, edges, passengers));


'use strict'

const n = +readline();
const edges = Array.from({ length: n - 1 }, () => readline().split(' ').map(i => +i - 1));
const passengers = Array.from({ length: +readline() }, () => readline().split(' ').map(i => +i)).map(p => [ p[0] - 1, p[1] - 1, p[2] ]);

const rootTree = (graph, n) => {
    // Do a DFS to (arbitrarily) root the tree and record depths
    const parent = Array(n).fill(null); parent[0] = Infinity;
    const parentEdge = Array(n).fill(null); parentEdge[0] = Infinity;
    const depth = Array(n).fill(null); depth[0] = 0;
    const stack = [ 0 ];
    while (stack.length) {
        const node = stack.pop();
        Object.keys(graph[node]).forEach((k) => {
            const edgeId = graph[node][k];
            if (parent[k] !== null) return;
            parent[k] = +node;
            parentEdge[k] = edgeId;
            depth[k] = depth[node] + 1;
            stack.unshift(k);
        });
    }
    return { parent, parentEdge, depth };
}

function* getLCAEdges(parent, parentEdge, depth, source, dest) {
    // Find shortest path by walking both nodes up till their LCA
    // Returns the edge ids in arbitrary order!
    let A = source, B = dest;

    // Start them at the same depth first
    let dA = depth[A], dB = depth[B];
    const r = [];
    while (dA > dB) {
        yield parentEdge[A];
        A = parent[A];
        dA -= 1;
    }
    while (dA < dB) {
        yield parentEdge[B];
        B = parent[B];
        dB -= 1;
    }
    // Walk up both paths until find lca
    while (A !== B) {
        yield parentEdge[A];
        A = parent[A];
        yield parentEdge[B];
        B = parent[B];
    }
    return r;
}

const problem = (n, edges, passengers) => {
    const graph = {};

    edges.forEach((a, i) => {
        const x = a[0], y = a[1];
        if (!graph[x]) graph[x] = {};
        if (!graph[y]) graph[y] = {};
        graph[x][y] = i;
        graph[y][x] = i;
    })

    const rt = rootTree(graph, n)
    const parent = rt.parent;
    const parentEdge = rt.parentEdge;
    const depth = rt.depth;
    // Sort by score, high to low
    passengers.sort((a, b) => b[2] - a[2]);
    // For each passenger, set any unset edges in their path to their min score
    const scores = Array(n - 1).fill(null);

    for (let i = 0; i < passengers.length; i++) {
        const p = passengers[i];
        const a = p[0];
        const b = p[1];
        const score = p[2];
        let numEdges = 0;

        for (let edgeId of getLCAEdges(parent, parentEdge, depth, a, b)) {
            if (scores[edgeId] === null) {
                numEdges += 1;
                scores[edgeId] = score;
            } else {
                // Since sorted any existing scores must higher or equal
                // Can't overwrite lower because will lower the previous's min score
                if (scores[edgeId] === score) numEdges += 1
            }
        }
        // Need to set at least one edge
        if (numEdges == 0) return -1;
    }

    return scores.map(i => i || 1).join(' ');
}

print(problem(n, edges, passengers));


'use strict'

const n = +readline();
const edges = Array.from({ length: n - 1 }, () => readline().split(' ').map(i => +i - 1));
const passengers = Array.from({ length: +readline() }, () => readline().split(' ').map(i => +i)).map(([ a, b, score ]) => [ a - 1, b - 1, score ]);

const rootTree = (graph, n) => {
    // Do a DFS to (arbitrarily) root the tree and record depths
    const parent = [ Infinity, ...Array(n-1).fill(null) ];
    const parentEdge = [ Infinity, ...Array(n-1).fill(null) ];
    const depth = [ 0, ...Array(n-1).fill(null) ];
    const stack = [ 0 ];
    while (stack.length) {
        const node = stack.pop();
        Object.keys(graph[node]).forEach((k) => {
            const edgeId = graph[node][k];
            if (parent[k] !== null) return;
            parent[k] = node;
            parentEdge[k] = edgeId;
            depth[k] = depth[node] + 1;
            stack.unshift(k);
        });
    }
    return { parent, parentEdge, depth };
}

const getLCAEdges = (parent, parentEdge, depth, source, dest) => {
    // Find shortest path by walking both nodes up till their LCA
    // Returns the edge ids in arbitrary order!
    let A = source, B = dest;

    // Start them at the same depth first
    let dA = depth[A], dB = depth[B];
    const r = [];
    while (dA > dB) {
        r.push(parentEdge[A]);
        A = parent[A];
        dA -= 1;
    }
    while (dA < dB) {
        r.push(parentEdge[B]);
        B = parent[B];
        dB -= 1;
    }
    // Walk up both paths until find lca
    while (A !== B) {
        r.push(parentEdge[A]);
        A = parent[A];
        r.push(parentEdge[B]);
        B = parent[B];
    }
    return r;
}

const problem = (n, edges, passengers) => {
    const graph = {}

    edges.forEach(([ x, y ], i) => {
        if (!graph[x]) graph[x] = {};
        if (!graph[y]) graph[y] = {};
        graph[x][y] = i;
        graph[y][x] = i;
    })

    const rt = rootTree(graph, n)
    const parent = rt.parent;
    const parentEdge = rt.parentEdge;
    const depth = rt.depth;
    // Sort by score, high to low
    passengers.sort((a, b) => b[2] - a[2]);
    // For each passenger, set any unset edges in their path to their min score
    const scores = Array(n - 1).fill(null);

    for (let i = 0; i < passengers.length; i++) {
        const p = passengers[i];
        const a = p[0];
        const b = p[1];
        const score = p[2];
        let numEdges = 0;
        const lca = getLCAEdges(parent, parentEdge, depth, a, b);
        for (let j = 0; j < lca.length; j++) {
            const edgeId = lca[j];
            if (scores[edgeId] === null) {
                numEdges += 1;
                scores[edgeId] = score;
            } else {
                // Since sorted any existing scores must higher or equal
                // Can't overwrite lower because will lower the previous's min score
                if (scores[edgeId] === score) numEdges += 1
            }
        }
        // Need to set at least one edge
        if (numEdges == 0) return -1;
    }

    return scores.map(i => i || 1).join(' ');
}

print(problem(n, edges, passengers));


'use strict'

const n = +readline();
const edges = Array.from({ length: n - 1 }, () => readline().split(' ').map(i => +i - 1));
const passengers = Array.from({ length: +readline() }, () => readline().split(' ').map(i => +i)).map(p => [ p[0] - 1, p[1] - 1, p[2] ]);

const rootTree = (graph, n) => {
    // Do a DFS to (arbitrarily) root the tree and record depths
    const parent = Array(n).fill(null); parent[0] = Infinity;
    const parentEdge = Array(n).fill(null); parentEdge[0] = Infinity;
    const depth = Array(n).fill(null); depth[0] = 0;
    const stack = [ 0 ];
    while (stack.length) {
        const node = stack.pop();
        Object.keys(graph[node]).forEach((k) => {
            const edgeId = graph[node][k];
            if (parent[k] !== null) return;
            parent[k] = node;
            parentEdge[k] = edgeId;
            depth[k] = depth[node] + 1;
            stack.unshift(k);
        });
    }
    return { parent, parentEdge, depth };
}

const getLCAEdges = (parent, parentEdge, depth, source, dest) => {
    // Find shortest path by walking both nodes up till their LCA
    // Returns the edge ids in arbitrary order!
    let A = source, B = dest;

    // Start them at the same depth first
    let dA = depth[A], dB = depth[B];
    const r = [];
    while (dA > dB) {
        r.push(parentEdge[A]);
        A = parent[A];
        dA -= 1;
    }
    while (dA < dB) {
        r.push(parentEdge[B]);
        B = parent[B];
        dB -= 1;
    }
    // Walk up both paths until find lca
    while (A !== B) {
        r.push(parentEdge[A]);
        A = parent[A];
        r.push(parentEdge[B]);
        B = parent[B];
    }
    return r;
}

const problem = (n, edges, passengers) => {
    const graph = {}

    edges.forEach(([ x, y ], i) => {
        if (!graph[x]) graph[x] = {};
        if (!graph[y]) graph[y] = {};
        graph[x][y] = i;
        graph[y][x] = i;
    })

    const rt = rootTree(graph, n)
    const parent = rt.parent;
    const parentEdge = rt.parentEdge;
    const depth = rt.depth;
    // Sort by score, high to low
    passengers.sort((a, b) => b[2] - a[2]);
    // For each passenger, set any unset edges in their path to their min score
    const scores = Array(n - 1).fill(null);

    for (let i = 0; i < passengers.length; i++) {
        const p = passengers[i];
        const a = p[0];
        const b = p[1];
        const score = p[2];
        let numEdges = 0;
        const lca = getLCAEdges(parent, parentEdge, depth, a, b);
        for (let j = 0; j < lca.length; j++) {
            const edgeId = lca[j];
            if (scores[edgeId] === null) {
                numEdges += 1;
                scores[edgeId] = score;
            } else {
                // Since sorted any existing scores must higher or equal
                // Can't overwrite lower because will lower the previous's min score
                if (scores[edgeId] === score) numEdges += 1
            }
        }
        // Need to set at least one edge
        if (numEdges == 0) return -1;
    }

    return scores.map(i => i || 1).join(' ');
}

print(problem(n, edges, passengers));


'use strict'

const n = +readline();
const edges = Array.from({ length: n - 1 }, () => readline().split(' ').map(i => +i - 1));
const passengers = Array.from({ length: +readline() }, () => readline().split(' ').map(i => +i)).map(p => [ p[0] - 1, p[1] - 1, p[2] ]);

const rootTree = (graph, n) => {
    // Do a DFS to (arbitrarily) root the tree and record depths
    const parent = Array(n).fill(null); parent[0] = Infinity;
    const parentEdge = Array(n).fill(null); parentEdge[0] = Infinity;
    const depth = Array(n).fill(null); depth[0] = 0;
    const stack = [ 0 ];
    while (stack.length) {
        const node = stack.pop();
        Object.keys(graph[node]).forEach((k) => {
            const edgeId = graph[node][k];
            if (parent[k] !== null) return;
            parent[k] = node;
            parentEdge[k] = edgeId;
            depth[k] = depth[node] + 1;
            stack.unshift(k);
        });
    }
    return { parent, parentEdge, depth };
}

const getLCAEdges = (parent, parentEdge, depth, source, dest) => {
    // Find shortest path by walking both nodes up till their LCA
    // Returns the edge ids in arbitrary order!
    let A = source, B = dest;

    // Start them at the same depth first
    let dA = depth[A], dB = depth[B];
    const r = [];
    while (dA > dB) {
        r.push(parentEdge[A]);
        A = parent[A];
        dA -= 1;
    }
    while (dA < dB) {
        r.push(parentEdge[B]);
        B = parent[B];
        dB -= 1;
    }
    // Walk up both paths until find lca
    while (A !== B) {
        r.push(parentEdge[A]);
        A = parent[A];
        r.push(parentEdge[B]);
        B = parent[B];
    }
    return r;
}

const problem = (n, edges, passengers) => {
    const graph = {};

    edges.forEach((a, i) => {
        const x = a[0], y = a[1];
        if (!graph[x]) graph[x] = {};
        if (!graph[y]) graph[y] = {};
        graph[x][y] = i;
        graph[y][x] = i;
    })

    const rt = rootTree(graph, n)
    const parent = rt.parent;
    const parentEdge = rt.parentEdge;
    const depth = rt.depth;
    // Sort by score, high to low
    passengers.sort((a, b) => b[2] - a[2]);
    // For each passenger, set any unset edges in their path to their min score
    const scores = Array(n - 1).fill(null);

    for (let i = 0; i < passengers.length; i++) {
        const p = passengers[i];
        const a = p[0];
        const b = p[1];
        const score = p[2];
        let numEdges = 0;
        const lca = getLCAEdges(parent, parentEdge, depth, a, b);
        for (let j = 0; j < lca.length; j++) {
            const edgeId = lca[j];
            if (scores[edgeId] === null) {
                numEdges += 1;
                scores[edgeId] = score;
            } else {
                // Since sorted any existing scores must higher or equal
                // Can't overwrite lower because will lower the previous's min score
                if (scores[edgeId] === score) numEdges += 1
            }
        }
        // Need to set at least one edge
        if (numEdges == 0) return -1;
    }

    return scores.map(i => i || 1).join(' ');
}

print(problem(n, edges, passengers));


'use strict'

const n = +readline();
const edges = Array.from({ length: n - 1 }, () => readline().split(' ').map(i => +i - 1));
const passengers = Array.from({ length: +readline() }, () => readline().split(' ').map(i => +i)).map(p => [ p[0] - 1, p[1] - 1, p[2] ]);

const rootTree = (graph, n) => {
    // Do a DFS to (arbitrarily) root the tree and record depths
    const parent = Array(n).fill(null); parent[0] = Infinity;
    const parentEdge = Array(n).fill(null); parentEdge[0] = Infinity;
    const depth = Array(n).fill(null); depth[0] = 0;
    const stack = [ 0 ];
    while (stack.length) {
        const node = stack.pop();
        Object.keys(graph[node]).forEach((k) => {
            const edgeId = graph[node][k];
            if (parent[k] !== null) return;
            parent[k] = +node;
            parentEdge[k] = edgeId;
            depth[k] = depth[node] + 1;
            stack.unshift(k);
        });
    }
    return { parent, parentEdge, depth };
}

const getLCAEdges = (parent, parentEdge, depth, source, dest) => {
    // Find shortest path by walking both nodes up till their LCA
    // Returns the edge ids in arbitrary order!
    let A = source, B = dest;

    // Start them at the same depth first
    let dA = depth[A], dB = depth[B];
    const r = [];
    while (dA > dB) {
        r.push(parentEdge[A]);
        A = parent[A];
        dA -= 1;
    }
    while (dA < dB) {
        r.push(parentEdge[B]);
        B = parent[B];
        dB -= 1;
    }
    // Walk up both paths until find lca
    while (A !== B) {
        r.push(parentEdge[A]);
        A = parent[A];
        r.push(parentEdge[B]);
        B = parent[B];
    }
    return r;
}

const problem = (n, edges, passengers) => {
    const graph = {};

    edges.forEach((a, i) => {
        const x = a[0], y = a[1];
        if (!graph[x]) graph[x] = {};
        if (!graph[y]) graph[y] = {};
        graph[x][y] = i;
        graph[y][x] = i;
    })

    const rt = rootTree(graph, n)
    const parent = rt.parent;
    const parentEdge = rt.parentEdge;
    const depth = rt.depth;
    // Sort by score, high to low
    passengers.sort((a, b) => b[2] - a[2]);
    // For each passenger, set any unset edges in their path to their min score
    const scores = Array(n - 1).fill(null);

    for (let i = 0; i < passengers.length; i++) {
        const p = passengers[i];
        const a = p[0];
        const b = p[1];
        const score = p[2];
        let numEdges = 0;
        const lca = getLCAEdges(parent, parentEdge, depth, a, b);
        for (let j = 0; j < lca.length; j++) {
            const edgeId = lca[j];
            if (scores[edgeId] === null) {
                numEdges += 1;
                scores[edgeId] = score;
            } else {
                // Since sorted any existing scores must higher or equal
                // Can't overwrite lower because will lower the previous's min score
                if (scores[edgeId] === score) numEdges += 1
            }
        }
        // Need to set at least one edge
        if (numEdges == 0) return -1;
    }

    return scores.map(i => i || 1).join(' ');
}

print(problem(n, edges, passengers));