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

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

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

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

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

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

e.s = a
e.w = g
k.v = a
k.r = e
a.s = e
a.w = k
g.v = e
g.r = a
assert e.s.w.r.txt == "e"