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

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

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

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

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

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

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