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

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

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

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

g = A("g")
h = B("h")
m = C("m")
d = D("d")
l = A("l")
e = D("e")
k = B("k")
i = C("i")

g.r = k
g.p = d
g.o = d
h.v = e
h.o = g
h.s = l
m.o = e
d.x = e
d.w = e
l.r = k
l.p = d
l.o = e
e.x = d
e.w = d
k.v = e
k.o = l
k.s = g
i.o = e
assert m.o.w.w.x.w.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.p: D = None
        self.o: D = None
        self.txt = txt

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

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

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

g = A("g")
h = B("h")
m = C("m")
d = D("d")
l = A("l")
e = D("e")
k = B("k")
i = C("i")

g.r = k
g.p = d
g.o = d
h.v = e
h.o = g
h.s = l
m.o = e
d.x = e
d.w = e
l.r = k
l.p = d
l.o = e
e.x = d
e.w = d
k.v = e
k.o = l
k.s = g
i.o = e
assert m.o.w.w.x.w.x.x.x.txt == "d"