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

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

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

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

c = A("c")
g = B("g")
a = C("a")
k = D("k")

c.o = g
c.r = k
c.s = k
g.o = a
a.p = g
a.y = g
a.w = g
a.q = c
k.u = g
k.o = c
assert a.q.o.o.p.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.r: D = None
        self.s: D = None
        self.txt = txt

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

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

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

c = A("c")
g = B("g")
a = C("a")
k = D("k")

c.o = g
c.r = k
c.s = k
g.o = a
a.p = g
a.y = g
a.w = g
a.q = c
k.u = g
k.o = c
assert a.q.o.o.p.txt == "g"