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

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

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

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

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

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

k.x = a
g.r = a
a.r = g
assert g.r.r.r.txt == "a"