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

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

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

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

h = A("h")
f = B("f")
b = C("b")
g = D("g")
d = C("d")
n = C("n")

h.w = f
f.p = h
b.v = n
b.p = h
b.y = g
g.v = d
d.v = b
d.p = h
d.y = g
n.v = b
n.p = h
n.y = g
assert g.v.v.y.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

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

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

h = A("h")
f = B("f")
b = C("b")
g = D("g")
d = C("d")
n = C("n")

h.w = f
f.p = h
b.v = n
b.p = h
b.y = g
g.v = d
d.v = b
d.p = h
d.y = g
n.v = b
n.p = h
n.y = g
assert g.v.v.y.txt == "g"