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

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

n = A("n")
m = B("m")
h = A("h")
j = A("j")
a = B("a")

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

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

n = A("n")
m = B("m")
h = A("h")
j = A("j")
a = B("a")

n.z = j
n.q = a
m.z = j
m.t = j
h.z = n
h.q = m
j.z = h
j.q = m
a.z = h
a.t = j
assert n.z.q.z.q.t.txt == "j"