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

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

a = A("a")
e = B("e")
b = A("b")
k = A("k")
m = B("m")
l = B("l")
h = A("h")

a.x = l
a.q = b
e.u = m
e.z = h
b.x = l
b.q = h
k.x = l
k.q = b
m.u = e
m.z = a
l.u = e
l.z = h
h.x = m
h.q = a
assert e.z.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.q: A = None
        self.txt = txt

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

a = A("a")
e = B("e")
b = A("b")
k = A("k")
m = B("m")
l = B("l")
h = A("h")

a.x = l
a.q = b
e.u = m
e.z = h
b.x = l
b.q = h
k.x = l
k.q = b
m.u = e
m.z = a
l.u = e
l.z = h
h.x = m
h.q = a
assert e.z.q.q.q.q.txt == "a"