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

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

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

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

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

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

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

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

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

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

g.w = m
d.y = f
d.x = j
l.s = g
m.r = e
m.x = b
m.v = b
e.s = g
b.r = e
b.x = m
b.v = m
f.w = m
j.s = f
i.y = f
i.x = j
assert j.s.w.r.txt == "e"