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

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

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

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

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

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

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

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

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

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

d.v = j
j.p = n
n.z = d
n.w = j
f.y = g
g.y = f
assert d.v.p.w.txt == "j"