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

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

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

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

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

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

n.u = h
n.q = e
m.o = n
m.x = i
h.o = i
h.x = n
e.u = m
e.q = n
i.u = h
i.q = n
assert h.x.u.x.txt == "n"