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

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

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

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

h = A("h")
i = B("i")
f = C("f")
b = D("b")

h.u = i
h.q = i
i.z = h
i.w = b
f.q = h
f.o = i
b.u = f
b.p = i
assert i.w.u.q.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.q: B = None
        self.txt = txt

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

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

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

h = A("h")
i = B("i")
f = C("f")
b = D("b")

h.u = i
h.q = i
i.z = h
i.w = b
f.q = h
f.o = i
b.u = f
b.p = i
assert i.w.u.q.txt == "h"