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

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

n = A("n")
d = B("d")
c = A("c")
k = A("k")
m = A("m")
h = A("h")
g = A("g")
l = B("l")
i = A("i")

n.p = l
d.y = l
d.v = h
c.p = l
k.p = d
m.p = d
h.p = d
g.p = l
l.y = d
l.v = k
i.p = l
assert n.p.v.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

n = A("n")
d = B("d")
c = A("c")
k = A("k")
m = A("m")
h = A("h")
g = A("g")
l = B("l")
i = A("i")

n.p = l
d.y = l
d.v = h
c.p = l
k.p = d
m.p = d
h.p = d
g.p = l
l.y = d
l.v = k
i.p = l
assert n.p.v.p.txt == "d"