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

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

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

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

d = A("d")
c = B("c")
h = C("h")
i = D("i")
b = A("b")
g = B("g")
f = D("f")
e = B("e")

d.x = f
d.r = h
d.q = h
c.o = h
c.t = e
h.r = c
h.w = g
i.o = b
i.y = e
i.w = f
b.x = f
b.r = h
b.q = h
g.o = h
g.t = e
f.o = d
f.y = g
f.w = i
e.o = h
e.t = c
assert b.r.w.o.w.o.txt == "
class A:
    def __init__(self, txt: str):
        self.x: D = None
        self.r: C = None
        self.q: C = None
        self.txt = txt

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

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

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

d = A("d")
c = B("c")
h = C("h")
i = D("i")
b = A("b")
g = B("g")
f = D("f")
e = B("e")

d.x = f
d.r = h
d.q = h
c.o = h
c.t = e
h.r = c
h.w = g
i.o = b
i.y = e
i.w = f
b.x = f
b.r = h
b.q = h
g.o = h
g.t = e
f.o = d
f.y = g
f.w = i
e.o = h
e.t = c
assert b.r.w.o.w.o.txt == "h"