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

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

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

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

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

j.o = k
k.s = j
k.x = j
k.v = b
k.y = b
i.s = f
b.y = k
b.p = k
b.q = k
b.o = i
f.o = k
a.s = j
assert k.s.o.s.o.v.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

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

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

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

j.o = k
k.s = j
k.x = j
k.v = b
k.y = b
i.s = f
b.y = k
b.p = k
b.q = k
b.o = i
f.o = k
a.s = j
assert k.s.o.s.o.v.txt == "b"