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

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

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

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

d = A("d")
n = B("n")
m = C("m")
f = D("f")
g = C("g")
c = C("c")
l = B("l")
i = D("i")

d.r = c
d.x = f
d.s = n
n.s = d
n.q = d
n.p = l
m.w = d
f.p = c
f.x = l
f.r = l
g.w = d
c.w = d
l.s = d
l.q = d
l.p = n
i.p = g
i.x = n
i.r = l
assert g.w.r.w.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.x: D = None
        self.s: B = None
        self.txt = txt

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

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

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

d = A("d")
n = B("n")
m = C("m")
f = D("f")
g = C("g")
c = C("c")
l = B("l")
i = D("i")

d.r = c
d.x = f
d.s = n
n.s = d
n.q = d
n.p = l
m.w = d
f.p = c
f.x = l
f.r = l
g.w = d
c.w = d
l.s = d
l.q = d
l.p = n
i.p = g
i.x = n
i.r = l
assert g.w.r.w.r.txt == "c"