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

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

d = A("d")
l = B("l")
k = A("k")
m = A("m")
g = B("g")
b = A("b")

d.x = l
d.u = k
l.s = b
l.z = m
k.x = g
k.u = m
m.x = g
m.u = d
g.s = d
g.z = k
b.x = g
b.u = k
assert d.u.x.z.x.s.u.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.u: A = None
        self.txt = txt

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

d = A("d")
l = B("l")
k = A("k")
m = A("m")
g = B("g")
b = A("b")

d.x = l
d.u = k
l.s = b
l.z = m
k.x = g
k.u = m
m.x = g
m.u = d
g.s = d
g.z = k
b.x = g
b.u = k
assert d.u.x.z.x.s.u.txt == "k"