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

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

k = A("k")
e = B("e")
i = A("i")
a = A("a")
b = B("b")

k.z = a
e.p = a
e.r = a
i.z = k
a.z = i
b.p = a
b.r = a
assert b.r.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

k = A("k")
e = B("e")
i = A("i")
a = A("a")
b = B("b")

k.z = a
e.p = a
e.r = a
i.z = k
a.z = i
b.p = a
b.r = a
assert b.r.z.z.txt == "k"