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

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

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

f = A("f")
g = B("g")
h = C("h")
d = C("d")
i = A("i")
l = A("l")
e = A("e")

f.p = l
f.q = l
f.r = i
g.v = d
g.x = i
h.u = d
d.u = h
i.p = l
i.r = l
i.q = f
l.p = f
l.r = f
l.q = e
e.p = i
e.r = i
e.q = l
assert f.r.p.r.p.q.r.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.q: A = None
        self.r: A = None
        self.txt = txt

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

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

f = A("f")
g = B("g")
h = C("h")
d = C("d")
i = A("i")
l = A("l")
e = A("e")

f.p = l
f.q = l
f.r = i
g.v = d
g.x = i
h.u = d
d.u = h
i.p = l
i.r = l
i.q = f
l.p = f
l.r = f
l.q = e
e.p = i
e.r = i
e.q = l
assert f.r.p.r.p.q.r.txt == "i"