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

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

l = A("l")
k = B("k")
d = B("d")
f = B("f")
h = B("h")
c = A("c")
g = B("g")

l.u = h
k.w = f
k.y = l
d.w = h
d.y = c
f.w = d
f.y = c
h.w = d
h.y = c
c.u = g
g.w = d
g.y = c
assert d.y.u.w.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

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

l = A("l")
k = B("k")
d = B("d")
f = B("f")
h = B("h")
c = A("c")
g = B("g")

l.u = h
k.w = f
k.y = l
d.w = h
d.y = c
f.w = d
f.y = c
h.w = d
h.y = c
c.u = g
g.w = d
g.y = c
assert d.y.u.w.txt == "d"