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

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

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

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

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

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

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