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

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

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

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

h = A("h")
c = B("c")
b = C("b")
m = D("m")

h.q = b
h.u = b
h.x = b
c.u = h
c.t = h
b.z = h
m.o = b
assert b.z.x.z.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.u: C = None
        self.x: C = None
        self.txt = txt

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

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

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

h = A("h")
c = B("c")
b = C("b")
m = D("m")

h.q = b
h.u = b
h.x = b
c.u = h
c.t = h
b.z = h
m.o = b
assert b.z.x.z.txt == "h"