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

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

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

j.p = g
e.r = g
e.x = j
g.p = j
assert e.x.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.r: A = None
        self.x: A = None
        self.txt = txt

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

j.p = g
e.r = g
e.x = j
g.p = j
assert e.x.p.p.txt == "j"