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

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

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

g.x = m
m.o = e
e.x = m
assert m.o.x.o.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

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

g.x = m
m.o = e
e.x = m
assert m.o.x.o.txt == "e"