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

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

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

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

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

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

e.q = g
e.u = n
h.o = e
h.w = m
n.o = e
n.w = e
g.o = m
g.w = m
m.q = g
m.u = n
assert m.q.o.q.o.txt == "m"