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

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

g = A("g")
h = B("h")
e = A("e")
l = A("l")
k = A("k")
n = B("n")

g.q = l
h.y = n
h.w = e
e.q = k
l.q = g
k.q = g
n.y = h
n.w = g
assert l.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.y: B = None
        self.w: A = None
        self.txt = txt

g = A("g")
h = B("h")
e = A("e")
l = A("l")
k = A("k")
n = B("n")

g.q = l
h.y = n
h.w = e
e.q = k
l.q = g
k.q = g
n.y = h
n.w = g
assert l.q.q.q.q.q.q.txt == "l"