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

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

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

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

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

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

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

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

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

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

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