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

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

l = A("l")
e = B("e")
h = A("h")
c = B("c")
i = A("i")
m = B("m")

l.u = c
e.q = h
e.y = l
h.u = m
c.q = h
c.y = i
i.u = e
m.q = l
m.y = i
assert h.u.q.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

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

l = A("l")
e = B("e")
h = A("h")
c = B("c")
i = A("i")
m = B("m")

l.u = c
e.q = h
e.y = l
h.u = m
c.q = h
c.y = i
i.u = e
m.q = l
m.y = i
assert h.u.q.u.txt == "c"