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

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

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

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

n = A("n")
k = B("k")
b = C("b")
g = D("g")

n.o = b
n.y = g
n.w = k
k.p = g
k.o = b
b.t = n
g.p = b
g.t = b
g.v = n
g.w = k
assert g.p.t.w.p.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.y: D = None
        self.w: B = None
        self.txt = txt

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

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

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

n = A("n")
k = B("k")
b = C("b")
g = D("g")

n.o = b
n.y = g
n.w = k
k.p = g
k.o = b
b.t = n
g.p = b
g.t = b
g.v = n
g.w = k
assert g.p.t.w.p.txt == "g"