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

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

k = A("k")
j = B("j")
h = A("h")
d = A("d")
c = B("c")
a = A("a")

k.p = c
k.v = h
j.p = h
h.p = j
h.v = a
d.p = j
d.v = h
c.p = a
a.p = c
a.v = h
assert a.p.p.v.p.p.v.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.v: A = None
        self.txt = txt

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

k = A("k")
j = B("j")
h = A("h")
d = A("d")
c = B("c")
a = A("a")

k.p = c
k.v = h
j.p = h
h.p = j
h.v = a
d.p = j
d.v = h
c.p = a
a.p = c
a.v = h
assert a.p.p.v.p.p.v.txt == "a"