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

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

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

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

h = A("h")
b = B("b")
d = C("d")
k = D("k")

h.r = b
b.u = d
b.w = h
b.z = h
d.w = h
d.z = h
d.o = k
d.r = k
k.o = d
assert b.w.r.z.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

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

h = A("h")
b = B("b")
d = C("d")
k = D("k")

h.r = b
b.u = d
b.w = h
b.z = h
d.w = h
d.z = h
d.o = k
d.r = k
k.o = d
assert b.w.r.z.r.txt == "b"