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

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

d = A("d")
n = B("n")
f = A("f")
a = B("a")
h = B("h")
i = B("i")

d.w = n
d.y = f
n.s = h
n.u = h
f.w = h
f.y = d
a.s = n
a.u = i
h.s = n
h.u = i
i.s = h
i.u = a
assert d.w.u.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.y: A = None
        self.txt = txt

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

d = A("d")
n = B("n")
f = A("f")
a = B("a")
h = B("h")
i = B("i")

d.w = n
d.y = f
n.s = h
n.u = h
f.w = h
f.y = d
a.s = n
a.u = i
h.s = n
h.u = i
i.s = h
i.u = a
assert d.w.u.s.s.txt == "h"