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

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

a = A("a")
c = B("c")
k = A("k")
e = B("e")

a.r = c
c.z = k
c.y = e
k.r = e
e.z = k
e.y = c
assert k.r.y.y.z.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

a = A("a")
c = B("c")
k = A("k")
e = B("e")

a.r = c
c.z = k
c.y = e
k.r = e
e.z = k
e.y = c
assert k.r.y.y.z.txt == "k"