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

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

k = A("k")
i = B("i")
c = A("c")

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

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

k = A("k")
i = B("i")
c = A("c")

k.r = c
i.p = k
c.r = k
assert c.r.r.r.txt == "k"