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

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

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

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

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

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

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