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

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

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

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

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

d.r = k
d.z = h
i.y = d
k.v = l
h.r = k
h.p = b
l.r = k
l.z = b
b.r = k
b.p = h
assert k.v.z.r.v.z.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.z: D = None
        self.txt = txt

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

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

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

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

d.r = k
d.z = h
i.y = d
k.v = l
h.r = k
h.p = b
l.r = k
l.z = b
b.r = k
b.p = h
assert k.v.z.r.v.z.txt == "b"