class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.o: C = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.p: A = None
        self.q: D = None
        self.w: C = None
        self.u: A = None
        self.r: D = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.p: B = None
        self.u: E = None
        self.txt = txt

class D:
    def __init__(self, txt: str):
        self.v: A = None
        self.p: C = None
        self.z: A = None
        self.txt = txt

class E:
    def __init__(self, txt: str):
        self.s: A = None
        self.t: B = None
        self.txt = txt

n = A("n")
h = B("h")
i = C("i")
a = D("a")
m = E("m")

n.r = i
n.o = i
h.p = n
h.u = n
h.q = a
h.r = a
h.w = i
i.p = h
i.u = m
a.v = n
a.z = n
a.p = i
m.s = n
m.t = h
assert m.t.q.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.o: C = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.p: A = None
        self.q: D = None
        self.w: C = None
        self.u: A = None
        self.r: D = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.p: B = None
        self.u: E = None
        self.txt = txt

class D:
    def __init__(self, txt: str):
        self.v: A = None
        self.p: C = None
        self.z: A = None
        self.txt = txt

class E:
    def __init__(self, txt: str):
        self.s: A = None
        self.t: B = None
        self.txt = txt

n = A("n")
h = B("h")
i = C("i")
a = D("a")
m = E("m")

n.r = i
n.o = i
h.p = n
h.u = n
h.q = a
h.r = a
h.w = i
i.p = h
i.u = m
a.v = n
a.z = n
a.p = i
m.s = n
m.t = h
assert m.t.q.p.txt == "i"