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

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

a = A("a")
n = B("n")
b = A("b")

a.p = b
n.t = b
b.p = a
assert b.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

a = A("a")
n = B("n")
b = A("b")

a.p = b
n.t = b
b.p = a
assert b.p.p.p.txt == "a"