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

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

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

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

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

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

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

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

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

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

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