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

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

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

g = A("g")
l = B("l")
j = C("j")
d = B("d")
a = A("a")
h = A("h")

g.x = d
g.p = a
l.q = d
l.o = j
j.s = a
j.r = h
d.q = l
d.o = j
a.x = l
a.p = h
h.x = l
h.p = g
assert g.x.o.s.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.p: A = None
        self.txt = txt

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

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

g = A("g")
l = B("l")
j = C("j")
d = B("d")
a = A("a")
h = A("h")

g.x = d
g.p = a
l.q = d
l.o = j
j.s = a
j.r = h
d.q = l
d.o = j
a.x = l
a.p = h
h.x = l
h.p = g
assert g.x.o.s.x.txt == "l"