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

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

d = A("d")
a = B("a")
f = A("f")
n = B("n")
h = A("h")

d.p = a
d.v = n
a.z = f
f.p = a
f.v = n
n.z = h
h.p = n
h.v = a
assert f.p.z.p.z.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.v: B = None
        self.txt = txt

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

d = A("d")
a = B("a")
f = A("f")
n = B("n")
h = A("h")

d.p = a
d.v = n
a.z = f
f.p = a
f.v = n
n.z = h
h.p = n
h.v = a
assert f.p.z.p.z.p.txt == "a"