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

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

g = A("g")
n = B("n")
h = B("h")
c = A("c")
e = A("e")
m = A("m")
a = A("a")
j = A("j")

g.z = n
g.y = n
n.q = m
n.w = a
h.q = e
h.w = j
c.z = n
c.y = n
e.z = n
e.y = n
m.z = h
m.y = n
a.z = n
a.y = n
j.z = h
j.y = n
assert g.y.w.z.q.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.y: B = None
        self.txt = txt

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

g = A("g")
n = B("n")
h = B("h")
c = A("c")
e = A("e")
m = A("m")
a = A("a")
j = A("j")

g.z = n
g.y = n
n.q = m
n.w = a
h.q = e
h.w = j
c.z = n
c.y = n
e.z = n
e.y = n
m.z = h
m.y = n
a.z = n
a.y = n
j.z = h
j.y = n
assert g.y.w.z.q.txt == "m"