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

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

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

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

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

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

h.y = a
h.p = l
a.w = n
a.q = n
m.y = a
m.p = f
l.y = d
l.p = f
f.y = n
f.p = h
d.w = n
d.q = n
n.w = d
n.q = a
assert a.w.w.w.w.txt == "d"