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

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

j = A("j")
a = B("a")
i = B("i")

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

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

j = A("j")
a = B("a")
i = B("i")

j.r = a
a.o = i
a.x = i
i.o = a
i.x = a
assert a.o.x.o.txt == "i"