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

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

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

g.s = k
k.y = f
k.o = g
f.s = k
c.s = k
assert k.y.s.o.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

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

g.s = k
k.y = f
k.o = g
f.s = k
c.s = k
assert k.y.s.o.txt == "g"