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

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

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

class D:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

d = A("d")
b = B("b")
h = C("h")
j = D("j")
f = D("f")
c = C("c")

d.s = b
b.x = d
b.s = d
b.w = h
b.o = h
h.s = c
h.p = f
h.q = d
h.o = b
j.x = d
f.x = d
c.s = h
c.p = j
c.q = d
c.o = b
assert c.s.q.s.x.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

d = A("d")
b = B("b")
h = C("h")
j = D("j")
f = D("f")
c = C("c")

d.s = b
b.x = d
b.s = d
b.w = h
b.o = h
h.s = c
h.p = f
h.q = d
h.o = b
j.x = d
f.x = d
c.s = h
c.p = j
c.q = d
c.o = b
assert c.s.q.s.x.s.txt == "b"