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

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

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

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

d.q = a
m.q = d
h.x = d
h.r = c
e.x = f
e.r = a
c.q = d
f.q = c
a.q = d
assert c.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

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

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

d.q = a
m.q = d
h.x = d
h.r = c
e.x = f
e.r = a
c.q = d
f.q = c
a.q = d
assert c.q.q.q.q.txt == "a"