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.v: B = None
        self.txt = txt

a = A("a")
g = B("g")
d = B("d")
c = B("c")

a.p = c
a.v = d
g.v = d
d.v = g
c.v = g
assert c.v.v.v.v.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.v: B = None
        self.txt = txt

a = A("a")
g = B("g")
d = B("d")
c = B("c")

a.p = c
a.v = d
g.v = d
d.v = g
c.v = g
assert c.v.v.v.v.txt == "d"