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

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

f = A("f")
b = B("b")
g = B("g")
c = A("c")

f.x = g
b.p = g
g.p = b
c.x = b
assert c.x.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

f = A("f")
b = B("b")
g = B("g")
c = A("c")

f.x = g
b.p = g
g.p = b
c.x = b
assert c.x.p.p.txt == "b"