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

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

d = A("d")
c = B("c")
k = B("k")
n = B("n")
j = A("j")
i = B("i")
l = B("l")
f = B("f")
m = A("m")

d.z = m
d.x = m
c.q = j
k.q = d
n.q = m
j.z = d
j.x = m
i.q = m
l.q = d
f.q = m
m.z = j
m.x = j
assert m.z.x.x.z.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.x: A = None
        self.txt = txt

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

d = A("d")
c = B("c")
k = B("k")
n = B("n")
j = A("j")
i = B("i")
l = B("l")
f = B("f")
m = A("m")

d.z = m
d.x = m
c.q = j
k.q = d
n.q = m
j.z = d
j.x = m
i.q = m
l.q = d
f.q = m
m.z = j
m.x = j
assert m.z.x.x.z.x.x.txt == "j"