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

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

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

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

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

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

d.w = n
d.r = h
h.y = c
f.y = n
c.w = a
c.r = h
n.w = a
n.r = h
a.w = d
a.r = h
assert d.w.r.y.w.w.w.txt == "n"