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

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

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

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

j = A("j")
l = B("l")
b = C("b")
g = D("g")

j.s = b
j.w = b
j.r = b
l.s = j
b.z = g
b.s = g
b.r = g
b.q = l
g.v = b
g.w = b
g.o = j
assert j.r.r.v.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.w: C = None
        self.r: C = None
        self.txt = txt

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

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

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

j = A("j")
l = B("l")
b = C("b")
g = D("g")

j.s = b
j.w = b
j.r = b
l.s = j
b.z = g
b.s = g
b.r = g
b.q = l
g.v = b
g.w = b
g.o = j
assert j.r.r.v.s.txt == "g"