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

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

a = A("a")
h = B("h")
f = A("f")
b = A("b")

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

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

a = A("a")
h = B("h")
f = A("f")
b = A("b")

a.y = h
h.v = f
h.p = b
f.y = h
b.y = h
assert h.p.y.p.y.txt == "h"