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

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

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

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

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

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

h.q = g
l.x = k
g.x = a
f.x = m
b.x = k
m.q = g
k.q = b
a.q = g
assert b.x.q.x.q.x.q.x.q.txt == "b"