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

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

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

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

f = A("f")
j = B("j")
k = C("k")
e = D("e")
i = D("i")
g = D("g")
a = C("a")
l = A("l")
d = B("d")

f.r = l
f.p = d
f.w = j
f.z = a
j.p = d
j.q = l
j.v = a
k.w = l
k.s = f
e.r = l
i.r = l
g.r = f
a.w = l
a.s = f
l.r = f
l.p = d
l.w = d
l.z = k
d.p = j
d.q = l
d.v = k
assert k.w.w.q.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.p: B = None
        self.w: B = None
        self.z: C = None
        self.txt = txt

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

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

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

f = A("f")
j = B("j")
k = C("k")
e = D("e")
i = D("i")
g = D("g")
a = C("a")
l = A("l")
d = B("d")

f.r = l
f.p = d
f.w = j
f.z = a
j.p = d
j.q = l
j.v = a
k.w = l
k.s = f
e.r = l
i.r = l
g.r = f
a.w = l
a.s = f
l.r = f
l.p = d
l.w = d
l.z = k
d.p = j
d.q = l
d.v = k
assert k.w.w.q.p.p.p.txt == "d"