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

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

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

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

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

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

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