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

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

j = A("j")
g = B("g")
n = B("n")

j.o = n
g.s = j
n.s = j
assert g.s.o.s.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

j = A("j")
g = B("g")
n = B("n")

j.o = n
g.s = j
n.s = j
assert g.s.o.s.txt == "j"