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

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

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

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

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

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

a.r = e
a.p = g
g.p = a
e.r = a
e.p = g
assert a.r.p.p.txt == "a"