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

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

f = A("f")
e = B("e")
a = B("a")
b = A("b")

f.t = b
e.o = f
e.r = f
a.o = b
a.r = f
b.t = f
assert a.r.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.txt = txt

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

f = A("f")
e = B("e")
a = B("a")
b = A("b")

f.t = b
e.o = f
e.r = f
a.o = b
a.r = f
b.t = f
assert a.r.t.t.txt == "f"