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

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

l = A("l")
g = B("g")
h = A("h")

l.o = h
l.w = g
g.z = h
h.o = l
h.w = g
assert h.w.z.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.w: B = None
        self.txt = txt

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

l = A("l")
g = B("g")
h = A("h")

l.o = h
l.w = g
g.z = h
h.o = l
h.w = g
assert h.w.z.o.txt == "l"