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.u: A = None
        self.r: B = None
        self.txt = txt

c = A("c")
j = B("j")
i = A("i")
k = B("k")

c.s = k
c.w = i
j.u = i
j.r = k
i.s = j
i.w = c
k.u = i
k.r = j
assert k.r.u.w.w.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.u: A = None
        self.r: B = None
        self.txt = txt

c = A("c")
j = B("j")
i = A("i")
k = B("k")

c.s = k
c.w = i
j.u = i
j.r = k
i.s = j
i.w = c
k.u = i
k.r = j
assert k.r.u.w.w.txt == "i"