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

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

g = A("g")
m = B("m")
n = B("n")
e = A("e")
h = B("h")
b = A("b")
i = A("i")
f = A("f")
a = A("a")

g.x = b
g.q = h
m.z = g
n.z = g
e.x = g
e.q = n
h.z = e
b.x = f
b.q = h
i.x = g
i.q = h
f.x = a
f.q = h
a.x = f
a.q = m
assert f.x.x.x.q.z.q.z.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.q: B = None
        self.txt = txt

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

g = A("g")
m = B("m")
n = B("n")
e = A("e")
h = B("h")
b = A("b")
i = A("i")
f = A("f")
a = A("a")

g.x = b
g.q = h
m.z = g
n.z = g
e.x = g
e.q = n
h.z = e
b.x = f
b.q = h
i.x = g
i.q = h
f.x = a
f.q = h
a.x = f
a.q = m
assert f.x.x.x.q.z.q.z.x.txt == "g"