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

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

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

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

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

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

m.w = f
m.t = a
f.p = a
f.o = m
a.w = f
a.t = m
assert a.t.t.w.txt == "f"