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

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

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

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

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

h.u = f
h.q = f
h.z = b
f.u = b
b.z = h
b.v = f
m.q = f
m.z = f
m.r = b
assert m.r.z.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.q: B = None
        self.z: C = None
        self.txt = txt

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

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

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

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

h.u = f
h.q = f
h.z = b
f.u = b
b.z = h
b.v = f
m.q = f
m.z = f
m.r = b
assert m.r.z.u.u.txt == "b"