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

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

class C:
    def __init__(self, txt: str):
        self.z: B = None
        self.q: D = None
        self.y: D = None
        self.txt = txt

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

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

g.o = n
g.w = n
g.p = f
f.x = j
n.z = f
n.q = j
n.y = j
j.w = n
b.x = j
k.x = j
assert b.x.w.z.x.w.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.p: B = None
        self.w: C = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.z: B = None
        self.q: D = None
        self.y: D = None
        self.txt = txt

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

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

g.o = n
g.w = n
g.p = f
f.x = j
n.z = f
n.q = j
n.y = j
j.w = n
b.x = j
k.x = j
assert b.x.w.z.x.w.txt == "n"