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

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

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

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

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

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

a.t = l
a.p = b
h.v = b
d.v = h
l.t = a
l.p = h
g.t = l
g.p = h
b.v = d
assert a.t.p.v.v.txt == "d"