class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.w: A = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.u: B = None
        self.o: C = None
        self.txt = txt

m = A("m")
d = B("d")
a = C("a")
c = D("c")
b = A("b")
k = D("k")
g = A("g")
e = A("e")
i = C("i")
j = C("j")

m.x = i
m.w = e
d.y = k
d.r = c
a.w = j
c.u = d
c.o = i
b.x = j
b.w = g
k.u = d
k.o = a
g.x = a
g.w = m
e.x = j
e.w = b
i.w = j
j.w = a
assert j.w.w.w.w.w.w.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.w: A = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.u: B = None
        self.o: C = None
        self.txt = txt

m = A("m")
d = B("d")
a = C("a")
c = D("c")
b = A("b")
k = D("k")
g = A("g")
e = A("e")
i = C("i")
j = C("j")

m.x = i
m.w = e
d.y = k
d.r = c
a.w = j
c.u = d
c.o = i
b.x = j
b.w = g
k.u = d
k.o = a
g.x = a
g.w = m
e.x = j
e.w = b
i.w = j
j.w = a
assert j.w.w.w.w.w.w.w.w.w.w.txt == "j"