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

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

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

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

f = A("f")
c = B("c")
a = C("a")
d = D("d")
k = C("k")
n = D("n")

f.o = a
c.s = n
a.w = f
a.y = n
a.z = k
a.x = k
d.x = a
k.w = f
k.y = n
k.z = a
k.x = a
n.x = k
assert a.w.o.y.x.w.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.txt = txt

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

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

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

f = A("f")
c = B("c")
a = C("a")
d = D("d")
k = C("k")
n = D("n")

f.o = a
c.s = n
a.w = f
a.y = n
a.z = k
a.x = k
d.x = a
k.w = f
k.y = n
k.z = a
k.x = a
n.x = k
assert a.w.o.y.x.w.o.txt == "a"