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

class B:
    def __init__(self, txt: str):
        self.u: D = None
        self.q: A = None
        self.z: D = None
        self.x: C = 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.u: B = None
        self.r: A = None
        self.o: C = None
        self.z: B = None
        self.txt = txt

a = A("a")
e = B("e")
b = C("b")
d = D("d")
h = C("h")

a.r = b
e.u = d
e.z = d
e.q = a
e.x = b
b.z = a
d.u = e
d.z = e
d.r = a
d.o = b
h.z = a
assert d.r.r.z.r.z.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.u: D = None
        self.q: A = None
        self.z: D = None
        self.x: C = 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.u: B = None
        self.r: A = None
        self.o: C = None
        self.z: B = None
        self.txt = txt

a = A("a")
e = B("e")
b = C("b")
d = D("d")
h = C("h")

a.r = b
e.u = d
e.z = d
e.q = a
e.x = b
b.z = a
d.u = e
d.z = e
d.r = a
d.o = b
h.z = a
assert d.r.r.z.r.z.txt == "a"