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

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

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

i = A("i")
c = B("c")
g = C("g")
j = A("j")
m = B("m")
d = C("d")
e = B("e")
h = A("h")
n = A("n")

i.x = j
c.p = g
g.q = d
g.u = d
j.x = h
m.p = g
d.q = g
d.u = g
e.p = g
h.x = j
n.x = i
assert d.q.q.q.u.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

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

i = A("i")
c = B("c")
g = C("g")
j = A("j")
m = B("m")
d = C("d")
e = B("e")
h = A("h")
n = A("n")

i.x = j
c.p = g
g.q = d
g.u = d
j.x = h
m.p = g
d.q = g
d.u = g
e.p = g
h.x = j
n.x = i
assert d.q.q.q.u.txt == "d"