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

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

h = A("h")
d = B("d")
c = A("c")
m = A("m")
f = A("f")
n = B("n")
l = B("l")
e = A("e")

h.w = e
h.y = n
d.w = c
d.q = n
c.w = f
c.y = l
m.w = h
m.y = d
f.w = c
f.y = d
n.w = f
n.q = d
l.w = e
l.q = n
e.w = f
e.y = d
assert h.w.y.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.y: B = None
        self.txt = txt

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

h = A("h")
d = B("d")
c = A("c")
m = A("m")
f = A("f")
n = B("n")
l = B("l")
e = A("e")

h.w = e
h.y = n
d.w = c
d.q = n
c.w = f
c.y = l
m.w = h
m.y = d
f.w = c
f.y = d
n.w = f
n.q = d
l.w = e
l.q = n
e.w = f
e.y = d
assert h.w.y.w.txt == "c"