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

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

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

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

a = A("a")
d = B("d")
h = C("h")
f = D("f")

a.r = h
a.z = h
d.w = f
h.r = a
h.u = d
h.o = d
h.q = d
f.x = h
assert h.r.z.q.w.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.z: C = None
        self.txt = txt

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

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

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

a = A("a")
d = B("d")
h = C("h")
f = D("f")

a.r = h
a.z = h
d.w = f
h.r = a
h.u = d
h.o = d
h.q = d
f.x = h
assert h.r.z.q.w.txt == "f"