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

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

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

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

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

b.p = c
b.r = c
b.w = d
b.z = g
d.v = j
d.w = m
j.t = k
m.s = d
m.v = d
g.p = c
g.r = c
g.w = h
g.z = b
k.v = j
k.w = m
c.s = k
c.v = d
h.v = j
h.w = c
assert j.t.v.t.w.s.txt == "
class A:
    def __init__(self, txt: str):
        self.p: D = None
        self.w: B = None
        self.r: D = None
        self.z: A = None
        self.txt = txt

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

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

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

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

b.p = c
b.r = c
b.w = d
b.z = g
d.v = j
d.w = m
j.t = k
m.s = d
m.v = d
g.p = c
g.r = c
g.w = h
g.z = b
k.v = j
k.w = m
c.s = k
c.v = d
h.v = j
h.w = c
assert j.t.v.t.w.s.txt == "d"