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

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

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

d.p = e
i.z = a
i.v = b
c.z = e
c.v = b
a.z = c
a.v = b
h.p = a
n.z = e
n.v = b
b.p = a
m.p = i
e.z = g
e.v = d
g.z = c
g.v = b
assert h.p.v.p.v.p.z.z.z.v.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

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

d.p = e
i.z = a
i.v = b
c.z = e
c.v = b
a.z = c
a.v = b
h.p = a
n.z = e
n.v = b
b.p = a
m.p = i
e.z = g
e.v = d
g.z = c
g.v = b
assert h.p.v.p.v.p.z.z.z.v.txt == "b"