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

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

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

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

h = A("h")
i = B("i")
e = C("e")
j = D("j")
b = A("b")
c = B("c")
n = B("n")
f = C("f")

h.s = j
h.r = b
i.p = f
i.q = n
i.w = h
e.y = h
e.x = b
e.r = b
e.s = c
j.w = i
j.q = f
j.t = c
b.s = j
b.r = h
c.p = e
c.q = n
c.w = b
n.p = e
n.q = c
n.w = h
f.y = b
f.r = b
f.x = h
f.s = i
assert b.s.q.s.w.r.txt == "
class A:
    def __init__(self, txt: str):
        self.s: D = None
        self.r: A = None
        self.txt = txt

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

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

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

h = A("h")
i = B("i")
e = C("e")
j = D("j")
b = A("b")
c = B("c")
n = B("n")
f = C("f")

h.s = j
h.r = b
i.p = f
i.q = n
i.w = h
e.y = h
e.x = b
e.r = b
e.s = c
j.w = i
j.q = f
j.t = c
b.s = j
b.r = h
c.p = e
c.q = n
c.w = b
n.p = e
n.q = c
n.w = h
f.y = b
f.r = b
f.x = h
f.s = i
assert b.s.q.s.w.r.txt == "b"