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

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

n = A("n")
d = B("d")
h = B("h")
m = A("m")
l = A("l")
b = B("b")
j = A("j")
e = A("e")
c = B("c")

n.q = e
d.x = n
h.x = e
m.q = l
l.q = e
b.x = l
j.q = m
e.q = m
c.x = n
assert e.q.q.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

n = A("n")
d = B("d")
h = B("h")
m = A("m")
l = A("l")
b = B("b")
j = A("j")
e = A("e")
c = B("c")

n.q = e
d.x = n
h.x = e
m.q = l
l.q = e
b.x = l
j.q = m
e.q = m
c.x = n
assert e.q.q.q.q.q.q.txt == "e"