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

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

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

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

a = A("a")
h = B("h")
j = C("j")
n = D("n")
b = A("b")
l = D("l")

a.z = l
h.u = a
j.u = a
n.z = b
n.r = b
n.o = a
b.z = l
l.z = a
l.r = a
l.o = a
assert b.z.r.z.r.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: D = None
        self.txt = txt

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

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

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

a = A("a")
h = B("h")
j = C("j")
n = D("n")
b = A("b")
l = D("l")

a.z = l
h.u = a
j.u = a
n.z = b
n.r = b
n.o = a
b.z = l
l.z = a
l.r = a
l.o = a
assert b.z.r.z.r.z.txt == "l"