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

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

d = A("d")
m = B("m")
h = A("h")
g = B("g")
c = A("c")
f = A("f")
b = B("b")
k = A("k")

d.w = c
d.z = h
m.p = b
m.x = b
h.w = c
h.z = d
g.p = m
g.x = b
c.w = k
c.z = d
f.w = d
f.z = k
b.p = m
b.x = m
k.w = c
k.z = f
assert b.x.x.p.x.x.p.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.z: A = None
        self.txt = txt

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

d = A("d")
m = B("m")
h = A("h")
g = B("g")
c = A("c")
f = A("f")
b = B("b")
k = A("k")

d.w = c
d.z = h
m.p = b
m.x = b
h.w = c
h.z = d
g.p = m
g.x = b
c.w = k
c.z = d
f.w = d
f.z = k
b.p = m
b.x = m
k.w = c
k.z = f
assert b.x.x.p.x.x.p.txt == "b"