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

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

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

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

class E:
    def __init__(self, txt: str):
        self.y: D = None
        self.txt = txt

h = A("h")
i = B("i")
j = C("j")
d = D("d")
c = E("c")
m = D("m")

h.p = j
i.y = j
i.u = j
j.t = m
j.z = h
d.v = h
d.s = c
d.z = c
c.y = m
m.v = h
m.s = c
m.z = c
assert h.p.z.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

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

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

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

class E:
    def __init__(self, txt: str):
        self.y: D = None
        self.txt = txt

h = A("h")
i = B("i")
j = C("j")
d = D("d")
c = E("c")
m = D("m")

h.p = j
i.y = j
i.u = j
j.t = m
j.z = h
d.v = h
d.s = c
d.z = c
c.y = m
m.v = h
m.s = c
m.z = c
assert h.p.z.p.txt == "j"