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

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

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

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

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

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

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

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

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

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

k.u = f
g.v = d
g.u = e
e.s = g
e.w = m
j.v = c
f.s = g
f.w = e
m.s = g
m.w = f
c.v = d
b.s = g
b.w = e
d.v = c
assert j.v.v.v.v.v.txt == "c"