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

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

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

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

i = A("i")
g = B("g")
m = C("m")
b = D("b")
f = D("f")
n = C("n")
d = A("d")
j = B("j")

i.w = n
g.q = i
m.r = g
m.x = g
m.s = d
b.y = f
b.w = i
b.s = j
b.r = m
f.y = b
f.w = d
f.s = g
f.r = n
n.r = g
n.x = g
n.s = i
d.w = m
j.q = d
assert i.w.x.q.w.r.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.txt = txt

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

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

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

i = A("i")
g = B("g")
m = C("m")
b = D("b")
f = D("f")
n = C("n")
d = A("d")
j = B("j")

i.w = n
g.q = i
m.r = g
m.x = g
m.s = d
b.y = f
b.w = i
b.s = j
b.r = m
f.y = b
f.w = d
f.s = g
f.r = n
n.r = g
n.x = g
n.s = i
d.w = m
j.q = d
assert i.w.x.q.w.r.txt == "g"