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

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

n = A("n")
d = B("d")
m = B("m")

n.r = d
n.p = d
d.t = n
d.o = n
m.t = n
m.o = n
assert m.t.r.o.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.p: B = None
        self.txt = txt

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

n = A("n")
d = B("d")
m = B("m")

n.r = d
n.p = d
d.t = n
d.o = n
m.t = n
m.o = n
assert m.t.r.o.txt == "n"