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

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

f = A("f")
g = B("g")
d = A("d")
k = B("k")

f.s = d
g.x = k
d.s = f
k.x = g
assert g.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

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

f = A("f")
g = B("g")
d = A("d")
k = B("k")

f.s = d
g.x = k
d.s = f
k.x = g
assert g.x.x.x.x.txt == "g"