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

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

class C:
    def __init__(self, txt: str):
        self.x: C = None
        self.t: B = None
        self.txt = txt

f = A("f")
d = B("d")
h = C("h")
l = C("l")
j = B("j")
c = C("c")
g = A("g")
n = B("n")
b = C("b")
i = C("i")

f.x = g
f.r = d
d.s = j
d.w = g
h.x = b
h.t = n
l.x = h
l.t = d
j.s = n
j.w = f
c.x = l
c.t = j
g.x = f
g.r = n
n.s = d
n.w = f
b.x = c
b.t = d
i.x = h
i.t = d
assert d.w.r.w.r.w.x.r.w.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.r: B = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.x: C = None
        self.t: B = None
        self.txt = txt

f = A("f")
d = B("d")
h = C("h")
l = C("l")
j = B("j")
c = C("c")
g = A("g")
n = B("n")
b = C("b")
i = C("i")

f.x = g
f.r = d
d.s = j
d.w = g
h.x = b
h.t = n
l.x = h
l.t = d
j.s = n
j.w = f
c.x = l
c.t = j
g.x = f
g.r = n
n.s = d
n.w = f
b.x = c
b.t = d
i.x = h
i.t = d
assert d.w.r.w.r.w.x.r.w.x.x.txt == "g"