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

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

e = A("e")
f = B("f")
h = A("h")
g = B("g")

e.q = f
e.s = g
f.o = h
f.w = g
h.q = f
h.s = f
g.o = h
g.w = f
assert e.s.w.w.o.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.s: B = None
        self.txt = txt

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

e = A("e")
f = B("f")
h = A("h")
g = B("g")

e.q = f
e.s = g
f.o = h
f.w = g
h.q = f
h.s = f
g.o = h
g.w = f
assert e.s.w.w.o.txt == "h"