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

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

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

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

n = A("n")
k = B("k")
b = C("b")
i = D("i")
j = B("j")

n.w = b
n.z = j
k.r = j
k.p = b
b.u = j
i.v = n
j.r = k
j.p = b
assert j.r.p.u.r.p.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.z: B = None
        self.txt = txt

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

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

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

n = A("n")
k = B("k")
b = C("b")
i = D("i")
j = B("j")

n.w = b
n.z = j
k.r = j
k.p = b
b.u = j
i.v = n
j.r = k
j.p = b
assert j.r.p.u.r.p.txt == "b"