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

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

h = A("h")
f = B("f")
a = A("a")
l = B("l")
k = B("k")
m = B("m")
i = B("i")
d = A("d")
c = A("c")

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

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

h = A("h")
f = B("f")
a = A("a")
l = B("l")
k = B("k")
m = B("m")
i = B("i")
d = A("d")
c = A("c")

h.w = m
h.q = d
f.p = i
f.x = k
a.w = i
a.q = c
l.p = f
l.x = k
k.p = i
k.x = m
m.p = k
m.x = f
i.p = f
i.x = f
d.w = f
d.q = a
c.w = l
c.q = a
assert c.q.w.p.x.x.p.x.txt == "m"