#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <valarray>
#include <string>
#include <cmath>
#include <numeric>
#include <cctype>
#include <set>
#include <map>
#define PB push_back
#define SIZE(x) (int)x.size()
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef valarray<LL> VALI;
typedef valarray<char> VALC;
typedef multiset<char> MC;
typedef set<int> SI;
typedef vector<string> VS;
//inline double round(const double& x) { return floor(x+0.5); }
template <class T>
istream& operator>>(istream& input, vector<T>& V)
{
for (int i = 0; i<SIZE(V); ++i) input >> V[i];
return input;
}
class abakus
{
private:
string T[15];
int ileKolumn;
string cyfryKol[10];
string napis;
void budujKolumne(int kolumna, int cyfra)
{
for (int i = 0; i<11; ++i) T[i + 2][kolumna] = cyfryKol[cyfra][i];
}
int czytajKolumne(int kolumna)
{
string kol;
for (int i = 0; i<11; ++i) kol += T[i + 2][kolumna];
for (int cyfra = 0; cyfra <= 9; ++cyfra)
{
if (cyfryKol[cyfra] == kol) return cyfra;
}
return -1;
}
void usunWiodaceZera()
{
napis.erase(0, napis.find_first_not_of('0'));
if (napis.empty()) napis = "0";
}
public:
abakus()
{
cyfryKol[0] = "* - ****";
cyfryKol[1] = "* -* ***";
cyfryKol[2] = "* -** **";
cyfryKol[3] = "* -*** *";
cyfryKol[4] = "* -**** ";
cyfryKol[5] = " *- ****";
cyfryKol[6] = " *-* ***";
cyfryKol[7] = " *-** **";
cyfryKol[8] = " *-*** *";
cyfryKol[9] = " *-**** ";
}
void czytaj(const string& S)
{
napis = S;
ileKolumn = SIZE(S);
for (int i = 0; i<15; ++i)
{
if (i == 0 || i == 14) T[i] = string(ileKolumn + 2, '-');
else T[i] = string(ileKolumn + 2, '|');
}
for (int i = 1; i <= ileKolumn; ++i)
{
T[0][i] = T[14][i] = '-';
T[13][i] = T[1][i] = '*';
}
for (int i = 0; i<ileKolumn; ++i)
{
int cyfra = S[i] - '0';
budujKolumne(i + 1, cyfra);
}
}
void czytaj()
{
cin.ignore();
for (int i = 0; i<15; ++i)
{
string wiersz;
getline(cin, wiersz);
if (i == 0) ileKolumn = SIZE(wiersz);
T[i] = wiersz;
}
for (int i = 1; i<ileKolumn - 1; ++i)
{
int cyfra = czytajKolumne(i);
napis += '0' + cyfra;
}
usunWiodaceZera();
}
void wypisz()
{
cout << napis;
}
void rysuj()
{
for (int i = 0; i<14; ++i) cout << T[i] << endl;
cout << T[14];
}
};
int main()
{
ios::sync_with_stdio(0);
bool first = true;
int x;
while (cin >> x)
{
if (first) first = false;
else cout << endl;
abakus A;
if (x == 0)
{
A.czytaj();
A.wypisz();
}
else
{
string napis;
cin >> napis;
A.czytaj(napis);
A.rysuj();
}
}
return 0;
}