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

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

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

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

l = A("l")
c = B("c")
d = C("d")
j = D("j")
f = D("f")
m = B("m")
k = B("k")
g = D("g")

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

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

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

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

l = A("l")
c = B("c")
d = C("d")
j = D("j")
f = D("f")
m = B("m")
k = B("k")
g = D("g")

l.q = k
l.w = c
l.s = d
l.p = d
c.w = l
c.q = f
d.q = f
j.r = g
j.q = l
f.r = g
f.q = l
m.w = l
m.q = j
k.w = l
k.q = j
g.r = f
g.q = l
assert g.r.r.q.q.q.r.q.txt == "l"