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

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

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

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

k = A("k")
b = B("b")
a = C("a")
e = D("e")
i = A("i")
f = C("f")
g = A("g")
c = B("c")

k.r = a
b.o = c
b.w = g
a.x = g
a.q = i
a.w = c
a.s = e
e.q = f
e.o = f
i.r = a
f.x = k
f.q = i
f.w = c
f.s = e
g.r = a
c.o = b
c.w = g
assert f.s.o.x.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

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

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

k = A("k")
b = B("b")
a = C("a")
e = D("e")
i = A("i")
f = C("f")
g = A("g")
c = B("c")

k.r = a
b.o = c
b.w = g
a.x = g
a.q = i
a.w = c
a.s = e
e.q = f
e.o = f
i.r = a
f.x = k
f.q = i
f.w = c
f.s = e
g.r = a
c.o = b
c.w = g
assert f.s.o.x.r.txt == "a"