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

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

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

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

i = A("i")
a = B("a")
h = C("h")
j = D("j")

i.x = a
a.z = i
a.u = j
a.q = j
h.y = a
j.y = a
j.w = a
assert h.y.z.x.u.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

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

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

i = A("i")
a = B("a")
h = C("h")
j = D("j")

i.x = a
a.z = i
a.u = j
a.q = j
h.y = a
j.y = a
j.w = a
assert h.y.z.x.u.txt == "j"