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

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

h = A("h")
l = B("l")
a = B("a")
g = B("g")

h.p = l
l.v = a
a.v = g
g.v = l
assert h.p.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

h = A("h")
l = B("l")
a = B("a")
g = B("g")

h.p = l
l.v = a
a.v = g
g.v = l
assert h.p.v.v.v.txt == "l"