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

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

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

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

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

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

a.r = k
k.p = c
c.r = k
l.r = k
assert a.r.p.r.txt == "k"