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

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

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

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

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

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

k.s = a
k.w = g
c.t = a
c.w = g
g.s = c
g.w = k
a.t = c
a.w = g
assert k.w.s.t.txt == "a"