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

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

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

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

e = A("e")
h = B("h")
g = C("g")
a = D("a")
i = A("i")

e.z = a
e.w = a
e.p = h
e.q = h
h.p = i
g.z = a
a.o = h
a.y = g
i.z = a
i.w = a
i.p = h
i.q = h
assert a.y.z.o.txt == "
class A:
    def __init__(self, txt: str):
        self.z: D = None
        self.p: B = None
        self.w: D = None
        self.q: B = None
        self.txt = txt

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

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

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

e = A("e")
h = B("h")
g = C("g")
a = D("a")
i = A("i")

e.z = a
e.w = a
e.p = h
e.q = h
h.p = i
g.z = a
a.o = h
a.y = g
i.z = a
i.w = a
i.p = h
i.q = h
assert a.y.z.o.txt == "h"