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

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

c = A("c")
m = B("m")
h = A("h")
i = B("i")

c.u = i
c.s = m
m.s = c
m.v = i
h.u = m
h.s = i
i.s = c
i.v = m
assert c.s.v.s.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.s: B = None
        self.txt = txt

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

c = A("c")
m = B("m")
h = A("h")
i = B("i")

c.u = i
c.s = m
m.s = c
m.v = i
h.u = m
h.s = i
i.s = c
i.v = m
assert c.s.v.s.txt == "c"