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

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

h = A("h")
d = B("d")
n = B("n")
f = A("f")
g = A("g")
c = A("c")
l = B("l")
a = A("a")

h.w = c
h.x = d
d.w = c
d.q = c
n.w = g
n.q = c
f.w = a
f.x = l
g.w = h
g.x = n
c.w = h
c.x = d
l.w = g
l.q = c
a.w = h
a.x = n
assert c.w.w.x.q.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.x: B = None
        self.txt = txt

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

h = A("h")
d = B("d")
n = B("n")
f = A("f")
g = A("g")
c = A("c")
l = B("l")
a = A("a")

h.w = c
h.x = d
d.w = c
d.q = c
n.w = g
n.q = c
f.w = a
f.x = l
g.w = h
g.x = n
c.w = h
c.x = d
l.w = g
l.q = c
a.w = h
a.x = n
assert c.w.w.x.q.w.w.txt == "c"