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.q: B = None
        self.txt = txt

k = A("k")
e = B("e")
i = B("i")
d = A("d")
g = B("g")
j = A("j")
h = A("h")
c = B("c")
f = A("f")
m = A("m")

k.x = g
k.q = d
e.q = g
i.q = c
d.x = g
d.q = j
g.q = c
j.x = c
j.q = d
h.x = c
h.q = m
c.q = g
f.x = c
f.q = h
m.x = i
m.q = k
assert m.x.q.q.q.q.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.q: B = None
        self.txt = txt

k = A("k")
e = B("e")
i = B("i")
d = A("d")
g = B("g")
j = A("j")
h = A("h")
c = B("c")
f = A("f")
m = A("m")

k.x = g
k.q = d
e.q = g
i.q = c
d.x = g
d.q = j
g.q = c
j.x = c
j.q = d
h.x = c
h.q = m
c.q = g
f.x = c
f.q = h
m.x = i
m.q = k
assert m.x.q.q.q.q.q.q.q.q.txt == "g"