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

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

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

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

e = A("e")
h = B("h")
k = C("k")
i = D("i")
m = B("m")
b = C("b")

e.p = b
h.s = k
h.z = e
k.v = b
k.z = b
i.t = h
i.q = b
m.s = b
m.z = e
b.v = k
b.z = k
assert m.z.p.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

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

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

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

e = A("e")
h = B("h")
k = C("k")
i = D("i")
m = B("m")
b = C("b")

e.p = b
h.s = k
h.z = e
k.v = b
k.z = b
i.t = h
i.q = b
m.s = b
m.z = e
b.v = k
b.z = k
assert m.z.p.v.v.txt == "b"