class A:
    def __init__(self, txt: str):
        self.y: 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.x: C = None
        self.r: C = None
        self.q: C = None
        self.txt = txt

a = A("a")
d = B("d")
e = C("e")
f = C("f")
m = B("m")
b = A("b")
c = B("c")
l = B("l")

a.y = b
d.p = e
e.x = f
e.r = f
e.q = f
f.x = e
f.r = e
f.q = e
m.p = f
b.y = a
c.p = e
l.p = e
assert f.q.x.q.r.q.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.y: 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.x: C = None
        self.r: C = None
        self.q: C = None
        self.txt = txt

a = A("a")
d = B("d")
e = C("e")
f = C("f")
m = B("m")
b = A("b")
c = B("c")
l = B("l")

a.y = b
d.p = e
e.x = f
e.r = f
e.q = f
f.x = e
f.r = e
f.q = e
m.p = f
b.y = a
c.p = e
l.p = e
assert f.q.x.q.r.q.x.x.txt == "e"