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

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

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

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

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

n.x = f
f.o = j
f.p = n
f.s = i
f.w = b
k.r = j
j.x = b
l.r = j
b.o = j
b.p = n
b.s = l
b.w = f
i.r = j
assert b.p.x.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

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

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

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

n.x = f
f.o = j
f.p = n
f.s = i
f.w = b
k.r = j
j.x = b
l.r = j
b.o = j
b.p = n
b.s = l
b.w = f
i.r = j
assert b.p.x.w.w.txt == "f"