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

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

class C:
    def __init__(self, txt: str):
        self.p: F = None
        self.txt = txt

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

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

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

h = A("h")
i = B("i")
g = C("g")
d = D("d")
b = E("b")
a = F("a")

h.x = a
h.s = d
h.q = d
i.y = g
g.p = a
d.u = i
d.w = b
b.o = g
a.q = h
a.p = i
assert g.p.q.s.txt == "
class A:
    def __init__(self, txt: str):
        self.x: F = None
        self.s: D = None
        self.q: D = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.p: F = None
        self.txt = txt

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

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

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

h = A("h")
i = B("i")
g = C("g")
d = D("d")
b = E("b")
a = F("a")

h.x = a
h.s = d
h.q = d
i.y = g
g.p = a
d.u = i
d.w = b
b.o = g
a.q = h
a.p = i
assert g.p.q.s.txt == "d"