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

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

k = A("k")
d = B("d")
h = B("h")
f = A("f")
e = A("e")
c = A("c")
b = A("b")
m = B("m")

k.u = c
k.s = d
d.x = m
h.x = d
f.u = k
f.s = m
e.u = b
e.s = h
c.u = k
c.s = m
b.u = k
b.s = d
m.x = d
assert c.s.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.s: B = None
        self.txt = txt

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

k = A("k")
d = B("d")
h = B("h")
f = A("f")
e = A("e")
c = A("c")
b = A("b")
m = B("m")

k.u = c
k.s = d
d.x = m
h.x = d
f.u = k
f.s = m
e.u = b
e.s = h
c.u = k
c.s = m
b.u = k
b.s = d
m.x = d
assert c.s.x.x.txt == "m"