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

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

m = A("m")
a = B("a")
f = B("f")

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

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

m = A("m")
a = B("a")
f = B("f")

m.p = a
m.t = a
a.p = f
a.r = f
f.p = a
f.r = a
assert m.p.p.p.txt == "a"