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

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

i = A("i")
m = B("m")
b = B("b")

i.r = b
m.p = b
b.p = m
assert b.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

i = A("i")
m = B("m")
b = B("b")

i.r = b
m.p = b
b.p = m
assert b.p.p.p.txt == "m"