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

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

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

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

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

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

n.q = b
n.x = g
m.t = c
g.q = a
g.x = b
c.t = m
d.q = f
d.x = g
a.q = d
a.x = h
b.q = n
b.x = e
h.q = g
h.x = b
f.q = a
f.x = a
e.q = f
e.x = d
assert d.x.x.x.q.q.x.txt == "h"