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

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

k = A("k")
e = B("e")
m = B("m")

k.r = e
e.r = m
e.p = m
m.r = e
m.p = e
assert m.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.r: B = None
        self.p: B = None
        self.txt = txt

k = A("k")
e = B("e")
m = B("m")

k.r = e
e.r = m
e.p = m
m.r = e
m.p = e
assert m.p.p.p.txt == "e"