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

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

f = A("f")
m = B("m")
l = A("l")
b = B("b")
g = A("g")
e = A("e")
h = B("h")
c = A("c")
k = B("k")
i = A("i")

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

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

f = A("f")
m = B("m")
l = A("l")
b = B("b")
g = A("g")
e = A("e")
h = B("h")
c = A("c")
k = B("k")
i = A("i")

f.p = h
f.q = i
m.w = b
m.x = h
l.p = b
l.q = e
b.w = k
b.x = m
g.p = k
g.q = l
e.p = m
e.q = l
h.w = b
h.x = b
c.p = b
c.q = e
k.w = h
k.x = b
i.p = k
i.q = c
assert b.w.x.x.w.x.w.txt == "b"