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

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

c = A("c")
f = B("f")
j = B("j")
a = A("a")

c.x = a
c.r = f
f.t = j
f.o = c
j.t = f
j.o = c
a.x = c
a.r = j
assert c.r.o.r.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.r: B = None
        self.txt = txt

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

c = A("c")
f = B("f")
j = B("j")
a = A("a")

c.x = a
c.r = f
f.t = j
f.o = c
j.t = f
j.o = c
a.x = c
a.r = j
assert c.r.o.r.txt == "f"