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

class B:
    def __init__(self, txt: str):
        self.q: D = 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.s: C = None
        self.v: A = None
        self.p: C = None
        self.o: B = None
        self.txt = txt

i = A("i")
m = B("m")
g = C("g")
f = D("f")
j = A("j")
a = B("a")

i.s = g
m.q = f
g.r = f
f.s = g
f.p = g
f.v = j
f.o = m
j.s = g
a.q = f
assert j.s.r.v.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.q: D = 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.s: C = None
        self.v: A = None
        self.p: C = None
        self.o: B = None
        self.txt = txt

i = A("i")
m = B("m")
g = C("g")
f = D("f")
j = A("j")
a = B("a")

i.s = g
m.q = f
g.r = f
f.s = g
f.p = g
f.v = j
f.o = m
j.s = g
a.q = f
assert j.s.r.v.s.txt == "g"