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

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

d = A("d")
g = B("g")
e = B("e")

d.r = e
g.p = d
g.v = e
e.p = d
e.v = g
assert d.r.p.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

d = A("d")
g = B("g")
e = B("e")

d.r = e
g.p = d
g.v = e
e.p = d
e.v = g
assert d.r.p.r.txt == "e"