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

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

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

h = A("h")
l = B("l")
i = C("i")
j = A("j")
k = C("k")
g = B("g")

h.q = l
l.x = i
l.w = i
l.q = i
i.p = g
j.q = g
k.p = l
g.x = k
g.q = k
g.w = i
assert i.p.x.p.w.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

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

h = A("h")
l = B("l")
i = C("i")
j = A("j")
k = C("k")
g = B("g")

h.q = l
l.x = i
l.w = i
l.q = i
i.p = g
j.q = g
k.p = l
g.x = k
g.q = k
g.w = i
assert i.p.x.p.w.txt == "i"